word完整版c++primerplus中文版第六版源代码.docx
- 文档编号:5024500
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:28
- 大小:21.71KB
word完整版c++primerplus中文版第六版源代码.docx
《word完整版c++primerplus中文版第六版源代码.docx》由会员分享,可在线阅读,更多相关《word完整版c++primerplus中文版第六版源代码.docx(28页珍藏版)》请在冰豆网上搜索。
word完整版c++primerplus中文版第六版源代码
C++primerplus中文版第六版源代码
第二章到第四章,后续继续更新………
第二章
1:
#include
voidmain()
{
usingnamespacestd;
intcarrots;
carrots=25;
cout<<”Ihave”;
cout<〈carrots;
cout<<”carrots。
";
cout< carrots=carrots—1; cout<〈”Crunch,crunch.NowIhave"〈 } 2: #include〈iostream〉 intstonetolb(int); intmain() { usingnamespacestd; intstone; cout〈<"Entertheweightinstone: "; cin〉〉stone; intpounds=stonetolb(stone); cout< cout〈 ”〈 return0; } intstonetolb(intsts) { return14*sts; } 3: #include voidmain() { usingnamespacestd; intcarrots; carrots=25; cout<〈"Howmanycarrotsdoyouhave? "< cin>〉carrots; cout<〈”Herearetwomore。 ”; carrots=carrots+2; cout<<”Nowyouhave"<〈carrots<〈"carrots.”< //下两行专门测试cin。 get() cin.get(); cin.get(); } 4: #include〈iostream〉 usingnamespacestd; voidmain() { cout〈〈"ComeupandC++mesometime。 "; cout〈 cout〈〈"Youwon’tregretit! "<〈endl; } 5#include voidsimon(int); intmain() { usingnamespacestd; simon(3); cout〈〈"Pickaninteger: ”; intcount; cin〉〉count; simon(count); cout<<"Done! "〈 return0; } voidsimon(intn) { usingnamespacestd; cout<〈"Simonsaystouchyourtoes”< ”<〈endl; } 6: #include #include〈cmath〉 voidmain() { usingnamespacestd; doublearea; cout<〈”Enterthefloorarae,insquarefeet,ofyourhome: ”; cin>〉area; doubleside; side=sqrt(area); cout〈<"That’stheequivalentofasquare”〈〈side 〈<"feettotheside。 ”< cout<〈"Howfascinating! "< } 第三章 1: #include #include〈climits> usingnamespacestd; intmain() { intn_int=INT_MAX; shortn_short=SHRT_MAX; longn_long=LONG_MAX; cout<〈"intis”〈 cout〈<”shortis"〈〈sizeofn_short〈<”bytes."〈〈endl; cout<<”longis”< cout〈<"Maximumvalues: ”<〈endl; cout〈<”int: "〈 cout〈<"short: ”< cout<<"long: "< cout<<"Minimumintvalue=”<〈INT_MIN〈 cout〈<"Bitsperbyts="〈 return0; } 2: #include #include〈climits〉 #defineZERO0 usingnamespacestd; intmain() { shortsam=SHRT_MAX; unsignedshortsue=sam; cout〈<”samhas"<〈sam〈〈"dollarsandsuehas”〈〈sue; cout<<"dollarsdeposited."〈 〈<"Add$1toeachaccount."〈 sam=sam+1; sue=sue+1; cout〈<”Samhas”〈 cout〈<”dollarsdeposited。 \npoorsam! "< sam=ZERO; sue=ZERO; cout<〈"samhas”〈〈sam<〈"dollarsandsuehas”〈 cout〈〈”dollarsdeposited。 ”〈〈endl; cout<〈"Take$1fromeachaccount。 "〈 sam=sam—1; sue=sue-1; cout<〈"samhas”< cout<<"dollarsdeposited。 "〈〈endl<〈”Luckysue! "< return0; } 3: #include usingnamespacestd; voidmain() { intchest=42; intwaist=0x42; intinseam=042; cout<〈"Monsieurcutsastrikingfigure! \n"; cout<<"chest=”< cout〈<”waist=”〈〈waist〈<”(0x42inhex)\n"; cout<〈”inseam=”<〈inseam<<”(042inoctal)\n”; } 4: #include usingnamespacestd; voidmain() { intchest=42; intwaist=42; intinseam=42; cout〈〈"Monsieurcutsastrikingfigure! \n”; cout〈<”chest="〈 cout〈〈hex; cout〈<"waist=”〈 cout< cout<〈"inseam=”< } 5: #include〈iostream> usingnamespacestd; voidmain() { cout<<”\aoperation\”HyperHype\"isnowactivated! \n"; cout〈<"Enteryouragentcode: __________\b\b\b\b\b\b\b\b”; longcode; cin>〉code; cout〈〈"\aYouentered"〈 。 。 \n”; cout〈<"\acodeverified! proceedwithplanz3! \n”; } 6: #include〈iostream〉 usingnamespacestd; voidmain() { charch; cout〈〈”Enteracharacter: ”< cin>〉ch; cout〈〈”Hola! "; cout<〈”Thankyouforthe"〈 } 7: #include〈iostream> usingnamespacestd; voidmain() { charch=’M’; inti=ch; cout<<”TheASCIIcodefor"〈 cout〈<”Addonetothecharactercode: ”<〈endl; ch=ch+1; i=ch; cout<〈”TheASCIIcodefor”< cout〈〈”Displayingcharchusingcout。 put(ch): ”; cout.put(ch); cout.put(’! '); cout<〈endl<<"Done”〈〈endl; } 8: #include usingnamespacestd; voidmain() { cout.setf(ios_base: : fixed,ios_base: : floatfield);//控制cout显示的形式 floattub=10.0/3。 0; doublemint=10。 0/3.0; constfloatmillion=1。 0e6; cout<<”tub="<〈tub; cout<<”,amilliontubs=”〈 cout〈<”,\nandtenmilliontubs=”; cout〈〈10*million*tub< cout<<"mint="<〈mint〈〈"andamillionmints="; cout< } 9: #include〈iostream〉 usingnamespacestd; voidmain() { floata=2。 34e+22f; floatb=a+1。 0f; cout〈〈"a="〈〈a<〈endl; cout〈<”b-a="<〈b—a〈 } 10: #include usingnamespacestd; voidmain() { doublehats,heads;//或者是float cout。 setf(ios_base: : fixed,ios_base: : floatfield); cout〈<"Enteranumber: ”; cin>〉hats; cout<<"Enteranothernumber: ”; cin>>heads; cout<〈"hats=”<〈hats<<";heads=”< cout<<”hats+heads="〈 cout〈<”hats-heads=”<〈hats—heads〈 cout〈<"hats*heads="< cout〈〈"hats/heads="〈 } 11: #include〈iostream> usingnamespacestd; voidmain() { cout。 setf(ios_base: : fixed,ios_base: : floatfield); cout〈<”Integerdivision: 9/5=”<<9/5< cout<〈"Floating—pointdivision: 9。 0/5.0="; cout〈<9。 0/5.0< cout<〈”Mixeddivision: 9。 0/5="<<9。 0/5<〈endl; cout〈<”doubleconstants: 1。 e7/9.0=”; cout<〈1.e7/9。 0〈 cout〈<"floatconstants: 1.e7f/9。 0f=”; cout〈〈1。 e7f/9.0f<〈endl; } 12: #include〈iostream> usingnamespacestd; voidmain() { constintLbs_per_stn=14; intlbs; cout〈<"Enteryourweightinpounds: ”; cin>>lbs; intstone=lbs/Lbs_per_stn; intpounds=lbs%Lbs_per_stn; cout〈 〈〈"stone,"〈〈pounds<<"pound(s)。 \n"; } 13: #include〈iostream〉 usingnamespacestd; voidmain() { cout。 setf(ios_base: : fixed,ios_base: : floatfield); floattree=3; intguess(3.9832); intdebt=7。 2E12; cout<<"tree="〈〈tree〈 cout<〈”guess="〈 cout〈<”debt=”<〈debt〈 } 14: #include〈iostream〉 usingnamespacestd; voidmain() { intauks,bats,coots; auks=19.99+11.99; bats=(int)19.99+(int)11。 99; coots=int(19.99)+int(11。 99); cout<〈”auks="〈 cout<<",coots=”<〈coots〈〈endl; charch='Z'; cout〈〈”Thecodefor"<〈ch〈〈"is"; cout< cout〈〈"Yes,thecodeis"; //cout< } 第四章 1: #include usingnamespacestd; voidmain() { intyams[3]; yams[0]=7; yams[1]=8; yams[2]=6; intyamcosts[3]={20,30,5}; cout<<”Totalyams="; cout< cout<<"Thepackagewith”〈 cout〈 inttotal=yams[0]*yamcosts[0]+yams[1]*yamcosts[1]; total=total+yams[2]*yamcosts[2]; cout〈<"Thetotalyamexpenseis"< \n”; cout〈<"\nSizeofyamsarray="< cout〈〈”bytes。 \n"; cout〈〈”Sizeofoneelement=”< cout〈<”bytes.\n”; } 2: #include usingnamespacestd; voidmain() { constintsize=15; charname1[size]; charname2[size]=”C++owboy”; cout〈〈"Howdy! I'm”〈〈name2; cout<<”! what'syourname? \n"; cin>〉name1; cout〈〈”Well,"< cout< cout〈〈"inanarrayof”〈 cout<〈”Yourinitialis”<〈name1[0]<〈”。 \n"; name2[3]='\0’; cout<〈"Herearethefirst3charchtersofmyname: ”; cout<〈name2〈〈endl; } 3: #include usingnamespacestd; voidmain() { constintarsize=20; charname[arsize]; chardessert[arsize]; cout〈<”Enteryourname: \n"; cin〉〉name; cout〈〈"Enteryourfavoritedessert: \n”; cin〉>dessert; cout<<"Ihavesomedelicious”<〈dessert; cout〈〈”foryou,"<〈name<〈".\n”; } 4: #include〈iostream〉 usingnamespacestd; voidmain() { constintarsize=20; charname[arsize]; chardessert[arsize]; cout<<”Enteryourname: \n"; cin.getline(name,arsize); cout<<”Enteryourfavoritedessert: \n"; cin。 getline(dessert,arsize); cout<〈”Ihavesomedelicious”〈 cout〈<"foryou,"〈〈name〈〈"。 \n"; } 5: #include〈iostream> usingnamespacestd; voidmain() { constintarsize=20; charname[arsize]; chardessert[arsize]; cout<〈”Enteryourname: \n”; cin。 get(name,arsize).get(); cout<〈”Enteryourfavoritedessert: \n”; cin.get(dessert,arsize); cout〈〈”Ihavesomedelicious"〈〈dessert; cout<<"foryou,”< \n"; } 6: #include #include〈string> usingnamespacestd; voidmain() { charcharr1[20]; charcharr2[20]="jaguar"; stringstr1; stringstr2=”panther"; cout<<”Enterakindoffeline: "; cin〉>charr1; cout<<"Enteranotherkindoffeline: "; cin〉>str1; cout〈<"Herearesomefelines: \n”; cout<〈charr1<<”"〈〈charr2<〈”” 〈 < cout<〈"Thethirdletterin”<〈charr2〈<”is” 〈 cout<<"Thethirdletterin”< 〈〈str2[2]〈〈endl; } 7: #include〈iostream〉 #include usingnamespacestd; voidmain() { strings1="penguin”; strings2,s3; cout〈<"Youcanassignonestringobjecttoanother: s2=s1\n”; s2=s1; cout〈<”s1: "〈 "〈〈s2< cout<<”Youcanassignac—stylestringtoastringobject.\n"; cout〈〈”s2=\"buzzard\"\n”; s2=”buzzard”; cout<<"s2: ”< cout〈<"Youcanconcatenatestrings: s3=s1
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- word 完整版 primerplus 中文版 第六 源代码
![提示](https://static.bdocx.com/images/bang_tan.gif)