结构的使用
来源:互联网 发布:ubuntu安装anaconda 编辑:程序博客网 时间:2024/06/14 19:58
#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;
}
}
0 0
- C#结构的使用
- SCROLLINFO结构的使用
- SCROLLINFO结构的使用
- list_head结构的使用
- CvFileStorage结构的使用
- IplImage结构的使用
- SCROLLINFO结构的使用
- 结构体的使用
- 结构体的使用
- list_head结构的使用
- 结构体的使用
- 结构体的使用
- 结构的使用
- 结构体的使用
- 树形结构的使用
- 结构的使用
- 结构体的使用
- 结构体的使用
- 初次感受python的力量
- android AIDL技术的简单演示
- Fibonacci数列
- coreData中integer16,integer32,integer64的区别
- RabbitMQ的原理与操作示例
- 结构的使用
- sql多表查询和In EXISIT
- 双端链表实现hash(哈希)
- poj 2488A Knight's Journey(搜索 记录路径)
- java(7)--TCP传输
- HDU Courses 二分图最大匹配
- Spanny字符串样式处理使用心得。
- Maven Error injecting org/sonatype/aether/version/VersionConstrain
- 产品经理需要会写代码吗?