2917: Shape系列-3

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

提交: 372  解决: 237

题目描述

送给小亮的Rectangle类已完成,送给小华Circle类还没有完成。Circle类有整型的数据成员color(小强的Shape类中的color可以继续使用,无需新定义),浮点型的数据成员radius,求面积的成员函数area()。但是小聪没有为Circle类写构造函数和成员函数,请帮助小聪完成Circle类。

小强写的Shape类:

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()

{

Circle cc=Circle(3,1);

cout<<"Circle color:"<<cc.getcolor()<<endl

<<"Circle radius:"<<cc.getradius()<<endl

<<"Circle area:"<<cc.area()<<endl

<<"Circle price:"<<cc.price()<<endl;

return 0;

}

提示:不用提交全部程序,只提交补充部分(包括头文件和π的定义)。

输入

输出

输出小聪测试的Circle类的各个数据。

样例输出

Circle color:3
Circle radius:1
Circle area:3.14
Circle price:9.42

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

#include<iostream>
using namespace std;
#define PI 3.14
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 Circle
{
public:
int x,y;
Circle(int a,int b);
int getcolor();
int getradius();
double area();
double price();
};
Circle::Circle(int a,int b)
{
x=a,y=b;
}
int Circle::getcolor()
{
return x;
}
int Circle::getradius()
{
return y;
}
double Circle::area()
{
return PI*y;
}
double Circle::price()
{
return x*PI;
}
int main()
{
Circle cc=Circle(3,1);
cout<<"Circle color:"<<cc.getcolor()<<endl
<<"Circle radius:"<<cc.getradius()<<endl
<<"Circle area:"<<cc.area()<<endl
<<"Circle price:"<<cc.price()<<endl;
return 0;
}

YTU 2917: Shape系列-3的更多相关文章

  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 2916: Shape系列-2

    2916: Shape系列-2 时间限制: 1 Sec  内存限制: 128 MB 提交: 268  解决: 242 题目描述 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小 ...

  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. luogu2894 [USACO08FEB]酒店Hotel

    跟线段树求区间最值一样每个节点维护左边开始的最大连续空房间数.右边开始的最大连续空房间数.这个区间内的最大连续空房间数 #include <iostream> #include <c ...

  2. 大数据学习——mapreduce倒排索引

    数据 a.txt hello jerry hello tom b.txt allen tom allen jerry allen hello c.txt hello jerry hello tom 1 ...

  3. HDU-1858-Max Partial Value I,有坑点,不难;

    Max Partial Value I Time Limit: 1000/5000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Othe ...

  4. Leetcode39.Combination Sum组合总和

    给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限制重复被选 ...

  5. hdu 1501 基本搜索深搜

    #include<stdio.h> #include<string.h> char s1[300],s2[300],s[500]; int len1,len2,len3,fla ...

  6. Hotel(poj 3667)

    题意:询问区间最长连续空串 /* 用线段树维护区间最长连续左空串和右空串 */ #include<cstdio> #include<iostream> #define N 50 ...

  7. ZOJ 1232 【灵活运用FLOYD】 【图DP】

    题意: copy自http://blog.csdn.net/monkey_little/article/details/6637805 有A个村子和B个城堡,村子标号是1~A,城堡标号是A+1~B.马 ...

  8. 无线网卡与本地连接不能同时使用&一机多网络的优先级设置

    无线网卡与本地连接不能同时使用&一机多网络的优先级设置 2012-05-30 20:39 初次记录 2012-08-09 10:32 修订 题目中的两个问题,其实都可以归结为一个问题,即网络优 ...

  9. maven生命周期和依赖的范围

    转载:http://blog.csdn.net/J080624/article/details/54692444 什么是依赖? 当 A.jar 包用到了 B.jar 包时,A就对B产生了依赖: 在项目 ...

  10. 通过grub硬盘安装centos7

    centos7与centos6.x有了很大的不同,从硬盘安装的方法也有了很大的不同,故出此文章我机器环境如下:    有俩系统 Win7 和 RHEL6.4 ,是通过grub(非grub2)引导的,g ...