2921: Shape系列-7

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

提交: 156  解决: 129

题目描述

小强做的Shape类在本次的测试中出了点状况,发现原来是其中的area函数的问题,请大家根据题意,帮助小强完成改动后的Shape类。
小强写的各种类
class Rectangle:public Shape 



public: 

 Rectangle(int c,double w,double h); 

 double getwidth(); 

 double getheight(); 

 double area(); 

 double price(); 

protected: 

 double height; 

 double width; 

}; 

Rectangle::Rectangle(int c,double w,double h):Shape(c) 



 width=w; 

 height=h; 



double Rectangle::getwidth() 



 return width; 



double Rectangle::getheight() 



 return height; 



double Rectangle::area() 



 return height*width; 



double Rectangle::price() 



 return height*width*color; 

}   

class Circle:public Shape 



public: 

 Circle(int c,double r); 

 double getradius(); 

 double area(); 

 double price(); 

protected: 

 double radius; 

};   

Circle::Circle(int c,double r):Shape(c) 



 radius=r; 



double Circle::getradius() 



 return radius; 



double Circle::area() 



 return PI*radius*radius; 



double Circle::price() 



 return PI*radius*radius*color; 

}

class Triangle:  public Shape

{

public:

 Triangle(int c,double b,double h);

 double area();

protected:

 double base,height;

};

Triangle::Triangle(int c,double b,double h):Shape(c)

{

 base=b;height=h;

}

double Triangle::area()

{

 return 0.5*base*height;

}

int main() 



 Shape *pt[3];

 Rectangle rr(1,1,1);

 Circle cc(2,1);

 Triangle tt(2,1,3);

 pt[0]=&rr;

 pt[1]=&cc;

 pt[2]=&tt;

 cout<<"Rectangle area:"<<pt[0]->area()<<endl;

 cout<<"Circle area:"<<pt[1]->area()<<endl;

 cout<<"Triangle area:"<<pt[2]->area()<<endl;

return 0;  

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

输入

输出

小强测试的各个类面积的数据

样例输出

Rectangle area:1
Circle area:3.14
Triangle area:1.5

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

#include<iostream>
using namespace std;
#define PI 3.14
class Shape
{
public:
Shape(int c):color(c) {}
virtual double area()=0;
int color;
};
class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
double price();
protected:
double height;
double width;
};
Rectangle::Rectangle(int c,double w,double h):Shape(c)
{
width=w;
height=h;
}
double Rectangle::getwidth()
{
return width;
}
double Rectangle::getheight()
{
return height;
}
double Rectangle::area()
{
return height*width;
}
double Rectangle::price()
{
return height*width*color;
}
class Circle:public Shape
{
public:
Circle(int c,double r);
double getradius();
double area();
double price();
protected:
double radius;
};
Circle::Circle(int c,double r):Shape(c)
{
radius=r;
}
double Circle::getradius()
{
return radius;
}
double Circle::area()
{
return PI*radius*radius;
}
double Circle::price()
{
return PI*radius*radius*color;
}
class Triangle: public Shape
{
public:
Triangle(int c,double b,double h);
double area();
protected:
double base,height;
};
Triangle::Triangle(int c,double b,double h):Shape(c)
{
base=b;
height=h;
}
double Triangle::area()
{
return 0.5*base*height;
}
int main()
{
Shape *pt[3];
Rectangle rr(1,1,1);
Circle cc(2,1);
Triangle tt(2,1,3);
pt[0]=&rr;
pt[1]=&cc;
pt[2]=&tt;
cout<<"Rectangle area:"<<pt[0]->area()<<endl;
cout<<"Circle area:"<<pt[1]->area()<<endl;
cout<<"Triangle area:"<<pt[2]->area()<<endl;
return 0;
}

YTU 2920: Shape系列-7的更多相关文章

  1. YTU 2922: Shape系列-8

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

  2. YTU 2918: Shape系列-4

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

  3. YTU 2918: Shape系列-5

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

  4. YTU 2917: Shape系列-3

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

  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. 大数据学习——mapreduce汇总手机号上行流量下行流量总流量

    时间戳 手机号 MAC地址 ip 域名 上行流量包个数 下行 上行流量 下行流量 http状态码 1363157995052 13826544101 5C-0E-8B-C7-F1-E0:CMCC 12 ...

  2. 一个抓取智联招聘数据并存入表格的python爬虫

    talk is cheap...show you the code..... import requests import lxml,time,os from bs4 import Beautiful ...

  3. HDU 1078 dfs+dp

    题目大意: 在n*n的矩阵中,每个格子放置了一定数量的食物,一只老鼠每次水平或竖直最多移动k格,每次到的位置食物都要比前一次多,问最后一共能得到多少食物 这道题利用记忆化搜索做,利用nowstate不 ...

  4. Vim command handbook

    /* 本篇文章已经默认你通过了vimtuor训练并能熟练使用大部分命令.此篇文章主要是对于tutor命令的总结和梳理.适合边学习边记忆 tutor那个完全是在学习中记忆 符合认知规律但是练习有限.所以 ...

  5. nginx反向代理ajax,解决跨域问题

    server { listen 8000; server_name somename alias another.alias; location /a { add_header 'Access-Con ...

  6. gerrit ssh 登陆设置

    [root@web ~]# cat ~/.ssh/config Host gerrit User deploy-gerrit Port Hostname gerrit.demo.com Identit ...

  7. 【OPPO主题制作系列 - 01】-- 写个小工具自动打包Theme文件

    参考OPPO主题设计师站: http://dev.theme.oppomobile.com/user/user_start 想要打包成Theme文件,必须把需要打包的文件夹拖到oppo-themepa ...

  8. FIREDAC保存ORACLE的BLOB字段数据

     FIREDAC默认识别ORACLE的BLOB字段为HUGEBLOB,需要将HBLOB映射为BLOB,才可以保存ORACLE的BLOB字段的数据.

  9. Python pandas学习笔记

    参考文献:<Python金融大数据分析> #导入模块 import pandas as pd #生成dataframe df = pd.DataFrame([10,20,30,40], c ...

  10. 【网络】TCP的拥塞控制

    一.拥塞控制的一般原理 拥塞:对网络中某一资源的需求超过了该资源所能提供的可用部分 拥塞控制是防止过多的数据注入到网络,这样可以使网络中的路由器或链路不致过载,拥塞控制是一个全局性的过程. 流量控制往 ...