第五周实验报告3
来源:互联网 发布:java即时通讯框架 编辑:程序博客网 时间:2024/05/29 07:05
/* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称: class Box * 作 者: 刘程程 * 完成日期: 2012 年 03 月 20 日* 版 本 号: 1.0 * 对任务及求解方法的描述部分* 输入描述: 长方体的长,宽,高* 问题描述: 计算长方体的面积和体积* 程序输出: 长方体的长,宽,高,体积,面积* 程序头部的注释结束*/#include <iostream>using namespace std;class Bulk{public: Bulk():lengh(1.0),width(1.0),height(1.0){};//默认构造函数 Bulk(double x,double y,double z):lengh(x),width(y),height(z){};//带参数的构造函数 void set_value(); void display();private: double lengh; double width; double height;};void Bulk::set_value(){ cout<<"please input lengh, width,height:"; cin>>lengh; cin>>width; cin>>height;} void Bulk::display() { cout<<" The volume is: "<<lengh*width*height<<endl; cout<<" The surface area is: "<<2*(lengh*width+lengh*height+width*height)<<endl; cout<<endl; } int main() { Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4,9.5),Bulk(10.5,22.3,3.14)};//前三个元素用带参构造函数初始化,后两个用默认构造函数 b[4].set_value(); //注意b[4]是一个对象,调用成员函数的形式b[4].set_value() for(int i=0;i<5;++i) { cout<<"关于b["<<i<<"]"<<endl; b[i].display();//调用对象数组中元素的成员函数 } system("pause"); return 0; }
通过仔细的看书,看程序,能够对对象数组有更深的认识!!!
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五周实验报告3
- 第五实验报告3
- 第五周实验报告(任务3)
- 第五周实验报告1-3
- 第五周实验报告 任务3
- 第五周实验报告(1-3)
- 《第五周实验报告任务3》
- 第五周实验报告(3)
- 第五周C++实验报告(3)
- Linux内核文档翻译:Documentation/gpio.txt(转+改)
- Linux文件系统的inode
- MSSQL SQL获取所有数据库名、表名、储存过程以及参数列表
- 不患寡而患不均,不患贫而患不安
- Using C# Connector SQLite
- 第五周实验报告3
- components and building system in RDK for TI 8168
- Oracle自适应共享游标
- 第五周实验报告(二)分数化简
- 最好不要在头文件里定义变量,那是非常业余的行为
- 关于jQuery基本知识
- Dojo AJAX 访问C#Web 服务 并且返回JS 格式的数据
- zoj3166 Lazy Tourist//floyd求两点间最短路
- linux命令 https://itunes.apple.com/cn/app/ha-ha-ba-xiu-xian-shi-jian/id1112036209?mt=8