- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
CPrimerPlus第六版课后题第八章
1.#includeiostreamusingnamespace std;void printf (constchar * str, int n );int main(){printf (HAPPY);cout endl;printf (HELLO, 0);printf (NO,3);return 0 ;}void printf (constchar * str, int n){staticint num = 0;num ++;if (n == 0 )cout str endl;else{for (int i = 0; i num;i ++)cout str endl;}}2.#includeiostreamusingnamespace std;struct CandyBar{char brand[30];double weight;int calorie;};void set ( CandyBar CB, constchar * b = Millennium Munch , constdouble w = 2.85, constint c = 350);void printf (const CandyBar cb );int main(){CandyBar CB;set (CB);printf(CB);char brand[30];double weight;int calorie;cout Please enter a brand : ;cin.getline(brand, 30);cout Please enter a weight : ;cin weight;cout Please enter a calorie : ;cin calorie;set(CB, brand, weight, calorie);printf (CB);return 0 ;}void set ( CandyBar CB, constchar * b, constdouble w, constint c){strcpy(CB.brand, b);CB.weight = w;CB.calorie = c;}void printf (const CandyBar cb ){cout CandyBars brand : cb.brand endl;cout CandyBars weight : cb.weight endl;cout CandyBars calorie : cb.calorie endl;}3.#includeiostream#includestringusingnamespace std;void toupper(string word);int main(){string words;cout Enter a string (q to quit): ;while( getline(cin, words) words[0] != q){toupper(words);cout words endl; cout Next string (q to quit): ;}if(words[0] = q)cout Bye. endl;return 0 ;}void toupper(string word){for (int i = 0; i word.size(); i++)word[i] = toupper(word[i]);}4.#includeiostream#includestringusingnamespace std;struct stringy{char * str;int ct;};void show(constchar * a1, constint n = 1);void show(const stringy a2, constint n = 1);void set( stringy a3, constchar * p);int main(){stringy beany;char testing[] = Reality isnt what it used to be.;set (beany, testing);show(beany);show(beany, 2);testing[0] = D;testing[1] = u;show(testing);show(testing, 3);show(Done!);return 0 ;}void set( stringy a3, constchar * p){int len = strlen(p);a3.ct = len;a3.str = newchar(len + 1);strcpy(a3.s
文档评论(0)