2916: Shape系列-2

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

提交: 268  解决: 242

题目描述

小聪不喜欢小强的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;
}
提示:不用提交全部程序,只提交补充部分。

输入

输出

输出小聪创建的矩形的相关数据。

样例输出

Rectangle color:1
Rectangle width:2
Rectangle height:3
Rectangle area:6
Rectangle price:6

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

#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:
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:"<<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;
}

YTU 2916: Shape系列-2的更多相关文章

  1. YTU 2922: Shape系列-8

    2922: Shape系列-8 时间限制: 1 Sec  内存限制: 128 MB 提交: 172  解决: 99 题目描述 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小 ...

  2. YTU 2920: Shape系列-7

    2921: Shape系列-7 时间限制: 1 Sec  内存限制: 128 MB 提交: 156  解决: 129 题目描述 小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函 ...

  3. YTU 2918: Shape系列-4

    2918: Shape系列-4 时间限制: 1 Sec  内存限制: 128 MB 提交: 276  解决: 232 题目描述 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状 ...

  4. YTU 2918: Shape系列-5

    2919: Shape系列-5 时间限制: 1 Sec  内存限制: 128 MB 提交: 251  解决: 199 题目描述 JC和Kitty听说小亮和小华有了Rectangle和Circle并用R ...

  5. YTU 2917: Shape系列-3

    2917: Shape系列-3 时间限制: 1 Sec  内存限制: 128 MB 提交: 372  解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...

  6. YTU 2915: Shape系列-1

    2915: Shape系列-1 时间限制: 1 Sec  内存限制: 128 MB 提交: 283  解决: 221 题目描述 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有 ...

  7. WPF 2D图形 Shape入门(一)--Shape

    本文是篇WPF Shape的入门文章 Shape 首先看看shape的继承链关系: 一个Shape具有哪些重要属性: 属性 说明 DefiningGeometry 默认的几何形状 RenderedGe ...

  8. 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型

    <zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...

  9. Android系列:res之shape制作

    大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...

随机推荐

  1. js中的constructor 和prototype

    参考 http://www.cnblogs.com/yupeng/archive/2012/04/06/2435386.html function a(c){ this.b = c; this.d = ...

  2. RF新手常见问题总结--(基础篇)

    1. 经常有人问这个元素找不到,一般先排除这两个地方,再自己找找A:是否等待了足够的时间让元素加载 (增加sleep xx, wait Until xxx)B:  仔细查查,这个元素是否进入到另一个f ...

  3. loadrunner报错-持续更新

    一.关联使用web_reg_save_param报错 1.以下是网页中需要关联的地方,有2处,通过网页查看源代码可以看: 2.还可以通过Generation Log来查看需要关联的地方: 3. 然后再 ...

  4. NYOJ-673悟空的难题~~水题~~

    悟空的难题 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 自从悟空当上了齐天大圣,花果山上的猴子猴孙们便也可以尝到天上的各种仙果神酒,所以猴子猴孙们的体质也得到了很好的 ...

  5. [luoguP2704] 炮兵阵地(状压DP)

    传送门 可以事先把每一行的所有状态处理出来,发现每一行的状态数最多不超过60个 f[i][j][k]表示前i行,第i行为状态j,第i-1行为状态k的最优解 #include <vector> ...

  6. 【带权并查集】HDU 3047 Zjnu Stadium

    http://acm.hdu.edu.cn/showproblem.php?pid=3047 [题意] http://blog.csdn.net/hj1107402232/article/detail ...

  7. 匈牙利游戏(codevs 1269)

    题目描述 Description Welcome to the Hungary Games! The streets of Budapest form a twisted network of one ...

  8. linux 安装问题make: 没有指明目标并且找不到makefile。 停止

    错误发生的可能原因,忘记安装软件需要的依赖.

  9. java基础语法4--封装,继承,多态

    学习路线: 未封装==>封装==>继承==>多态==>抽象类 首先还是那句话,万物皆对象,对象有行为和属性. 一:封装 1.封装的概念: 信息隐蔽和对象的属性及操作结合成一个独 ...

  10. Eclipse Explorer插件快速打开项目文件在系统资源管理器

    官网:https://github.com/Jamling/eclipse-explorer 安装: 1.在线安装 [Help]->[Eclipse Marketplace]搜索:Eclipse ...