连接错误。。--------------------Configuration: 派生 - Win32 Debug--------------------
程序代码:
形状(一) 编写C++程序完成以下功能: 声明一个基类Shape(形状),其中包含一个方法来计算面积; 从Shape派生两个类矩形和圆形; 从矩形派生正方形; 分别实现派生类构造函数、析构函数和其他方法; 创建派生类的对象,观察构造函数、析构函数调用次序; 不同对象计算面积。 #include<iostream> using namespace std; const double Pi=3.14; class shape { public: shape(){cout<<"shape constructor called"<<endl;} double Getarea(double x,double y){return area=x*y;} ~shape(){cout<<"shape destructor called"<<endl;} private: double area; }; class rectangle:public shape { public: rectangle(); double rect(double X,double Y){return Getarea(X,Y);cout<<"rectangle constructor called"<<endl;} ~rectangle(){cout<<"rectangle destructor called"<<endl;} }; class circle:public shape { public: circle(); double cir_area(double r){cout<<"circle constructor called"<<endl;return Pi*Getarea(r,r);} ~circle(){cout<<"circle destructor called"<<endl;} }; class square:public rectangle { public: square(); double squa(double X){cout<<"square constructor called"<<endl;return Getarea(X,X);} ~square(){cout<<"aquare destructor called"<<endl;} }; int main() { double l,w,r,x; cout<<"请输入长方形的长与宽"<<endl; cin>>l>>w; rectangle rec(); cout<<"the area of rec is:"<<rec.rect(l,w)<<endl; cout<<"请输入圆的半径"<<endl; cin>>r; circle cir( ); cout<<"the area of cir is:"<<cir.cir_area(r)<<endl; cout<<"请输入正方形的边长"<<endl; cin>>x; square squ( ); cout<<"the area of squ is:"<<squ.squa(x)<<endl; return 0; }
[ 本帖最后由 fishviv 于 2010-9-11 10:41 编辑 ]