您的位置:首页 > 编程语言 > C语言/C++

编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第4章编程练习9

2013-11-20 16:59 435 查看
#include <iostream>
#include <string>
using namespace std;
struct CandyBar
{
//string kind;
char kind[20];
float weight;
double calory;
};
void Display(CandyBar ca,int n)
{
cout<<"The kind of ca["<<n<<"] is: "<<ca.kind<<endl;
cout<<"The weight of ca["<<n<<"] is: "<<ca.weight<<endl;
cout<<"The calory of ca["<<n<<"] is: "<<ca.calory<<endl;
}

int main()
{
int size;
cout<<"Enter the size of the array: ";
cin>>size;
cin.get();
CandyBar *ca=new CandyBar[size];
//getline(cin,ca[0].kind);
cin.get(ca[0].kind,20).get();
ca[0].weight=200;
ca[0].calory=100;//getline(cin,ca[1].kind);//

cin.get(ca[1].kind,20).get();
ca[1].weight=205;
ca[1].calory=105;//getline(cin,ca[2].kind);//

cin.get(ca[2].kind,20).get();
ca[2].weight=210;
ca[2].calory=110;

Display(ca[0],0);
Display(ca[1],1);
Display(ca[2],2);
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐