欢迎来到天天文库
浏览记录
ID:6723964
大小:301.50 KB
页数:12页
时间:2018-01-23
《c++程序设计原理与实践第三章课后答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、“std_lib_facilities.h”这个头文件是《c++程序设计原理与实践》一直用到的头文件,要将此头文件放在你的文件目录中,下面我给出这个头文件:////Thisisastandardlibrarysupportcodetothechaptersofthebook//"Programming--PrinciplesandPracticeUsingC++"byBjarneStroustrup//#ifndefSTD_LIB_FACILITIES_GUARD#defineSTD_LIB_FACILITIES_GUARD1#includ
2、eusingnamespacestd;//------------------------------------------------------------------------------//Thecalltokeep_window_open()isneededonsomeWindowsmachinestoprevent//themfromclosingthewindowbeforeyouhaveachancetoreadtheoutput.inlinevoidkeep_window_open(){cin.ge
3、t();}//------------------------------------------------------------------------------#endif//STD_LIB_FACILITIES_GUARD将上述代码拷贝到记事本中,把后缀.txt改为.h,放在你的根目录即可引用。第三章对象,类型和值第6题#include"std_lib_facilities.h"intmain(){inta;intb;intc;intt;cout<<"请您输入三个数:";cin>>a>>b>>c;if(a>b)//如果a大于
4、b,将a,b交换.{t=a;a=b;b=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}cout<#includeusingnamespacestd;//------------------------------------------------------------------------------intmain(){cout<<"请您输入三个字符串:
5、n";stringfirst;stringsecond;stringthird;stringspace;cin>>first>>second>>third;//读入三个字符串。if(first>second){space=first;first=second;second=space;}if(first>third){space=first;first=third;third=space;}if(second>third){space=second;second=third;third=space;}cout<6、cond<<","<>a;if(a%2==0)cout<<"您输入的数:"<7、;return0;}Vc6.0运行结果如下:第9题#include#includeusingnamespacestd;intmain(){stringstr;cout<<"请您输入一个英文数字:";cin>>str;if(str=="zero")cout<<"对应的阿拉伯数字是:"<<"0";elseif(str=="one")cout<<"对应的阿拉伯数字是:"<<"1";elseif(str=="two")cout<<"对应的阿拉伯数字是:"<<"2";elseif(str=="thr8、ee")cout<<"对应的阿拉伯数字是:"<<"3";elseif(str=="four")cout<<"对应的阿拉伯数字是:"<<"4";elsecout<<"暂时超
6、cond<<","<>a;if(a%2==0)cout<<"您输入的数:"<7、;return0;}Vc6.0运行结果如下:第9题#include#includeusingnamespacestd;intmain(){stringstr;cout<<"请您输入一个英文数字:";cin>>str;if(str=="zero")cout<<"对应的阿拉伯数字是:"<<"0";elseif(str=="one")cout<<"对应的阿拉伯数字是:"<<"1";elseif(str=="two")cout<<"对应的阿拉伯数字是:"<<"2";elseif(str=="thr8、ee")cout<<"对应的阿拉伯数字是:"<<"3";elseif(str=="four")cout<<"对应的阿拉伯数字是:"<<"4";elsecout<<"暂时超
7、;return0;}Vc6.0运行结果如下:第9题#include#includeusingnamespacestd;intmain(){stringstr;cout<<"请您输入一个英文数字:";cin>>str;if(str=="zero")cout<<"对应的阿拉伯数字是:"<<"0";elseif(str=="one")cout<<"对应的阿拉伯数字是:"<<"1";elseif(str=="two")cout<<"对应的阿拉伯数字是:"<<"2";elseif(str=="thr
8、ee")cout<<"对应的阿拉伯数字是:"<<"3";elseif(str=="four")cout<<"对应的阿拉伯数字是:"<<"4";elsecout<<"暂时超
此文档下载收益归作者所有