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. Elastic-Job-Lite 源码分析 —— 作业分片策略

    摘要: 原创出处 http://www.iocoder.cn/Elastic-Job/job-sharding-strategy/ 「芋道源码」欢迎转载,保留摘要,谢谢! 本文基于 Elastic-J ...

  2. OO第二次作业

    第一次作业: 由于第一次作业的调度较为简单,采用FIFO策略,以及不支持捎带功能,因此我的第一次电梯作业并没有设置单独的调度器,而会直接将任务交给电梯,电梯进行调度策略也仅为先运动到people的In ...

  3. css装饰文本框input

    在web程序前端页面中,<input>恐怕是用的最多的html元素了,各个需要录入信息的场合都会用到它,一般都会用css来修饰一下使得它更好看. 原始的不加修饰的文本框像下面,有些单调,页 ...

  4. 【网络流】codeforces C. Heidi and Library (hard)

    http://codeforces.com/contest/802/problem/C

  5. hdu 1059二进制优化背包问题

    #include<stdio.h> #include<string.h> int max(int a,int b ) {  return a>b?a:b; } int a ...

  6. 禁止ScrollView在子控件的布局改变时自动滚动的的方法

    重写scrollview中的如下方法,并将其返回值设为0即可. @Override  protected int computeScrollDeltaToGetChildRectOnScreen(Re ...

  7. 骑士精神 (codevs 2449)

    题目描述 Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐标相差为1,纵坐标相差为2或者横坐标 ...

  8. hdu 4923 Room and Moor [ 找规律 + 单调栈 ]

    传送门 Room and Moor Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Oth ...

  9. sed命令解析[转载]

    1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕.具体过程如下 ...

  10. 显示倒计时的Button按钮

    package com.pingyijinren.helloworld.activity; import android.os.CountDownTimer; import android.suppo ...