结构的使用
2015-12-09 18:03
369 查看
#include<iostream>
using namespace std;
const int M = 5;
struct box
{
char maker[40];
float height;
float width;
float length;
double volume;
};
void print_array(box *name,int number);//显示每一个成员的值
void init_array(box *name, int number);//初始化成员的值
int main(void)
{
using namespace std;
box *p = new box[M];
cout.setf(ios_base::fixed, ios_base::floatfield);
init_array(p, M);
cout << "init succese" << endl;
print_array(p, M);
delete[] p;
cin.get();
cin.get();
return 0;
}
void print_array(box *name, int number)
{
for (int i = 0;i < number;++i)
{
cout << "This is the " << i+1 << " data" <<endl;
cout << "maker = " << name[i].maker << endl;
cout << "height = " << name[i].height << endl;
cout << "width = " << name[i].width << endl;
cout << "length = " << name[i].length << endl;
cout << "volume = " << name[i].volume << endl;
}
}
void init_array(box *name, int number)
{
for (int i = 0;i < number;++i)
{
cout << "\n\nInput " << i+1 << " data" << ",a total of " << M << " data" << endl;
cout << "maker:";
cin >> name[i].maker;
cout << "height:";
cin >> name[i].height;
cout << "width:";
cin >> name[i].width;
cout << "length:";
cin >> name[i].length;
name[i].volume = (name[i].height + name[i].width + name[i].length) / 3;
}
}
using namespace std;
const int M = 5;
struct box
{
char maker[40];
float height;
float width;
float length;
double volume;
};
void print_array(box *name,int number);//显示每一个成员的值
void init_array(box *name, int number);//初始化成员的值
int main(void)
{
using namespace std;
box *p = new box[M];
cout.setf(ios_base::fixed, ios_base::floatfield);
init_array(p, M);
cout << "init succese" << endl;
print_array(p, M);
delete[] p;
cin.get();
cin.get();
return 0;
}
void print_array(box *name, int number)
{
for (int i = 0;i < number;++i)
{
cout << "This is the " << i+1 << " data" <<endl;
cout << "maker = " << name[i].maker << endl;
cout << "height = " << name[i].height << endl;
cout << "width = " << name[i].width << endl;
cout << "length = " << name[i].length << endl;
cout << "volume = " << name[i].volume << endl;
}
}
void init_array(box *name, int number)
{
for (int i = 0;i < number;++i)
{
cout << "\n\nInput " << i+1 << " data" << ",a total of " << M << " data" << endl;
cout << "maker:";
cin >> name[i].maker;
cout << "height:";
cin >> name[i].height;
cout << "width:";
cin >> name[i].width;
cout << "length:";
cin >> name[i].length;
name[i].volume = (name[i].height + name[i].width + name[i].length) / 3;
}
}
相关文章推荐
- RabbitMQ的原理与操作示例
- android AIDL技术的简单演示
- Jvm堆划分和基本参数配置
- android RecyclerView 使用完全解析 介绍(二)
- 【Android开发学习笔记】【高级】【随笔】插件化——Activity生命周期
- jemter的使用(三)
- webstrom热键[持续更新]
- Hbase常用的shell命令
- 文章标题
- yii2 strace 追踪正在执行的进程
- 【转载】CAS实现单点登录(SSO)经典完整教程
- 用位运算实现加、减、乘、除、取余_demo(未完成)
- 4-4-word2003-word文件操作和视图设置
- Android-Activity所应该了解的大概就这样。(下)
- 信息安全系统设计基础实验三
- 5)二叉树[4]哈夫曼树
- 线段树(区间合并) LA 3989 "Ray, Pass me the dishes!"
- spring - constructor-arg 的使用
- Android 6.0 Changes
- Android-Activity所应该了解的大概就这样。(上)