c++ primer plus 中文版 第六版源代码.doc
《c++ primer plus 中文版 第六版源代码.doc》由会员分享,可在线阅读,更多相关《c++ primer plus 中文版 第六版源代码.doc(33页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流c+ primer plus 中文版 第六版源代码【精品文档】第 33 页c+ primer plus 中文版 第六版源代码c+ primer plus 中文版 第六版源代码C+ primer plus 中文版 第六版 源代码 第二章到第四章,后续继续更新 第二章1:#includevoid main()using namespace std;int carrots;carrots=25;coutI have ;coutcarrots;coutcarrots.; coutendl;carrots=carrots-1;coutCrunch,crunch.N
2、ow I have carrots carrotsendl;2:#includeint stonetolb(int);int main()using namespace std;int stone;coutstone;int pounds=stonetolb(stone);coutstone stone= ;coutpounds pounds.endl;return 0;int stonetolb(int sts)return 14*sts;3:#includevoid main()using namespace std;int carrots;carrots=25;coutHow many
3、carrots do you have?carrots;coutHere are two more.; carrots=carrots+2;coutNow you have carrots carrots.endl; /下两行专门测试cin.get() cin.get();cin.get();4:#includeusing namespace std;void main()coutCome up and C+ me some time.;coutendl;coutYou wont regret it!endl;5#includevoid simon(int);int main()using n
4、amespace std;simon(3);coutcount;simon(count);coutDone !endl;return 0;void simon(int n)using namespace std;coutSimon says touch your toes n times.endl;6:#include#includevoid main()using namespace std;double area;coutarea;double side;side=sqrt(area);coutThats the equivalent of a square side feet to th
5、e side.endl;coutHow fascinating!endl; 第三章1:#include#includeusing namespace std;int main()int n_int=INT_MAX;short n_short=SHRT_MAX;long n_long=LONG_MAX;coutint is sizeof(int) bytes.endl;coutshort issizeof n_short bytes.endl;coutlong issizeof n_long bytes.endlendl;coutMaximum values :endl;coutint :n_i
6、ntendl;coutshort :n_shortendl;coutlong :n_longendl;coutMinimum int value = INT_MINendl;coutBits per byts = CHAR_BITendl;return 0;2:#include#include#define ZERO 0using namespace std;int main()short sam=SHRT_MAX;unsigned short sue=sam;coutsam has sam dollars and sue has sue;cout dollars deposited.endl
7、Add $1 to each account.endlNow ;sam=sam+1;sue=sue+1;coutSam has sam dollars and sue has sue;cout dollars deposited.npoor sam!endl;sam=ZERO;sue=ZERO;coutsam has sam dollars and sue has sue;cout dollars deposited.endl;coutTake $1 from each account.endlNow ;sam=sam-1;sue=sue-1;coutsam has sam dolars an
8、d sue has sue;cout dollars deposited.endlLucky sue!endl;return 0;3:#includeusing namespace std;void main()int chest=42;int waist=0x42;int inseam=042;coutMonsieur cuts a striking figure!n;coutchest = chest (42 in decimal)n;coutwaist = waist (0x42 in hex)n;coutinseam =inseam (042 in octal)n;4:#include
9、using namespace std;void main()int chest=42;int waist=42;int inseam=42; coutMonsieur cuts a striking figure!n;coutchest = chest (decimal for 42)endl; couthex;coutwaist = waist (hexadecimal for 42)endl;coutoct;coutinseam =inseam (octal for 42)nendl;5:#includeusing namespace std;void main()coutaoperat
10、ion HyperHype is now activated!n;coutcode;coutaYou entered code .n;coutacode verified !proceed with plan z3!n;6:#includeusing namespace std;void main()char ch;coutEnter a character:ch;coutHola! ;coutThank you for the ch character.endl;7:#includeusing namespace std;void main()char ch=M;int i=ch;coutT
11、he ASCII code for ch is iendl;coutAdd one to the character code:endl;ch=ch+1;i=ch;coutThe ASCII code for ch is iendl;coutDisplaying char ch using cout.put(ch): ;cout.put(ch);cout.put(!);coutendlDoneendl;8:#includeusing namespace std;void main()cout.setf(ios_base:fixed,ios_base:floatfield);/控制cout显示的
12、形式float tub=10.0/3.0;double mint=10.0/3.0;const float million=1.0e6;couttub = tub;cout, a million tubs = million*tub;cout,nand ten million tubs = ;cout10*million*tubendl;coutmint = mint and a million mints = ;coutmillion*mintendl;9:#includeusing namespace std;void main()float a=2.34e+22f;float b=a+1
13、.0f;couta= aendl;coutb-a= b-aendl;10:#includeusing namespace std;void main()double hats,heads;/或者是floatcout.setf(ios_base:fixed,ios_base:floatfield);couthats;coutheads;couthats = hats;heads = headsendl;couthats+heads = hats+headsendl;couthats-heads = hats-headsendl;couthats*heads = hats*headsendl;co
14、uthats/heads = hats/headsendl;11:#includeusing namespace std;void main()cout.setf(ios_base:fixed,ios_base:floatfield);coutInteger division:9/5= 9/5endl;coutFloating-point division: 9.0/5.0 = ;cout9.0/5.0endl;coutMixed division: 9.0/5 = 9.0/5endl;coutdouble constants:1.e7/9.0 = ;cout1.e7/9.0endl;cout
15、float constants:1.e7f/9.0f = ;cout1.e7f/9.0fendl;12:#includeusing namespace std;void main()const int Lbs_per_stn=14;int lbs;coutlbs;int stone=lbs/Lbs_per_stn;int pounds=lbs%Lbs_per_stn;coutlbs pounds are stone stone, pounds pound(s).n;13:#includeusing namespace std;void main()cout.setf(ios_base:fixe
16、d,ios_base:floatfield);float tree=3;int guess(3.9832);int debt=7.2E12;couttree = treeendl;coutguess = guessendl;coutdebt = debtendl;14:#includeusing namespace std;void main()int auks,bats,coots;auks=19.99+11.99;bats=(int)19.99+(int)11.99;coots=int (19.99)+int (11.99);coutauks = auks,bats = bats;cout
17、,coots = cootsendl;char ch=Z;coutThe code forch is ;coutint (ch)endl;coutYes,the code is ;/coutstatiic_cast(ch)endl; 第四章1:#includeusing namespace std;void main()int yams3;yams0=7;yams1=8;yams2=6;int yamcosts3=20,30,5;coutTotal yams = ;coutyams0+yams1+yams2endl;coutThe package with yams1 yams costs ;
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ primer plus 中文版 第六版源代码 第六 源代码
限制150内