chapter8test2

这段程序基本正确,但是我的VS2013已知不能运行strcpy,所以没有出现结果,但是问题不大

#include<iostream>

#include<string>
using namespace std;
struct CandyBar
{
char *name;
double weight;
int energy;
};
void set(CandyBar &Bar,string n = "Millennium Munch", double w=2.85, int e=350);
void Show(CandyBar &Bar);
int mian()
{
CandyBar initial = { "Millennium Munch", 2.85, 350 };
CandyBar &first = initial;
Show(first);
cout << "The follow information entered :" << endl;
char *m; double w; int e;
m="Bar name :";
    w=0.54;
e=1230;
set(first, m, w, e);
Show(first);
return 0;
}
void set(CandyBar &Bar, char *a, double w, int e)
{
Bar.name =a;
Bar.weight = w;
Bar.energy = e;
}
void Show(CandyBar &Bar)
{
cout << "CandyBar name :" << Bar.name << endl;
cout << "CandyBar weight :" << Bar.weight << endl;
cout << "CandyBar energy :" << Bar.energy << endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值