欢迎来到天天文库
浏览记录
ID:40531739
大小:244.50 KB
页数:58页
时间:2019-08-04
《c++精解和程序设计》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、**********************清单2-4****************************//File:coins.cpp//Determinesthevaluesofacoincollection#include#includeusingnamespacestd;intmain(){stringname;//input:niece'sfirstnameintpennies;//input:countofpenniesintnickels;//input:countofnickelsintdol
2、lars;//output:valueofcoinsindollarsintchange;//output:valueofcoinsincentsinttotalCents;//totalcentsrepresented//Readinyourniece'sfirstname.cout<<"Enteryourfirstname:";cin>>name;//Readinthecountofnickelsandpennies.cout<<"Enterthenumberofnickels:";cin>>nickels;cout<<"Enterthenumb
3、erofpennies:";cin>>pennies;//Computethetotalvalueincents.totalCents=5*nickels+pennies;//Findthevalueindollarsandchange.dollars=totalCents/100;change=totalCents%100;//Displaythevalueindollarsandchangecout<<"Goodwork"<4、rsand"<usingnamespacestd;intmain(){constfloatKM_PER_MILE=1.609;//1.609kminamilefloatmiles,//input:distanceinmilesk5、ms;//output:distanceinkilometers//Getthedistanceinmiles.cin>>miles;cout<<"Thedistanceinmilesis"<6、作说明***********************//File:stringOperations.cpp//Illustratesstringoperations#include#includeusingnamespacestd;intmain(){stringfirstName,lastName;//inputs-firstandlastnamesstringwholeName;//inputs-wholenamestringgreeting="Hello";//output-agreetingstring//7、Readfirstandlastnames.cout<<"Enteryourfirstname:";cin>>firstName;cout<<"Enteryourlastname:";cin>>lastName;//JoinnamesinwholenamewholeName=firstName+""+lastName;//Displayresultscout<8、l;//Displayinitialscout<<"Yourinitialsare"<
4、rsand"<usingnamespacestd;intmain(){constfloatKM_PER_MILE=1.609;//1.609kminamilefloatmiles,//input:distanceinmilesk
5、ms;//output:distanceinkilometers//Getthedistanceinmiles.cin>>miles;cout<<"Thedistanceinmilesis"<6、作说明***********************//File:stringOperations.cpp//Illustratesstringoperations#include#includeusingnamespacestd;intmain(){stringfirstName,lastName;//inputs-firstandlastnamesstringwholeName;//inputs-wholenamestringgreeting="Hello";//output-agreetingstring//7、Readfirstandlastnames.cout<<"Enteryourfirstname:";cin>>firstName;cout<<"Enteryourlastname:";cin>>lastName;//JoinnamesinwholenamewholeName=firstName+""+lastName;//Displayresultscout<8、l;//Displayinitialscout<<"Yourinitialsare"<
6、作说明***********************//File:stringOperations.cpp//Illustratesstringoperations#include#includeusingnamespacestd;intmain(){stringfirstName,lastName;//inputs-firstandlastnamesstringwholeName;//inputs-wholenamestringgreeting="Hello";//output-agreetingstring//
7、Readfirstandlastnames.cout<<"Enteryourfirstname:";cin>>firstName;cout<<"Enteryourlastname:";cin>>lastName;//JoinnamesinwholenamewholeName=firstName+""+lastName;//Displayresultscout<8、l;//Displayinitialscout<<"Yourinitialsare"<
8、l;//Displayinitialscout<<"Yourinitialsare"<
此文档下载收益归作者所有