1、C+primerplus中文版编程练习答案n”;endl; return 0;double C2F(double t)return *t+32;endl; return 0;double convert(double t)return 63240*t;n; return 0;style(miles per gallon):endl; coutEuro_style L/100Km = *Euro_styleUS_style;coutConverts to European style(miles per gallon):endl; coutUS_style mpg = *US_styleL/10
2、0Kmn; return 0;style(miles per gallon):19Converts to European style(miles per gallon): 19 mpg = 100KmPress any key to continue第四章 复合类型n;return 0;randendlsnacki.weightendlsnacki.caloryendlendl;return 0;rand=A;eight=;snack0.calory=200; snack1.brand=B; snack1.weight=; snack1.calory=400; snack2.brand=C;
3、 snack2.weight=; snack2.calory=500;for(int i=0;i3;i+)cout brand: snacki.brand endl; cout weight: snacki.weight endl;cout calorie: snacki.calory endlendl;delete snack; return 0;et(); car* ps=new carnum;for(int i=0;inum;+i)coutCar #i+1:n; coutPlease enter the make: ; getline(cin,psi.name); coutpsi.yea
4、r).get();coutHere is your collection:n; for(int i=0;inum;+i) coutpsi.year psi.nameendl; delete ps;return 0;#include #include using namespace std; struct carstring maker; int year;int main()int number;cout number;car* a = new carnumber;for (int i = 0; i number; i+)cout Car # i+1 : endl; cout Please e
5、nter the maker: ; ();getline(cin,ai.maker);cout ai.year;cout Here is your collection: endl; for (int i = 0; i number; i+)cout ai.year ai.maker endl; delete a;return 0;#include using namespace std; struct carchar maker20; int year;int main()int number;cout number;car* a = new carnumber;for (int i = 0
6、; i number; i+)cout Car # i+1 : endl; cout Please enter the maker: ; ();(ai.maker, 20);cout ai.year;cout Here is your collection: endl; for (int i = 0; i number; i+)cout ai.year ai.maker endl; delete a;return 0;n; return 0;n;return 0;和 的区别是:word != done,因为当 word = done 一样时,返回值为 1,不一样时 才是返回 0.;for(in
7、t k=0;k=i;+k) cout*; coutendl;return 0;第六章 分支语句和逻辑运算符n; break;case p:coutA maple is a pianist.n; break;case t:coutA maple is a tree.n; break;case g:return 0;coutA maple is a game.n;#include using namespace std; void show();int main()show();char choice;while (cin choice)switch(choice)case c : cout It
8、s a carnivore.n; break;case p : cout Its a pianist.n; break;case t : cout A maple is a tree.n; break;case g : cout Its a game.n; break;default : cout Please enter a c, p, t, or g:;return 0;void show()cout Please enter one of the following choices: n c) carnivore p) pianistnt) tree g) gamen;display b
9、y name b. display by titlenc. display by bopname d. diplay by preferencenq. quitn; char ch;bop member5=Wimp Macho,English Teacher,DEMON,0,Raki Rhodes,Junior Programmer,BOOM,1,Celia Laiter,Super Star,MIPS,2,Hoppy Hipman,Analyst Trainee,WATEE,1,Pat Hand,Police,LOOPY,2;coutch&ch!=q)switch(ch)case a:for
10、(int i=0;i5;i+) coutmemberi.fullnameendl; break;case b:for(int i=0;i5;i+) coutmemberi.titleendl; break;case c:for(int i=0;i5;i+) coutmemberi.bopnameendl; break;case d:for(int i=0;i5;i+)if(memberi.preference=0) coutmemberi.fullnameendl; else if(memberi.preference=1) coutmemberi.titleendl; else if(mem
11、beri.preference=2) coutmemberi.bopnameendl;break;coutNext choice: ;coutBye!n; return 0;#include using namespace std; const int strsize = 30; struct bopchar fullnamestrsize; char titlestrsize; char bopnamestrsize; int preference;void show(); int main()bop A5 =Wimp Macho, Teacher, HAHA, 0,Raki Rhodes,
12、 Junior Programmer, LIAR, 1,Celia, engineer, MIPS, 2,Hoppy Hipman, Analyst Trainee, WAHU, 1,Pat Hand, Student, LOOPY, 2;cout Benevolent Order of Programmers Reportn; show();cout choice;while (choice != q)switch(choice)case a : cout A0.fullname endl A1.fullname endl A2.fullname endl A3.fullname endl
13、A4.fullname endl; break;case b : cout A0.title endl A1.title endl A2.title endl A3.title endl A4.title endl; break;case c : cout A0.bopname endl A1.bopname endl A2.bopname endl A3.bopname endl A4.bopname endl; break;case d : cout A0.fullname endl A1.title endl A2.bopname endl A3.title endl A4.bopnam
14、e endl; break;default : cout Thats not the proper choice.n;cout choice;cout Bye!n; return 0;void show()cout a. display by name b. display by titlen c. display by bopname d. display by preferencen q. quitn;ame); cout请输入第i+1psi.money;();coutGrand Patrons:n; for(int i=0;i10000)coutpsi.namenpsi.moneyend
15、l;+temp;if(temp=0) coutnonen;coutPatrons:n; for(int i=0;inum;+i) if(psi.money=10000)coutpsi.namenpsi.moneyendl;+temp;if(temp=0) coutnonen;delete ps; return 0;#include #include using namespace std; struct charitystring name; double money;int main()int number; int count = 0;cout number;charity *pt = n
16、ew charitynumber; for (int i = 0; i number; i+)cout Please enter your name: ; ();getline(cin, pti.name);cout pti.money;if(pti.money 10000) count+;if(count = 0)cout 10000); elsecout Grand Patronn; for(int i = 0; i 10000)cout pti.name pti.money endl;cout endl;if(10 - count = 0)cout None(money 10000);
17、elsecout Patronn;for(int i = 0; i number; i+)if(pti.money 10000)cout pti.name pti.money ch; while()+sum; inFilech;if()coutEnd of file reached.n; else if()coutInput terminated by data mismatch.n; elsecoutInput terminated for unkonwn reason.n;cout总共有sum个字符在这个文件中。endl; return 0;#include #include #inclu
18、de using namespace std; const int Size = 20; int main()char filenameSize; ifstream infile;cout Enter name of data file: ; (filename, Size); (filename);if (!()cout Could not open the file filename endl; cout a;while ()+count; infile a;if ()cout End of file reached.n; else if ()cout Input terminated b
19、y data mismatch.n; elsecout Input terminated for unknown reason.n; if (count = 0)cout No data processed.n; elsecout The text contains count character(s) num; ();member *pd=new membernum; for(int i=0;ipdi.donation; ();coutGrand Patrons:n; for(int i=0;i=10000)coutpdi.namenpdi.donationendl; count1+;if(
20、count1=0) coutnonen; coutPatrons:n; for(int i=0;inum;i+) if(pdi.donation10000)coutpdi.namenpdi.donationendl; count2+;if(count2=0) coutnonen;delete pd; return 0;#include #include #include #include using namespace std; struct charitystring name; double money;int main()string filename; ifstream infile;
21、cout Enter name of data file: ; getline(cin, filename); (filename);if (!()cout Could not open the file filename endl; cout number;charity *pt = new charitynumber; for (int i = 0; i pti.money; if(pti.money 10000)count+;if(count = 0)cout 10000); elsecout Grand Patron:n; for(int i = 0; i 10000)cout pti.name pti.money endl;if(10 - count = 0)cout None(money 10000); elsecout Patron:n;for(int i = 0; i number; i+)if(pti.money 10000)cout pti.name pti.money endl;delete pt; return 0;第 7 章 函数C+的编程模块n;return 0;int input(double score, int limit)double a; int i;for
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1