对象数组
2013-07-28 20:15
441 查看
#include<iostream>
using namespace std;
class Box
{
public:
Box(int h=10,int w=12,int len=15):height(h),width(w),length(len) {}
int volume();
private:
int height;
int width;
int length;
};
int Box::volume()
{
return(height*width*length);
}
int main()
{
Box a[3]={Box(10,12,15),Box(15,18,20),Box(16,20,26)};
cout<<"volume of a[0] is "<<a[0].volume() <<endl;
cout<<"volume of a[1] is "<<a[1].volume()<<endl;
cout<<"volume of a[2] is "<<a[2].volume()<<endl;
return 0;
}
using namespace std;
class Box
{
public:
Box(int h=10,int w=12,int len=15):height(h),width(w),length(len) {}
int volume();
private:
int height;
int width;
int length;
};
int Box::volume()
{
return(height*width*length);
}
int main()
{
Box a[3]={Box(10,12,15),Box(15,18,20),Box(16,20,26)};
cout<<"volume of a[0] is "<<a[0].volume() <<endl;
cout<<"volume of a[1] is "<<a[1].volume()<<endl;
cout<<"volume of a[2] is "<<a[2].volume()<<endl;
return 0;
}
相关文章推荐
- 对象 数组 正则表达式
- PHP中$_files数组对象信息及错误信息
- 对象数组【c++】
- javascript中的数组对象
- jquery筛选数组之grep、each、inArray、map的用法及遍历json对象
- Android程序员学PHP开发(6)-字符串数组对象资源-PhpStorm
- JSON对象(数组)转换为JSON字符串
- 给Array本地对象增加一个原型方法,他的用途是删除数组中重复的条目,并将新的数组返回
- 浅谈json,对象,数组
- 将JSON格式字符串转成对象、数组、取值等(注意事项)
- javascript 对象和数组理论篇
- 进一步理解javascript对象、数组和哈希表
- 理解ES6 --- 第4章 如何拆解数组和对象来获取数据 desturcturing
- sessionStorage、localStorage如何存储数组与对象
- Java学习note 数组,String,面向对象综合
- 数组对象排序
- C++自定义类的对象数组初始化
- 【java学习笔记】对象数组初始化问题
- js提交数组对象备份
- java对象怎么转json数组