欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    C++课件(精华版).ppt

    • 资源ID:6154038       资源大小:341KB        全文页数:54页
    • 资源格式: PPT        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C++课件(精华版).ppt

    2、C+programming,A simple C+program Types,variables,expressions,How to write a program,Find the whole steps in the real modelUse some graph or nature language to describeRealize with computer language,workflow,Pseudo Code,A first idea:int main()variableswhile(condition)analyze the expressionevaluate the expressionprint the result,4,main Function,int main(void)return 0;,int x=5;int y=8;int z=x+y;coutx“+”y“=“zendl;,5,#include using namespace std;/*A simple program for demonstrating the basics of a C+project.*It does a good job of demonstrating C+fundamentals,but a*terrible job with the poetry.*/int main()cout Dont you just feel like a louse;cout endl;cout To learn that your new theorem was proved by Gauss?;cout endl;return 0;,6,cout,cout,7,C+Tokens,A token is the smallest element of a C+program that is meaningful to the compiler.Kinds of tokens:identifiers,keywords,literals,operators,punctuators,and other separators.Tokens are usually separated by white space.White space can be one or more blanks,horizontal or vertical tabs,new lines,form feeds or comments.,8,C+Keywords,auto const double float int short struct unsigned unsignedbreak break continue elsefor long switch void case sizeoftypedef char do if returnstatic union while,ETC.,9,Commenting,/*name of program*information of author*function of program*/a sampleint main()/*this is in the comment this is also in the comment*/.,10,Constants,1,2,31.2,4.50“name”,“your_phonenumber”ture,false0 x121,A,$,xhh,ddd#define PI 3.141592#define PRICE 100const int pi=3.141592;,11,/2.2.cpp,#include using namespace std;int main()int x;int y;x=3;y=4;cout x+y endl;return 0;,12,Variables Types,Built-in typesBoolean typebool 1byteCharacter typeschar 1byteInteger typesint 2-4bytes(2)-3276832767short(2)&long(4)-21474836482147483647Floating-point typesdouble 8bytesfloat 4bytes,13,Variables Literals,Boolean literals:bool t;true,falseCharacter literals:char c;a,x,4,n,$Integer literals:int x;0,1,123,-6,0 x34,0 xa3Floating point literals:double d;float f;1.2,13.345,.3,-0.54,1.2e3,.3F,.3FString literals:string s;asdf,Howdy,all yall!”,14,Variables Names,Choose meaningful namesconfusemtbf,TLA,myw,nbvShort names can be meaningfulx is a local variablei is a loop indexDont use long namesOk:partial_sum,element_count,staple_partitionToo long:the_number_of_elementsremaining_free_slots_in_the_symbol_table,15,Not Variables Names,A name in a C+programStarts with a letter,contains letters,digits,and underscores(only)x,number_of_elements,Fourier_transform,z2Not names:12x,time$to$market,main lineNot start names with underscores:_fooNot use keywordsintifwhile,16,Declaration and initialization,int a=7;int b=9;char c=a;double x=1.2;string s1=Hello,world;string s2=1.2;,17,9,a,1.2,13 Hello,world,4|1.2,b:,c:,x:,s1:,s2:,7,a:,|,Constant variables,const int i=5;i=6;/error,18,Think about:,int a,b,c=2;int x,y,z,10;int m=2;int n=3;long int sum=0,add;long hello;char a=m;char b,c,d;char m=65,n=a+1;float a,b,ccc=3.1415;float sum=0.0;double f1,f2=1.414e12,19,Assignment and increment,int a=7;a=9;a=a+a;a+=2;+a;,20,7,9,18,20,21,a:,Think about,int a=10,b;b=a;float x;int k=300;x=k;float x=3.14;int n;n=x+6;float x=3.14;int n;n=3;cout x+n;3.0/9 or(float)3/9,/2.3.cpp A program to illustrate integer overflow,#include using namespace std;/*A program to illustrate what happens when large integers*are multiplied together.*/int main()int million=1000000;int trillion=million*million;cout According to this computer,million squared is trillion.endl;,22,A type-safety violation(“implicit narrowing”),int main()int a=20000;char c=a;int b=c;if(a!=b)cout oops!:a!=b n;elsecout Wow!We have large charactersn;,23,C+character set,0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z _$#()%:;.?*+/&|!=,24,ASCII code,25,Chars to ints,Convert between a char and its ASCII intint num=a;char let=97;Cycle through the ASCII table with math!char bee=a+1;,26,Operators,+,+-,-*/%,27,Arithmetic Assignment Operators,28,Think about:int a=12;a+=a-=a*a;cout a;,29,Expressions,Boolean type:bool(true and false)Equality operators:=(equal),!=(not equal)Logical operators:&(and),|(or),!(not)Relational operators:(greater than),=Character type:char(a,7,and)Integer types:short,int,long arithmetic operators:+,-,*,/,%Floating-point types:float,double(12.45 and 1.234e3)arithmetic operators:+,-,*,/,/2.5.cpp input and output,#include using namespace std;/A program to investigate the behavior of the mod(%)operation.int main()int a,b;cout;cin a;cout;cin b;cout a%b=a%b endl;return 0;,30,Think about:,17/3=5?5/9=0?int n;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,Think about:,int i=2;(i+)+(i+)+(i+);couti;i=2;(-i)+(-i);couti;i=2;i=(i+i+i);couti;i=2;i=(i-i);couti;,/2.6.cpp String input,#include#include using namespace std;int main()cout first second;string name=first+second;cout Hello,name n;,33,Think about:the output?,int x,y;x=10;y=x+;cout y endl;int a,b;a=10;b=+a;cout b endl;,34,Boolean expressions,a b a&btrue true true true false false false true false false false false,a b a|b true true true true false true false true true false false false,a!a true false false true,35,Think about,assume x=6 and y=2!(x 2)false(x y)&(y 0)true(x 0)false(x 0)true,36,Think about,int a,b,c,d,k=1,h=0;a=!k,37,38,Statements,a=b;double d2=2.5;if(x=2)y=4;while(true)cout“hello”;for(int i=0;i8;i+)cout i;int average=(length+width)/2;return x;,Floor,int floor(float x)return(int)x;,39,Ceiling,int ceiling(float x)if(x(int)x 0.0)return(int)(x+1.0);else return(int)x;,40,To be continued,3、C+programming,Control statements,Conditions1,if(condition)/do this,void main()int x;cin x;if(x0)x=-x;cout x;coutsqrt(x);,/bool leapyear(int y),/*any year divisible by 4 except centenary years not divisible by 400*/bool leapyear(int y)/any year divisible by 4 except centenary years not divisible by 400if(y%4)return false;if(y%100=0,Conditions2,if(condition)/do thiselse/do that,if(x0)cout-x;else coutx;,void main()int a=5,b=8;if(ab)cout a;else cout b;,Example,void main()char a;couta;if(a=a,Conditions3,if(condition)/do thiselse if(condition)/do thatelse/do other thing,void main()int a=3,b=17,c=5;if(ab)if(bc)coutc)coutc)coutc)coutbca;else coutcba;,1 x0 y=f(x)=0 x=0-1 x0)k=1;else if(x=0)k=0;else k=-1;coutx k;,Example,(xy)?x:y;,Get the max one of a and bint max(int a,int b)int m=a b?a:b;return m;,if(condition)/do this else if(condition)/do this,conditions4,Switches,switch(expression)case i:/do this break;case j:/do that break;default:/do other thing,Switch example,#include using namespace std;int main()int x=6;switch(x)case 1:cout x is 1n;break;case 2:case 3:cout x is 2 or 3;break;default:cout x is not 1,2,or 3;return 0;,/weekday,void weekday(int d)switch(d)case 7:cout Sunday;break;case 1:cout Monday;break;case 2:cout Tuesday;break;case 3:cout Wednesday;break;case 4:cout Thursday;break;case 5:cout Friday;break;case 6:cout Saturday;break;return;,For Loops,for(initializations;condition;updates)/do this again and again,for(int i=0;i 10;i+)cout i;,

    注意事项

    本文(C++课件(精华版).ppt)为本站会员(牧羊曲112)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开