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

C++primer plus第六版课后编程练习答案8.2

2015-11-28 14:38 316 查看
#include<iostream>
#include<fstream>
#include<cstdlib>//
#include<string>
#include<cctype>

using namespace std;

struct CandyBar
{
char name[50];
double weight;
int heat;
};
void initial(CandyBar &c,char *n="Millennium Munch",double w=2.85,int h=350);
void showC(const CandyBar &c);

void initial(CandyBar &c,char *n,double w,int h)//
{
strcpy(c.name,n);//使用strcpy函数将指针n的值赋予数组
c.weight=w;
c.heat=h;
}

void showC(const CandyBar &c)
{
cout<<"糖块的品牌名字为"<<c.name<<endl
<<"糖块的重量为"<<c.weight<<endl
<<"糖块的热量为"<<c.heat<<endl;
}

void main()
{
CandyBar c;
initial(c);
showC(c);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: