[YTU]_2915(Shape系列-1)

Description

小强开始迷恋彩色的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;

}

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

Input

Output

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

Sample Input

Sample Output

Shape color:0,Shape area:10000
Shape color:5,Shape area:10000
#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;
 
}

posted @ 2017-06-09 10:09  衣带渐宽、为伊憔悴  阅读(209)  评论(0编辑  收藏  举报