资源描述:
《CPrimerPlus(6)第4单元程序清单》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、4.1arrayone>cpp#includeintmain(){usingnamespacestd;intyams[3J;yams[OJ=7;yams[l]=&yams[2]=6;intyamcosts[3]={20,30,5};cout«nTotalyams=n«yams[O]+yams[1]+yams[2]«endl;cout«MThepackagewithH«yams[l]«HyamscostsM«yamcosts[l]«Hcentsperyam.H«endl;inttotal=yams[0]*yamcosts[OJ+yams[1]*yam
2、costs[1]+yams[2]*yamcosts[2];cout«HThetotalyamexpenseisn«total«Mcents.H;cout«endl«nSizeofyamsarray=M«sizeofyams«Mbytes.M;coul«HSizeofyamselemenl=n«sizeofyams[()]«HbylesAn11;return0;)4.2stringxpp#includc#includeintmain(){usingnamespacestd;constintSize=15;charname1[
3、Size];charname2[Size]=HC++owboyH;cout«MHowdy!PmM«name2«M!whatisyourname?H;cin»namel;cout«MWelLn«namel«,yournamehasH«strlen(name1)«nlettersandisstoredn;cout«HinanarrayofH«sizeofnamel«Hbytes.H«endl;cout«MYourinitialisM«namellO]«M.n«endl;name2[3]=' ';cout«MHerearethefirst3characterso
4、fmyname:H«name2«endl;return0;4.1instrlxpp#includeintmain(){usingnamespacestd;constintArSize=20;charname[ArSizeJ;chardessert[ArSize];cout«HEnteryourname:H;cin»name;cout«HEnteryourfavoritedessert:n;cin»dessert;cout«MIhavesomedeliciousH«dessert«Hforyou,H«name«,,.,';return0;
5、4.2instr2xpp#includeintmain(){usingnamespacesld;constintArSize=20;charname[ArSize];chardessert[ArSize];cout«nEnteryourname:H;cin.gctlinc(namc,ArSizc);cout«MEnteryourfavoritedessert:H;cin.getline(dessert,ArSize);cout«MIhavesomedeliciousH«dessert«Hforyou,H«name«,,.,';retur
6、n0;4.3instr3xpp#includcintmain(){usingnamespacesld;constintArSizc=20;charname[ArSize];chardessert[ArSize];cout«nEnteryourname:H;cin.get(name,ArSize).get();cout«MEnteryourfavoritedessert:H;cin.get(dessert,ArSize).get();cout«MIhavesomedeliciousH«dessert«Hforyou,H«name«,,.,
7、';4.4numstncpp#includeintmain(){usingnamespacestd;cout«nWhatyearwasyourhousebuilt?H;intyear;cin»year;cout«MWhatisitsstreetaddress?M;charaddress[80];cin.getline(address,80);cout«pYearbuilt:p«year«endl;cout«uAddress:M«address«endl;cout«MDone!,,«endkreturn0;4.1strtyp