YTU 2916: Shape系列-2
2916: Shape系列-2
时间限制: 1 Sec
内存限制: 128 MB
提交: 268
解决: 242
题目描述
小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小聪创建了Rectangle类,并且决定用该类做两个矩形出来,送给好朋友小亮。Rectangle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员width和height,求面积的成员函数area()。但是小聪没有为Rectangle类写构造函数和成员函数,请帮助小聪完成Rectangle类。
小强写的文件头和Shape类:
#includeusing 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:"<提示:不用提交全部程序,只提交补充部分。
输入
无
输出
输出小聪创建的矩形的相关数据。
样例输出
Rectangle color:1Rectangle width:2Rectangle height:3Rectangle area:6Rectangle price:6
im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......
#includeusing 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;}class Rectangle{public: int x,y,z; Rectangle(int a,int b,int c); int getcolor(); int getwidth(); int area(); int price(); int getheight(); };Rectangle::Rectangle(int a,int b,int c){ x=a,y=b,z=c;}int Rectangle::getheight(){ return z;}int Rectangle::getcolor(){ return x;}int Rectangle::getwidth(){ return y; }int Rectangle::area(){ return x*y*z;}int Rectangle::price(){ return (x+y+z);}int main(){ Rectangle rr=Rectangle(1,2,3); cout<<"Rectangle color:"<
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~