内容发布更新时间 : 2024/11/16 1:55:38星期一 下面是文章的全部内容请认真阅读。
B::~B() called.
A::~A() called. 4、Call B's function f() Call B's function g() Call C's function g() 四、编程题(共27分) 1、(10分)
Complex::Complex(){real=0;imag=0;} Complex::Complex(double r){real=r;}
Complex::Complex(double r,double i){real=r;imag=i;} Complex operator+(Complex &c1,Complex &c2) { Complex c;
c.real=c1.real+c2.real; c.imag=c1.imag+c2.imag; return c; }
ostream& operator << (ostream& output,Complex& c) { output<<\ return output; }
istream& operator >> (istream& input,Complex& c)
{ cout<<\ input>>c.real>>c.imag; return input; }
2、(17分)
class Circle:public Shape {public:
Circle(double r){radius=r;} void set() { cout<<\ cin>>radius;
}
void show()
{
cout<<\
double area() {return 3.14159*radius*radius;} private: double radius;
};
class Square:public Shape {public:
Square(double a){this->a=a;} void set() { cout<<\ cin>>a;
}
void show()
{
cout<<\
}
double area(){return a*a;} private: double a;
}; int main()
}
{ }
Circle C(5.5); C.show(); Square S(9.9); S.show();
Shape *s[]={&C,&S};
cout<<\return 0;