网友您好, 请在下方输入框内输入要搜索的题目:
如下程序声明了一个二维图形类TwoDShape,从其派生出矩形类Rec。
include<iostream>
include<string>
using namespaee std,
class TwoDShape{// 二维图形类
char name[20];
public:
TwoDShape (char * n="unknown") {
strcpy(name, n);
}
Char * getName(){return name;}
【 】=0;
};
class Rec: public TwoDShape{
double width, height
public:
Rec(double w-=0. 0,double h=0. 0):TwoDShape("rectangle")
{ width=w; height=h; }
double getWidth() {return width;}
double getHeight() {return height;}
double area() {return width * height;}
};
int main() {
TwoDShape * shape;
Shape=new Rec(2.1,3.0);
cout<<"object is"<<shape->getName()<<"\n";
cout<<"Area is"<<shape->area()<<"\n";
return 0
}
请将程序补充完整,使程序在运行时输出:
abject is triangle
Area is 6.3
参考答案