sdut 3-4 长方形的周长和面积计算
3-4 长方形的周长和面积计算
Time Limit: 1000MS Memory limit: 65536K
标题叙述性说明
类中有私有数据成员Length(长)、Width(宽)。由具有缺省參数值的构造函数对其初始化,函数原型为:Rect(double Length=0, double Width=0); 再为其定义拷贝构造函数,形參为对象的常引用。函数原型为:Rect(const Rect &); 编写主函数。创建Rect对象r1初始化为长、宽数据,利用r1初始化还有一个Rect对象r2。分别输出对象的长和宽、周长和面积。
输入
输入两个实数,中间用一个空格间隔;代表长方形的长和宽
输出
共同拥有6行;
分别输出r1的长和宽。r1的周长;r1的面积;r2的长和宽;r2的周长;r2的面积。注意单词与单词之间用一个空格间隔
演示样例输入
56 32
演示样例输出
the length and width of r1 is:56,32
the perimeter of r1 is:176
the area of r1 is:1792
the length and width of r2 is:56,32
the perimeter of r2 is:176
the area of r2 is:1792
提示
输入-7.0 -8.0
输出
the length and width of r1 is:0,0
the perimeter of r1 is:0
the area of r1 is:0
the length and width of r2 is:0,0
the perimeter of r2 is:0
the area of r2 is:0
来源
演示样例程序
#include <iostream> using namespace std; class Rect
{
private:
double l;
double w; public:
Rect (double x=0,double y=0);
Rect (const Rect &a); const void display1()
{
cout<<"the length and width of r1 is:"<<l<<","<<w<<endl;
cout<<"the perimeter of r1 is:"<<(l+w)*2<<endl;
cout<<"the area of r1 is:"<<l*w<<endl;
} const void display2()
{
cout<<"the length and width of r2 is:"<<l<<","<<w<<endl;
cout<<"the perimeter of r2 is:"<<(l+w)*2<<endl;
cout<<"the area of r2 is:"<<l*w<<endl;
}
}; Rect::Rect(double x,double y)
{
l=x;
w=y;
} Rect::Rect(const Rect & a)
{
l=a.l;
w=a.w;
} int main()
{
double x,y;
cin>>x>>y;
if(x<0|| y<0)
{
x=0;
y=0;
}
Rect rect(x,y);
Rect rect_copy=rect; rect.display1();
rect_copy.display2();
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
sdut 3-4 长方形的周长和面积计算的更多相关文章
- Java练习 SDUT-3339_计算长方形的周长和面积(类和对象)
计算长方形的周长和面积(类和对象) Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 设计一个长方形类Rect,计算长方形 ...
- HDU 1828 Picture(长方形的周长和)
HDU 1828 Picture 题目链接 题意:给定n个矩形,输出矩形周长并 思路:利用线段树去维护,分别从4个方向扫一次,每次多一段的时候,就查询该段未被覆盖的区间长度,然后周长就加上这个长度,4 ...
- 【DTOJ】1001:长方形周长和面积
DTOJ 1001:长方形周长和面积 解题报告 2017.11.05 第一版 ——由翱翔的逗比w原创 题目信息: 题目描述 已知长方形的长和宽,求长方形的周长和面积? 输入 一行:空格隔开的两个整 ...
- C#编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出
编写一个控制台应用程序,输入三角形或者长方形边长,计算其周长和面积并输出. 代码: using System; using System.Collections.Generic; using Syst ...
- Java面向对象5(V~Z)
计算各种图形的周长(接口与多态)(SDUT 3338) import java.util.Scanner; public class Main { public static void main(St ...
- Java面向对象练习
1.定义长方形类,含: 属性:宽.高(整型): 方法:求周长.面积: 构造方法3个:(1)无参——宽.高默认值为1:(2)1个参数——宽.高均为参数值:(3)2个参数——宽.高各为参数值. 要求:进行 ...
- 1028作业:Java语法基础
//1.输入长与宽计算长方形面积与周长.(用精度类型计算) package com.lovo.J133; import java.util.Scanner; public class Homework ...
- C#知识点有必要知会
如果说你父类里面有一个成员比如int a;那么你子类里面也可以再定义一个int a,这个时候base.a和this.a表示的就不是一个变量了,如果说子类里面没有,那么base.a和this.a表示的都 ...
- Python ~~~ 面向对象的利器
class Rectangle(): # 有没有括号都行 . def __init__(self,x,y): self.x=x self.y=y def getPeri(self): def getA ...
随机推荐
- system strategies of Resources Deadlock
In computer science, Deadlock is a naughty boy aroused by compete for resources. Even now, there ...
- poj 2001 Shortest Prefixes(特里)
主题链接:http://poj.org/problem?id=2001 Description A prefix of a string is a substring starting at the ...
- 思维导图(自己整理,希望对大家有用):JavaScript函数+canvas绘图+Array数组
1.javascript函数: 2.Array数组: 3.canvas绘图:
- hdu 3076 ssworld VS DDD (概率dp)
///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次 ...
- COM Interop
1.MSDN上的文章:COM Interop教程 2.接口的三种类型:IDispatch.IUnknown和Dual 3.使用TlbImp来更灵活地自动生成RCW 4.托管事件基于委托,而非托管事件( ...
- hibernate 双向n-n
领域模型: 关系数据模型 双向 n-n 关联须要两端都使用集合属性 双向n-n关联必须使用连接表 集合属性应添加 key 子元素用以映射外键列, 集合元素里还应添加many-to-many子元素关联实 ...
- sdut 在机器上面向对象编程练习11(运算符重载)
在机器上面向对象编程练习11(运算符重载) Time Limit: 1000MS Memory limit: 65536K 标题叙述性说明 有两个矩阵a和b,均为2行3列,求两个矩阵之和.重载运算符& ...
- JavaScript权威指南科13章 webj浏览器avascript
13.1 clientjavascript window对象是所有clientjavascript特点和api主要的接入点.它代表了一个浏览器窗口,通过window对象引用它. window 方法 a ...
- 体验安装金蝶K/3 Wise 13.0(图像)
金蝶13.0它提供windows7支持,而数据库也升级到SQL server 2008,有许多功能上的改善和增强.原本在位置低版本号需要时间来管理此功能,因为有这个模块没有原因一直没能起来,现在,新版 ...
- MySQL 更新中国列:1366 Incorrect string value 问题解决了
周围环境:Win7 64位置,mysql-5.6.25-winx64,MySQL workbench 问题:MySQL在更新时出现异常: warning(s): 1366 Incorrect stri ...