C++PrimerPlus第四章编程练习.doc_第1页
C++PrimerPlus第四章编程练习.doc_第2页
C++PrimerPlus第四章编程练习.doc_第3页
C++PrimerPlus第四章编程练习.doc_第4页
C++PrimerPlus第四章编程练习.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第四章编程练习1、#include int main() using namespace std; coutWhat is your first name? ; char firstname20; cin.getline(firstname,20); coutWhat is your last name? ; char lastname10; cin.get(lastname,10).get(); coutgrade).get(); coutage; coutName:lastname, firstnameendl; coutGrade: char(grade+1)endl; coutAge: ageendl; system(pause); return 0;2、#include #include int main() using namespace std; coutWhat is your first name? ; string f_name; getline(cin,f_name); coutWhat is your last name? ; string l_name; getline(cin,l_name); coutgrade; cin.get(); coutage; string full_name=l_name+, +f_name; coutName: full_nameendl; coutGrade: char(grade+1)endl; coutAge: ageendl; system(pause); return 0;3、#include #include int main() using namespace std; coutfirstname).get(); coutEnter your last name: ; char lastname10; cin.getline(lastname,10); coutHeres the information in a single string: ; char fullname20; strcpy(fullname,lastname); strcat(fullname, ); strcat(fullname,firstname); coutfullnameendl; system(pause); return 0;4、#include #include int main() using namespace std; coutEnter your first name: ; string f_name; getline(cin,f_name); coutEnter your last name: ; string l_name; getline(cin,l_name); string full_name=l_name+, +f_name; coutHeres the information in a single string: full_nameendl; system(pause); return 0;5、#include struct CandyBar char brand_name20; double weight; int calorie;int main() using namespace std; CandyBar snack= Mocha Munch, 2.3, 350 ; coutThe name of the candy is: snack.brand_nameendl; coutThe weight of the candy is: snack.weightendl; coutThe calorie of the candy is: snack.calorieendl; system(pause); return 0;6、#include struct CandyBar char brand_name20; double weight; int calorie;int main() using namespace std; CandyBar snack3= Mocha Munch,2.3,350, Double Mint,1.5,100, Contacnt,4.5,255 ; for(int i=0;i3;i+) coutThe name of the candy is: snacki.brand_nameendl; coutThe weight of the candy is: snacki.weightendl; coutThe calorie of the candy is: snacki.calorieendl; system(pause); return 0;7、#include struct Pizza char c_name20; double diameter; double weight;int main() using namespace std; Pizza sample1; coutPlease enter the name of the company: ; cin.getline(sample1.c_name,20); coutsample1.diameter).get(); coutsample1.weight; cin.get(); coutnnName: sample1.c_nameendl; coutDiameter: sample1.diameterendl; coutWeight: sample1.weightendl; system(pause); return 0;8、#include struct Pizza char c_name20; double weight; double diameter;int main() using namespace std; Pizza *ps=new Pizza; coutps-diameter).get(); coutc_name,20).get(); coutps-weight; coutnnName: c_nameendl; coutDiameter: diameterendl; coutWeight: weightendl; delete ps; system(pause); return 0;9、#include struct CandyBar char brand_name20; double weight; int calorie;int main() using namespace std; CandyBar *ps=new CandyBar3; for(int i=0;i3;i+) coutPlease enter the name: ; cin.getline(psi.brand_name,20); coutpsi.weight).get(); coutpsi.calorie; cin.get(); for(int i=0;i3;i+) coutThe name of the candy

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论