您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 北邮课件--C++(5)
C++(5)TangXiaoshengBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!!!!!!!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.1!!!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnElem*next_elem();char*strcpy(char*to,char*from);voidexit(int);doublesqrt(double);doublesr2=sqrt(2);doublesr3=sqrt(“three”);//Errordoublesqrt(doubletemperature);BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.1.1!()!!inline()BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnexternvoidswap(int*,int*);//voidswap(int*p,int*q)//{intt=*p;*p=*q;*q=t;}inlineintfac(intn){return(n2)?1:n*fac(n-1);}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.1.2!!staticBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidf(inta){while(a--){staticintn=0;//intx=0;//cout“n=“n++“,x=“x++‘\n’;}}intmain(){f(3);}n=0,x=0n=1,x=0n=2,x=0BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.2!!const!const&constBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(1)voidf(intval,int&ref){val++;ref++;}intstrlen(constchar*);//Cchar*strcpy(char*to,constchar*from);//Cintstrcmp(constchar*,constchar*);//Cvoidg(){inti=1;intj=1;f(i,j);//ij2}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn(2)floatfsqrt(constfloat&);//voidg(doubled){floatr=fsqrt(2.0f);//2.0fr=fsqrt(r);//rr=fsqrt(d);//float(d)}voidupdate(float&i);//voidg(doubled,floatr){update(2.0f);//Error:constupdate(r);//rupdate(d);//Error:update}//float(d)BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.2.1!T[]T*!()!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnintstrlen(constchar*);voidf(){charv[]=“anarray”;inti=strlen(v);intj=strlen(“Nicholas”);}voidcompute1(int*vec_ptr,intvec_size);//structVec{int*ptr;intsize;}voidcompute2(constVec&v);//BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.3!voidvoid!(return)!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnintf1(){}//Error:voidf2(){}//okintf3(){return1;}//okvoidf4(){return1;}//Errorintf5(){return;}//Errorvoidf6(){return;}//okintfac(intn){return(n1)?n*fac(n-1):1;}//intfac2(intn){if(n1)returnn*fac2(n-1);return1;}//doublef(){return1;}//1double(1)int*fp(){intlocal=1;/*…*/return&local;}//Errorint&fr(){intlocal=1;/*…*/returnlocal;}//Errorvoidg(int*p);voidh(int*p){/*…*/returng(p);}//okBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.4!!fff!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn!(TconstT)!(boolintcharintshortint)floatdouble!(intdoubledoubleintdoublelongdoubleDerived*Base*T*void*intunsignedint)!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidprint(double);voidprint(long);voidf(){print(1L);//print(long)print(1.0);//print(double)print(1);//Error:}voidprint(int);voidprint(constchar*);voidprint(double);voidprint(long);voidprint(char);voidh(charc,inti,shorts,floatf){print(c);print(i);//print(s);//print(int)print(f);//floatdoubleprint(‘a’);print(49);//print(0);//print(int)print(“a”);//print(constchar*)}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.4.1!floatsqrt(float);doublesqrt(double);voidf(doubled,floatf){floatfl=sqrt(d);//sqrt(double)doubledb=sqrt(d);//sqrt(double)fl=sqrt(f);//sqrt(float)db=sqrt(f);//sqrt(float)}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.4.2!voidf(int);voidg(){voidf(double);f(1);//f(double)}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.4.3!()!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidf1(char);voidf1(long);voidf2(char*);voidf2(int*);voidk(inti){f1(i);//f2(0);//}voidf1(intn){f1(long(n));}f2(static_castint*(0));BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.4.4!()BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnintpow(int,int);doublepow(double,double);complexpow(double,complex);complexpow(complex,int);complexpow(complex,double);complexpow(complex,complex);voidk(complexz){inti=pow(2,2);//pow(int,int)doubled=pow(2.0,2.0);//pow(double,double)complexz2=pow(2,z);//pow(double,complex)complexz3=pow(z,2);//pow(complex,int)complexz4=pow(z,z);//pow(complex,complex)}doubled=pow(2.0,2);BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.5!!!!BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnvoidprint(intvalue,intbase=10);voidf(){print(31);print(31,10);print(31,16);print(32,2);}31311f11111voidprint(intvalue,intbase);voidprint(intvalue){print(value,10);}intf(int,int=0,char*=0);//okintg(int=0,int=0,char*);//Errorinth(int=0,int,char*=0);//Errorintnasty(char*=0);//SyntaxErrorvoidf(intx=7);voidf(int=7);//Error:voidf(int=8);//Error:voidg(){voidf(intx=9);//ok}BeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cn7.6!(...)!C++!cstdargBeijingUniversityofPosts&Telecommunicationsyoung@buptnet.edu.cnintprintf(constchar*...);printf(“Hello,world!\n”);printf(“Mynameis%s%s\n”,first_name,last_name);printf(“%d+%d=%d\n”,2,3,5);#includestdio.hintmain(){printf(“Mynameis%s%s\n”
本文标题:北邮课件--C++(5)
链接地址:https://www.777doc.com/doc-4043460 .html