[YTU]_2916(Shape系列-2)
来源:互联网 发布:mac的qq群相册 编辑:程序博客网 时间:2024/06/14 12:55
Description
小聪不喜欢小强的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)
{
Shape::Shape(int c)
{
color=c;
}
int Shape::getcolor()
{
return color;
int Shape::getcolor()
{
return color;
}
double Shape::area()
{
return 10000;
}
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;
}
提示:不用提交全部程序,只提交补充部分。
Input
无
Output
输出小聪创建的矩形的相关数据。
Sample Output
Rectangle color:1Rectangle width:2Rectangle height:3Rectangle area:6Rectangle price:6#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;}class Rectangle:public Shape{public: Rectangle(){} Rectangle(int c,int w,int h):Shape(c),width(w),height(h){} int getwidth(); int getheight(); int area(); int price();private: int width,height;}; int Rectangle::getwidth(){return width;}int Rectangle::getheight(){return height;}int Rectangle::area(){return width*height;}int Rectangle::price(){return width+height+color;}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;}
阅读全文
0 0
- [YTU]_2916(Shape系列-2)
- YTU 2916: Shape系列-2
- YTU 2915: Shape系列-1
- YTU 2917: Shape系列-3
- YTU 2918: Shape系列-5
- YTU 2918: Shape系列-4
- YTU 2920: Shape系列-7
- YTU 2922: Shape系列-8
- [YTU]_2915(Shape系列-1)
- [YTU]_2917(Shape系列-3)
- [YTU]_2918( Shape系列-4)
- [YTU]_2919( Shape系列-5)
- [YTU]_2920( Shape系列-6)
- [YTU]_2921( Shape系列-7)
- [YTU]_2922(Shape系列-8)
- Android系列: 自定义图形shape
- OJ嘻唰唰 Shape系列-4
- OJ嘻唰唰Shape系列-6
- JSON.parse()和JSON.stringify()
- java和Android好的学习网址收集
- Vmware虚拟机磁盘lvm扩容
- LeetCode-606. Construct String from Binary Tree (Java)
- 性能监视器- Performance Monitor
- [YTU]_2916(Shape系列-2)
- Android常用开源项目(十一)
- 并查集学习并实现
- 基于 Redis 的分布式锁到底安全吗(上)?
- matlab学习
- Android 一个视图界面内某一View设置动画,其他视图view.setvisibility无效得解决方法
- myeclipse插件安装(一)-link文件安装
- Address already in use: JVM_Bind(端口冲突)
- Object.create方法及其在继承上的应用