#include<iostream>
using namespace std;
class Box
{
public:
Box();
Box(double length);
void seta(double length);
void getvolume(double length);
void getarea(double length);
void disp();
private:
double a;
double volume;
double area;
};
int main()
{
Box box;
double length;
cout << "Start to enter datas:\n";
box.seta(length);
box.getvolume(length);
box.getarea(length);
box.disp();
return 0;
}
Box::Box():a(0),volume(0),area(0)
{
}
Box::Box(double length)
{
if(length<0)
{
cout << "The data you enter for a length is illgle!\n";
exit(0);
}
a=length;
}
void Box::seta(double length)
{
cout << "Please enter the length of the box:";
cin >> length;
a=length;
}
void Box::getvolume(double length)
{
volume=a*a*a;
}
void Box::getarea(double length)
{
area=6*a*a;
}
void Box::disp()
{
cout << "The length of the box you set is:" << a << endl;
cout << "The volume of the box is:" << volume <<endl;
cout << "The area of the box is:" << area <<endl;
}
C++设计源代码 类的实现
需积分: 0 196 浏览量
2011-06-20
19:54:26
上传
评论
收藏 2KB ZIP 举报
gejia10086
- 粉丝: 0
- 资源: 1
最新资源
- 基于Pytorch复现Point-Transformer,用于ShapeNet数据集点云分割
- 【医学影像分析】2D超声图像的分割检测(Ultrasound Nerve Segmentation - Kaggle数据集)
- 嘎嘎香的五款神仙谷歌插件
- .arch书源导入教程.mp4
- 贪心算法介绍及代码示例讲解
- CR13SP35MSI64 Crystal 水晶报表运行组件最后版本64位
- 图像分类数据集:玉米叶是否感染分类数据集(2分类,包含训练集、验证集)
- 小U商城.zip
- 高光谱图像计算机视觉分类图像预处理工具集,包含去除图片无关背景,数据增强,生成标签文件等功能
- (顶刊复现)基于配电网韧性提升的应急移动电源预配置和动态调度(下)-MPS动态调度
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈