#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);
}
C++primer plus第六版课后编程练习答案8.2
最新推荐文章于 2023-05-04 15:00:57 发布