|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
题目要求:每个二维图形类应包括图形名、平面位置(Point2D点对象)、边长或半径等数据成员,成员函数包括默认及有参构造函数,并实现计算二维图形的面积和周长,以及输出基本信息等功能。
问题:输出结果出问题
求大佬教教在下是为什么输出这么个东西,求改正,谢谢您了
代码:设置类Shape,类TwoDiemnsionalShape,类Square,具体如下:
#include <iostream>
#include<cstring>
using namespace std;
class Shape
{
public:
virtual void print()=0;
virtual void show()=0;
virtual double getV()=0;
virtual double getArea()=0;
};
class TwoDiemnsionalShape:public Shape
{
private:
double x,y;
public:
TwoDiemnsionalShape(double xx=0,double yy=0):x(xx),y(yy)
{
cout <<"construct a TwoDiemnsionalShape"<<endl;
}
virtual ~TwoDiemnsionalShape()
{
cout <<"destruct a TwoDiemnsionalShape" <<endl;
}
void print()
{
cout <<"center:" <<x <<"," <<y <<endl;
}
};
class Square:public TwoDiemnsionalShape
{
private:
double side;
char name[7];
public:
Square():TwoDiemnsionalShape(0,0)
{
side = 1;
strcpy(name,"Square");
cout <<"construct a Square" <<endl;
}
Square(double x,double y,double s,char *n):TwoDiemnsionalShape(x,y)
{
side = s;
strcpy(name,n);
cout <<"construct a Square" <<endl;
}
~Square()
{
cout <<"destruct a Square" <<endl;
}
void show()
{
cout <<"Square:" <<name <<endl;
print();
cout <<"面积为:" <<getArea();
}
double getArea()
{
return side*side;
}
double getV()
{
return 0;
}
};
int main()
{
Square s(1,1,1,"S1");
s.show();
return 0;
} |
|