CPrimerPlus6第六章程序清单.pdf

上传人:zh****71 文档编号:126718699 上传时间:2020-03-27 格式:PDF 页数:10 大小:55.39KB
返回 下载 相关 举报
CPrimerPlus6第六章程序清单.pdf_第1页
第1页 / 共10页
CPrimerPlus6第六章程序清单.pdf_第2页
第2页 / 共10页
亲,该文档总共10页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《CPrimerPlus6第六章程序清单.pdf》由会员分享,可在线阅读,更多相关《CPrimerPlus6第六章程序清单.pdf(10页珍藏版)》请在金锄头文库上搜索。

1、6 1 if cpp include int main usingnamespace std char ch int spaces 0 int total 0 cin get ch while ch if ch spaces total cin get ch cout spaces spaces total characters total in sentence endl return 0 6 2 ifelse cpp include int main usingnamespace std char ch cout Type and I shall repeat endl cin get c

2、h while ch if ch n cout ch else cout ch cin get ch cout endl Please excuse the slight confusion endl return 0 6 3 ifelseif cpp include constint Fave 27 int main usingnamespace std int n cout Enter a number in the range 1 100 to find cout n if n Fave cout Fave cout Too high guess again else cout Fave

3、 is right endl while n Fave return 0 6 4 or cpp include int main usingnamespace std cout This program may reformat your hard disk endl and destroy all your data nDo you wish to continue char ch cin ch if ch y ch Y cout You were warned a a n elseif ch n ch N cout A wise choice bye n else cout That wa

4、sn t a y or n Apparently you can t follow ninstruction so I ll trash your dish anyway a a a n return 0 6 5 and cpp include constint ArSize 6 int main usingnamespace std float naaq ArSize cout Enter the NAAQ New Age Awareness Quotients of nyourneighbors Program terminates when you make n ArSize entri

5、es or enter a negative value endl int i 0 float temp cout temp while i 0 naaq i temp i if i ArSize cout temp if i 0 cout No data bye endl else cout you int count 0 for int j 0 jyou count cout count cout of your neighbors have greater awareness of n the New Age than you do endl return 0 6 6 more and

6、cpp include constchar qualify 4 10 000 meter race n mud tug of war n masters canoe jousting n pie throwing festival n int main usingnamespace std int age cout age int index if age 17 else index 3 cout You qualify for the qualify index return 0 6 7 not cpp include include bool is int double int main

7、usingnamespace std double num cout num while is int num cout num int val int num cout You ve enterd the integer val nBye n return 0 bool is int double x if x INT MIN returntrue else returnfalse 6 8 cctypes cpp include include int main usingnamespace std cout Enter text for analysis and type to termi

8、nate input n char ch int whitespace 0 int digits 0 int chars 0 int punct 0 int others 0 cin get ch while ch if isalpha ch chars elseif isspace ch whitespace elseif isdigit ch digits elseif ispunct ch punct else others cin get ch cout chars letters whitespace whitespace digits digits punct punctuatio

9、ns others others n return 0 6 9 condit cpp include int main usingnamespace std int a b cout a b cout The larger of a and b a b cout is c endl return 0 6 10 switch cpp include usingnamespace std void showmenu void report void comfort int main showmenu int choice cin choice while choice 5 switch choic

10、e case 1 cout a n break case 2 report break case 3 cout The boss was in all day n break case 4 comfort break default cout choice return 0 6 11 enum cpp include enum red orange yellow green blue violet indigo int main usingnamespace std int code cout code while code red break case orange cout Her hai

11、r was orange n break case yellow cout Her shoes were yellow n break case green cout Her nails were green n break case blue cout Her sweatsuit was blue n break case violet cout Her eyes were violet n break case indigo cout Her mood wa indigo n break cout code cout Bye n return 0 6 12 jump cpp include

12、 constint ArSize 80 int main usingnamespace std char line ArSize int spaces 0 cout Enter a line of text n cin get line ArSize cout Complete line n line endl cout Line through first period n for int i 0 line i 0 i cout line i if line i break if line i continue spaces cout n spaces spaces n cout Done

13、n return 0 6 13 cinfish cpp include constint Max 5 int main usingnamespace std double fish Max cout Please enter the weights of your fish n cout You may enter up to Max fish n cout fish 1 int i 0 while i fish i if i Max cout fish i 1 double total 0 0 for int j 0 j i j total fish j if i 0 cout No fis

14、h endl else cout total i average weight of i fish endl cout Done endl return 0 6 14 cingolf cpp include constint Max 5 int main usingnamespace std int golf Max cout Please enter your golf scores endl cout You must enter Max rounds endl int i for i 0 i Max i cout round i 1 golf i cin clear while cin

15、get n continue cout Please enter a number double total 0 0 for i 0 i Max i total golf i cout total Max average score Max round endl return 0 6 15 outfile cpp include include int main usingnamespace std char automobile 50 int year double a price double d price ofstream outFile outFile open carinfo tx

16、t cout Enter the make and model of automobile cin getline automobile 50 cout year cout a price d price 0 913 a price cout fixed cout precision 2 cout setf ios base showpoint cout Make and model automobile endl cout Year year endl cout Was asking a price endl cout Now asking outFile fixed outFile precision 2 outFile setf ios base showpoint outFile Make and model automobile endl outFile Year year endl outFile Was asking a price endl outFile Now asking outFile close return 0 6 16 sumafile cpp inclu

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 其它文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号