0
点赞
收藏
分享

微信扫一扫

YTU 2915: Shape系列-1


2915: Shape系列-1


时间限制: 1 Sec   内存限制: 128 MB

提交: 283  

解决: 221


题目描述


小强开始迷恋彩色的Shape,于是决定做一个Shape类。Shape类有整型的数据成员color,求面积的成员函数area()。小强针对不知道千奇百怪的Shape如何求面积,于是就统一Shape的面积为10000。小聪看见小强做好的Shape类,决定用该类做两个形状出来,并测试其颜色和面积。但是小强没有为Shape类写构造函数和成员函数,请帮助小强完成Shape类。

小强写的文件头和Shape类的C++代码如下

#include<iostream>
using namespace std;
class Shape
{
public:
Shape();
Shape(int c);
int getcolor();
double area();
private:
int color;
};
小聪测试的C++代码如下
int main()
{
Shape ss1=Shape();
Shape ss2=Shape(5);
cout<<"Shape color:"<<ss1.getcolor()<<","
<<"Shape area:"<<ss1.area()<<endl;
cout<<"Shape color:"<<ss2.getcolor()<<","
<<"Shape area:"<<ss2.area()<<endl;
return 0; }

提示:小强和小聪已经写好的部分不用提交了,只提交补充部分就可以了。


输入



输出


输出小聪测试的两个Shape的颜色和面积。


样例输入

样例输出

Shape color:0,Shape area:10000
Shape color:5,Shape area:10000

im0qianqian_站在回忆的河边看着摇晃的渡船终年无声地摆渡,它们就这样安静地画下黄昏画下清晨......


#include<iostream>
using namespace std;
class Shape
{
public:
Shape();
Shape(int c);
int getcolor();
double area();
private:
int color;
};
Shape::Shape()
{
color=0;
}
Shape::Shape(int c)
{
color=c;
}
int Shape::getcolor()
{
return color;
}
double Shape::area()
{
return 10000;
}
int main()
{
Shape ss1=Shape();
Shape ss2=Shape(5);
cout<<"Shape color:"<<ss1.getcolor()<<","
<<"Shape area:"<<ss1.area()<<endl;
cout<<"Shape color:"<<ss2.getcolor()<<","
<<"Shape area:"<<ss2.area()<<endl;
return 0;
}



举报

相关推荐

0 条评论