热门搜索 :
考研考公
您的当前位置:首页正文

《数据结构》期末考试编程大题

来源:伴沃教育
动物类继承

#include using namespace std;

class Mammal{ public: Mammal(){}; ~Mammal(){};

virtual void speak(){cout<<\"it is a mammal\"<class Dog:public Mammal {public: Dog(){}; ~Dog(){};

void speak(){cout<<\"it is a dog\"<void fun(Mammal *ptr){ptr->speak();}

int main(){ Mammal d,*p; Dog b; p=&d; fun(p); p=&b; fun(p); return 0;}

++,——-的前置后置 #include using namespace std; class point{ public: point(double x=0,double y=0); void showpoint()const; point &operator++(); point operator++(int); private : double x,y;};

point::point(double x,double y){ this->x=x; this->y=y;}

void point:: showpoint() const {cout<<\"x=\"<point &point::operator++(){ x++; y++; return *this ;}

point point::operator++(int){ point old =*this; ++(*this); return old;}

int main(){ point p(4,5); p.showpoint(); (p++).showpoint(); (++p).showpoint(); return 0;}

因篇幅问题不能全部显示,请点此查看更多更全内容

Top