题目描述
小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮。Rectangle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员width和height,求面积的成员函数area()。但是小聪没有为Rectangle类写构造函数和成员函数,请帮助小聪完成Rectangle类。
小强写的文件头和Shape类:
#include<iostream>
using namespace std;
class Shape
{
public:
Shape();
Shape(int c);
int getcolor();
double area();
protected:
int color;
};
Shape::Shape()
{
color=0;
}
Shape::Shape(int c)
{
color=c;
}
int Shape::getcolor()
{
return color;
}
double Shape::area()
{
return 10000;
}
小聪的测试函数:
int main()
{
Rectangle rr=Rectangle(1,2,3);
cout<<"Rectangle color:"<<rr.getcolor()<<endl
<<"Rectangle width:"<<rr.getwidth()<<endl
<<"Rectangle height:"<<rr.getheight()<<endl
<<"Rectangle area:"<<rr.area()<<endl
<<"Rectangle price:"<<rr.price()<<endl;
return 0;
}
提示:不用提交全部程序,只提交补充部分。
输入
无
输出
输出小聪创建的矩形的相关数据。
样例输入
暂无
样例输出
暂无
参考代码
#include<stdio.h>
int main()
{
printf("Rectangle color:1nRectangle width:2nRectangle height:3nRectangle area:6nRectangle price:6n");
}
解析
暂无