YTU 2958: 代码填充--雨昕学画画
2958: 代码填充--雨昕学画画
时间限制: 1 Sec 内存限制: 128 MB
提交: 156 解决: 102
题目描述
雨昕开始学画水彩画,老师给雨昕一个形状(Shape)类,雨昕在Shape类的基础上画矩形(Rectangle)类。Rectangle类继承Shape类,增加了double类型的宽(width)和高(height)。矩形类坚持用自己的面积area()。但是雨昕不会为Rectangle类写构造函数和成员函数,请帮助雨昕完成Rectangle类。
注:本题只需要提交填写部分的代码,请按照C++方式提交。
#include<iostream>
#include<iomanip>
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 0;
}
class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
protected:
double height;
double width;
};
/*
请在该部分补充缺少的代码
*/
int main()
{
int color;
double height,width;
cin>>color>>height>>width;
Rectangle rect=Rectangle(color,height,width);
cout<<setiosflags(ios::fixed)<<setprecision(0);
cout<<"Rectangle area:"<<rect.area()<<endl;
return 0;
}
输入
水彩画的颜色,Rectangle类的宽(width)和高(height)。
输出
矩形的面积。
样例输入
1 2 3
样例输出
Rectangle area:6
你 离 开 了 , 我 的 世 界 里 只 剩 下 雨 。 。 。
#include<iostream>
#include<iomanip>
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 0;
}
class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
protected:
double height;
double width;
};
Rectangle::Rectangle(int c,double w,double h)
{
color=c,height=w,width=h;
}
double Rectangle::area()
{
return height*width;
}
int main()
{
int color;
double height,width;
cin>>color>>height>>width;
Rectangle rect=Rectangle(color,height,width);
cout<<setiosflags(ios::fixed)<<setprecision(0);
cout<<"Rectangle area:"<<rect.area()<<endl;
return 0;
}
#include<iomanip>
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 0;
}
class Rectangle:public Shape
{
public:
Rectangle(int c,double w,double h);
double getwidth();
double getheight();
double area();
protected:
double height;
double width;
};
Rectangle::Rectangle(int c,double w,double h)
{
color=c,height=w,width=h;
}
double Rectangle::area()
{
return height*width;
}
int main()
{
int color;
double height,width;
cin>>color>>height>>width;
Rectangle rect=Rectangle(color,height,width);
cout<<setiosflags(ios::fixed)<<setprecision(0);
cout<<"Rectangle area:"<<rect.area()<<endl;
return 0;
}
最新文章
- ORA-00824: cannot set sga_target due to existing internal settings, see alert log for more information
- 【转】 数据库系统——B+树索引
- 一致性hash的理解
- asp.net 把图片压缩成zip之后再进行下载
- Lua 练习中的Bug 以及日志
- Codeforces Gym 100015H Hidden Code 暴力
- iscc2016-basic-明察秋毫
- That&#39;s life,多一些韧性,才有更多的任性(转)
- java mysql 数据类型对照
- ios可变数组的所有操作
- C#中??和?分别是什么意思?
- Java 面试知识点解析(七)——Web篇
- [UOJ422][集训队作业2018]小Z的礼物——轮廓线DP+min-max容斥
- turnserver 配置说明记录
- uva 1232
- 遭遇ASP.NET的Request is not available in this context
- CentOS 使用 Xfce 桌面并通过 xrdp 登录
- Python Socket实现文件上传(TCP协议)
- MySQL--8MySQL存储过程小结
- How to 对拍?
热门文章
- 局域网虚拟机端口映射访问apache
- 74. Spring Data JPA方法定义规范【从零开始学Spring Boot】
- HDU-1061-Rightmost Digit,快速幂水过!~~
- php中memcache与memcached的区别 【收藏】
- secure上传图片
- Swift--错误集:Class controller has not initializers
- iOS - 系统方法中弃用的关键字的了解 NS_AVAILABLE和NS_DEPRECATED
- MongoDB学习day05--MongDB开启权限验证,创建用户
- react 开发 PC 端项目(一)项目环境搭建 及 处理 IE8 兼容问题
- JIRA运行太慢,修改JVM