C++Primer Plus(第六版) 第八章 第二题

来源:互联网 发布:数据透视表怎么做差异 编辑:程序博客网 时间:2024/05/16 18:33
如题
#include<iostream>#include<cstring>struct CandyBar{char name[40];double weight;int heat;};void setCandyBar(CandyBar &candybar, const char *name = "Millennium Munch", const double weight = 2.85, const int heat = 350);void showCandyBar(const CandyBar &candybar);int main(){using namespace std;CandyBar c1, c2;setCandyBar(c1);showCandyBar(c1);setCandyBar(c2, "Abc", 8.45, 8700);showCandyBar(c2);cin.get();return 0;}void setCandyBar(CandyBar & candybar, const char * name, const double weight, const int heat){strcpy_s(candybar.name, name);candybar.weight = weight;candybar.heat = heat;}void showCandyBar(const CandyBar & candybar){std::cout << "name:" << candybar.name << ",weight:" << candybar.weight << ",heat:" << candybar.heat << std::endl;}

阅读全文
0 0
原创粉丝点击