




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选,1,2、C+programming,AsimpleC+programTypes,variables,expressions,精选,2,Howtowriteaprogram,FindthewholestepsintherealmodelUsesomegraphornaturelanguagetodescribeRealizewithcomputerlanguage,精选,3,workflow,精选,4,PseudoCode,Afirstidea:intmain()variableswhile(condition)analyzetheexpressionevaluatetheexpressi
2、onprinttheresult,4,精选,5,mainFunction,intmain(void)return0;,intx=5;inty=8;intz=x+y;coutx“+”y“=“zendl;,5,精选,6,/2.1.cpp,#includeusingnamespacestd;/*AsimpleprogramfordemonstratingthebasicsofaC+project.*ItdoesagoodjobofdemonstratingC+fundamentals,buta*terriblejobwiththepoetry.*/intmain()coutDontyoujustfe
3、ellikealouse;coutendl;coutTolearnthatyournewtheoremwasprovedbyGauss?;coutendl;return0;,6,精选,7,cout,cout,7,精选,8,C+Tokens,AtokenisthesmallestelementofaC+programthatismeaningfultothecompiler.Kindsoftokens:identifiers,keywords,literals,operators,punctuators,andotherseparators.Tokensareusuallyseparatedby
4、whitespace.Whitespacecanbeoneormoreblanks,horizontalorverticaltabs,newlines,formfeedsorcomments.,8,精选,9,C+Keywords,autoconstdoublefloatintshortstructunsignedunsignedbreakbreakcontinueelseforlongswitchvoidcasesizeoftypedefchardoifreturnstaticunionwhile,ETC.,9,精选,10,Commenting,/*nameofprogram*informat
5、ionofauthor*functionofprogram*/asampleintmain()/*thisisinthecommentthisisalsointhecomment*/.,10,精选,11,Constants,1,2,31.2,4.50“name”,“your_phonenumber”ture,false0 x121,A,$,xhh,ddd#definePI3.141592#definePRICE100constintpi=3.141592;,11,精选,12,/2.2.cpp,#includeusingnamespacestd;intmain()intx;inty;x=3;y=
6、4;coutx+yendl;return0;,12,精选,13,VariablesTypes,Built-intypesBooleantypebool1byteCharactertypeschar1byteIntegertypesint2-4bytes(2)-3276832767short(2)true,falseCharacterliterals:charc;a,x,4,n,$Integerliterals:intx;0,1,123,-6,0 x34,0 xa3Floatingpointliterals:doubled;floatf;1.2,13.345,.3,-0.54,1.2e3,.3F
7、,.3FStringliterals:strings;asdf,Howdy,allyall!”,14,精选,15,VariablesNames,Choosemeaningfulnamesconfusemtbf,TLA,myw,nbvShortnamescanbemeaningfulxisalocalvariableiisaloopindexDontuselongnamesOk:partial_sum,element_count,staple_partitionToolong:the_number_of_elementsremaining_free_slots_in_the_symbol_tab
8、le,15,精选,16,NotVariablesNames,AnameinaC+programStartswithaletter,containsletters,digits,andunderscores(only)x,number_of_elements,Fourier_transform,z2Notnames:12x,time$to$market,mainlineNotstartnameswithunderscores:_fooNotusekeywordsintifwhile,16,精选,17,Declarationandinitialization,inta=7;intb=9;charc
9、=a;doublex=1.2;strings1=Hello,world;strings2=1.2;,17,9,a,1.2,13Hello,world,4|1.2,b:,c:,x:,s1:,s2:,7,a:,|,精选,18,Constantvariables,constinti=5;i=6;/error,18,精选,19,Thinkabout:,inta,b,c=2;intx,y,z,10;intm=2;intn=3;longintsum=0,add;longhello;chara=m;charb,c,d;charm=65,n=a+1;floata,b,ccc=3.1415;floatsum=0
10、.0;doublef1,f2=1.414e12,19,精选,20,Assignmentandincrement,inta=7;a=9;a=a+a;a+=2;+a;,20,7,9,18,20,21,a:,精选,21,Thinkabout,inta=10,b;b=a;floatx;intk=300;x=k;floatx=3.14;intn;n=x+6;floatx=3.14;intn;n=3;coutx+n;3.0/9or(float)3/9,精选,22,/2.3.cppAprogramtoillustrateintegeroverflow,#includeusingnamespacestd;/*
11、Aprogramtoillustratewhathappenswhenlargeintegers*aremultipliedtogether.*/intmain()intmillion=1000000;inttrillion=million*million;coutAccordingtothiscomputer,millionsquaredistrillion.endl;,22,精选,23,Atype-safetyviolation(“implicitnarrowing”),intmain()inta=20000;charc=a;intb=c;if(a!=b)coutoops!:a!=bn;e
12、lsecoutWow!Wehavelargecharactersn;,23,精选,24,C+characterset,0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_$#()%:;.?*+/charlet=97;CyclethroughtheASCIItablewithmath!charbee=a+1;,26,精选,27,Operators,+,+-,-*/%,27,精选,28,ArithmeticAssignmentOperators,28,Thinkabout:inta=12;a+=a-=a*a;couta;co
13、ut;cinb;couta%b=a%bendl;return0;,30,精选,31,Thinkabout:,17/3=5?5/9=0?intn;n%2+(n+1)%2=?n=2;n+;n=n+1n=2:n+;n-;+n;-n;r=2;m=-n;p=r+;m=10,n=100;p=(n+n,n*n,n-2);p=n+n,n*n,n-2;,31,精选,32,Thinkabout:,inti=2;(i+)+(i+)+(i+);couti;i=2;(-i)+(-i);couti;i=2;i=(i+i+i);couti;i=2;i=(i-i);coutsecond;stringname=first+se
14、cond;coutHello,namen;,33,精选,34,Thinkabout:theoutput?,intx,y;x=10;y=x+;coutyendl;inta,b;a=10;b=+a;coutby)a=!k,37,精选,38,38,Statements,a=b;doubled2=2.5;if(x=2)y=4;while(true)cout“hello”;for(inti=0;i8;i+)coutx;if(x0)x=-x;coutx;coutsqrt(x);,精选,44,/boolleapyear(inty),/*anyyeardivisibleby4exceptcentenaryye
15、arsnotdivisibleby400*/boolleapyear(inty)/anyyeardivisibleby4exceptcentenaryyearsnotdivisibleby400if(y%4)returnfalse;if(y%100=0,精选,45,Conditions2,if(condition)/dothiselse/dothat,if(x0)cout-x;elsecoutb)couta;elsecout=a,精选,47,Conditions3,if(condition)/dothiselseif(condition)/dothatelse/dootherthing,voi
16、dmain()inta=3,b=17,c=5;if(ab)if(bc)coutc)coutc)coutc)coutbca;elsecoutcb0y=f(x)=0 x=0-1x0)k=1;elseif(x=0)k=0;elsek=-1;coutxb?a:b;returnm;,精选,50,if(condition)/dothiselseif(condition)/dothis,conditions4,精选,51,Switches,switch(expression)casei:/dothisbreak;casej:/dothatbreak;default:/dootherthing,精选,52,Switchexample,#includeusingnamespacestd;intmain()intx=6;switch(x)case1:coutxis1n;break;case2:case3:coutxis2or3;break;default:coutxisnot1,2,or3;return0;,精选,53,/weekday,voidweekday(intd)switch(d)case7:coutSun
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 机场安全年度检查计划
- 宾馆客房危险源及管控措施
- 生物实验课程设置计划
- 四年级英语写作能力提升教学计划他
- 广东省中山一中等七校2025届物理高二下期末联考模拟试题含解析
- 河南省黄河湿地生物多样性保护立法研究
- 急诊中心新入院患者收住院暨核酸检测流程
- 重庆市外国语学校2024-2025学年物理八上期末教学质量检测试题含解析
- 新冠肺炎医务人员职业暴露监测流程
- 四川省成都高新东区2024-2025学年物理八年级第一学期期末经典模拟试题含解析
- 教师进企业实践三方协议书
- 施工现场隐患图片识别合集
- 山西省建设工程计价依据
- 煤矿在用安全设备检测检验制度
- GB/T 24632.2-2009产品几何技术规范(GPS)圆度第2部分:规范操作集
- GB/T 20428-2006岩石平板
- GB/T 11363-1989钎焊接头强度试验方法
- 内调焦准距式望远系统光学设计2022年
- 核磁共振的发展史课件
- 切纸机安全操作规程标准范本
- 国家开放大学2022秋法理学形考1-4参考答案
评论
0/150
提交评论