第八周项目二 用对象数组操作长方柱类
2016-04-21 08:54
267 查看
* All rights reserved,
* 文件名称:用对象数组操作长方柱类.Cpp
* 作者:刘默涵
* 完成日期:2016年4月21日
* 版本号:vc++6.0
*
* 问题描述:基于对象的程序,求五个长方柱的体积及其表面积。
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
Bulk(double x=1.0,double y=1.0,double z=1.0);
void get_value();
double value();
double area();
private:
double length;
double width;
double heigth;
};
Bulk::Bulk(double l,double w,double h)
{
length=l,width=w,heigth=h;
}
void Bulk::get_value()
{
cin>>length>>width>>heigth;
}
double Bulk::value()
{
return width*length*heigth;
}
double Bulk::area()
{
return 2*(width*length+length*heigth+heigth*width) ;
}
int main()
{
int i;
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
cout<<"Please input the length,width and height:";
b[4].get_value();
cout<<"The volume is:";
for(i=0;i<5;i++)
cout<<b[i].value()<<" ";
cout<<endl;
cout<<"The area is:";
for(i=0;i<5;i++)
cout<<b[i].area()<<" ";
cout<<endl;
return 0;
}
* 文件名称:用对象数组操作长方柱类.Cpp
* 作者:刘默涵
* 完成日期:2016年4月21日
* 版本号:vc++6.0
*
* 问题描述:基于对象的程序,求五个长方柱的体积及其表面积。
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
Bulk(double x=1.0,double y=1.0,double z=1.0);
void get_value();
double value();
double area();
private:
double length;
double width;
double heigth;
};
Bulk::Bulk(double l,double w,double h)
{
length=l,width=w,heigth=h;
}
void Bulk::get_value()
{
cin>>length>>width>>heigth;
}
double Bulk::value()
{
return width*length*heigth;
}
double Bulk::area()
{
return 2*(width*length+length*heigth+heigth*width) ;
}
int main()
{
int i;
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
cout<<"Please input the length,width and height:";
b[4].get_value();
cout<<"The volume is:";
for(i=0;i<5;i++)
cout<<b[i].value()<<" ";
cout<<endl;
cout<<"The area is:";
for(i=0;i<5;i++)
cout<<b[i].area()<<" ";
cout<<endl;
return 0;
}
相关文章推荐
- c++第4次实验项目1
- redis中multi和pipeline区别以及效率(推荐使用pipeline)
- codeforces 665D Simple Subset
- 计算机大端模式和小端模式 内存对齐问题(sizeof)[密码学哈希密码部分参考]
- 日期格式转化
- 第七周项目-用多文件组织多个类的程序2.role.cpp:定义角色类的成员函数
- Rust 1.8 发布,放弃了 Unix 系统传统 Make 编译系统
- 面向对象编程
- redis的初认识
- 137. Single Number II
- swfupload学习
- TestNG 学习总结 - 参数化测试(十二)
- IOS学习之——用NSUserDefaults保存和读取程序设置
- asp.net js与后台C#代码相互调用
- 1到n的和、阶乘以及阶乘的和
- 第8周项目1
- 第一篇文章 用来测试
- 第八周项目-建立一个简单的学生信息表
- 第七周项目3-用多文件组织多个类的程序1.game.h:类声明
- STM32F4毕业设计(1)