网站大量收购独家精品文档,联系QQ:2885784924

C++ Primer Plus(6) 第八章 程序清单.doc

  1. 1、本文档共13页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
8.1 inline.cpp #includeiostream inline double square(double x) { return x*x; } int main() { using namespace std; double a,b; double c=3.0; a=square(5.0); b=square(4.5+7.5); couta=a,b=bendl; coutc=c; cout,c aqured=square(c++)endl; coutNow c=cendl; return 0; } 8.2 firstref.cpp #includeiostream int main() { using namespace std; int rats=101; int rodents=rats; coutrats=rats; cout,rodents=rodentsendl; rodents++; coutrats=rats; cout,rodents=rodentsendl; coutrats address=rats; cout,rodents address=rodents; return 0; } 8.3 sceref.cpp #includeiostream int main() { using namespace std; int rats=101; int rodents=rats; coutrats=rats; cout,rodents=rodentsendl; coutrats address=rats; cout,rodents address=rodentsendl; int bunnies=50; rodents=bunnies; coutbunnies=bunnies; cout,rats=rats; cout,rodents=rodentsendl; coutbunnies address=bunnies; cout,rodents address=rodentsendl; return 0; } 8.4 swaps.cpp #includeiostream void swapr(int a, int b); void swapp(int *p,int *q); void swapv(int a,int b); int main() { using namespace std; int wallet1=300; int wallet2=350; coutwallet1=$wallet1; cout, wallet2=$wallet2endl; coutUsing references to swap contents:endl; swapr(wallet1,wallet2); coutwallet1=$wallet1; cout, wallet2=$wallet2endl; coutUsing pointers to swap contents again:endl; swapp(wallet1,wallet2); coutwallet1=$wallet1; cout, wallet2=$wallet2endl; coutTrying to use passing by value:endl; swapv(wallet1,wallet2); coutwallet1=$wallet1; coutwallet2=$wallet2endl; return 0; } void swapr(int a,int b) { int temp; temp=a; a=b; b=temp; } void swapp(int *p,int *q) { int temp; temp=*p; *p=*q; *q=temp; } void swapv(int a,int b) { int temp; temp=a; a=b; b=temp; } 8.5 cubes.cpp #includeiostream double cube(double a); double refcube(double ra); int main() { using namespace std; double x=3.0; coutcube(x); cout=cube of xendl; coutrefcube(x); cout=cube of xendl; return 0; } double cube(double a) { a *=a*a; return a; } double

文档评论(0)

yan698698 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档