YTU 2920: Shape系列-7
2921: Shape系列-7
时间限制: 1 Sec 内存限制: 128 MB
提交: 156 解决: 129
题目描述
{
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的更多相关文章
- YTU 2922: Shape系列-8
2922: Shape系列-8 时间限制: 1 Sec 内存限制: 128 MB 提交: 172 解决: 99 题目描述 小聪又想借用小强的Shape类了,但是不巧的是小强去考英语四级去了,但是小 ...
- YTU 2918: Shape系列-4
2918: Shape系列-4 时间限制: 1 Sec 内存限制: 128 MB 提交: 276 解决: 232 题目描述 小聪送给小亮和小华的形状他们都很喜欢,小亮和小华非要比一下他们两个的形状 ...
- YTU 2918: Shape系列-5
2919: Shape系列-5 时间限制: 1 Sec 内存限制: 128 MB 提交: 251 解决: 199 题目描述 JC和Kitty听说小亮和小华有了Rectangle和Circle并用R ...
- YTU 2917: Shape系列-3
2917: Shape系列-3 时间限制: 1 Sec 内存限制: 128 MB 提交: 372 解决: 237 题目描述 送给小亮的Rectangle类已完成,送给小华Circle类还没有完成. ...
- YTU 2916: Shape系列-2
2916: Shape系列-2 时间限制: 1 Sec 内存限制: 128 MB 提交: 268 解决: 242 题目描述 小聪不喜欢小强的Shape类,声称用Shape类做出的形状不真实,于是小 ...
- YTU 2915: Shape系列-1
2915: Shape系列-1 时间限制: 1 Sec 内存限制: 128 MB 提交: 283 解决: 221 题目描述 小强开始迷恋彩色的Shape,于是决定做一个Shape类.Shape类有 ...
- WPF 2D图形 Shape入门(一)--Shape
本文是篇WPF Shape的入门文章 Shape 首先看看shape的继承链关系: 一个Shape具有哪些重要属性: 属性 说明 DefiningGeometry 默认的几何形状 RenderedGe ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数013,shape模型
<zw版·Halcon-delphi系列原创教程> Halcon分类函数013,shape模型 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“pr ...
- Android系列:res之shape制作
大家好,pls call me francis. nice to me you. 本文将介绍使用在Android中使用shape标签绘制drawable资源图片. 下面的代码是shap标签的基本使用情 ...
随机推荐
- mysql数据库中的索引有那些、有什么用
本文主要讲述了如何加速动态网站的MySQL索引分析和优化. 一.什么是索引? 索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第 ...
- Java比较两个数组中的元素是否相同的最简单方法
import java.util.Arrays; public class Test { /** * Java比较两个数组中的元素是否相同 */ public static void main(Str ...
- 71.mybatis 如何获取插入的id【从零开始学Spring Boot】
[从零开始学习Spirng Boot-常见异常汇总] 在之前的文章已经讲过spring boot集成mybatis了,但是忘记说一个很重要的知识点了,那就是获取获取主键id,这篇文章补充下,sprin ...
- .net异步编程async和await的讨论收获
微软官方描述: C# 5 引入了一种简便方法,即异步编程.此方法利用了 .NET Framework 4.5 及更高版本..NET Core 和 Windows 运行时中的异步支持. 编译器可执行开发 ...
- 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]CF-236B. Easy Number Challenge
B. Easy Number Challenge time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- JS Enter键跳转 控件获得焦点
//回车跳转 jQuery(document).ready(function () { //$(':input:text:first').focus(); jQuery(':input:enabled ...
- 《Shell脚本学习指南》书籍目录
摘要:Shell脚本与Windows/Dos下的批处理相似,也就是用各类命令预先放入到一个文件中,方便一次性执行的一个程序文件,主要是方便管理员进行设置或者管理用的.但是它比Windows下的批处理更 ...
- ubuntu使用git的时:Warning: Permanently added the RSA host key for IP address '13.250.177.223' to the list of known hosts.
1:问题现象: hlp@hlp:~/code/github_code/catch_imooc1$ git push origin master Warning: Permanently added t ...
- 【收藏】SSH原理与运用
http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html http://www.ruanyifeng.com/blog/2011/12/ ...
- windows7 下安装使用Redis
Redis 安装使用 本地环境:Windows7 64位web环境:wamp集成环境,php版本:PHP Version 7.1.17 学习参考网站: RUNOOB.COM官网 http://www ...