C++程序设计编程实例大全(106页).doc
《C++程序设计编程实例大全(106页).doc》由会员分享,可在线阅读,更多相关《C++程序设计编程实例大全(106页).doc(107页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、-C+程序设计编程实例大全#includeint main() std:couthello world!;#include iostreamusing namespace std;void main() int *p; p=new int; *p=5; /*p=new int(5);*/ cout*p; delete p; #include iostreamusing namespace std;void main() char name10; coutname; coutthe name is nameendl; #include iostreamusing namespace std;vo
2、id main() char name10; int age; coutname; coutage; coutthe name is nameendl; coutthe age is agen; student wang; wang.no=n; cinwang.math; coutwang.no wang.mathendl; #include iostreamusing namespace std;void main() int *p; int n; coutn; if(p=new intn)=0) coutcant allocate more memory, terminatingendl;
3、 exit(1); for(int i=0;in;i+) pi=i*2; coutNow output the array: endl; for(i=0;in;i+) coutpi endl; delete p; #include iostreamusing namespace std;void main() int *p; int n; coutn; if(p=new intn)=0) coutcant allocate more memory, terminatingendl; exit(1); for(int i=0;in;i+) pi=i*i+1; coutNow output the
4、 array: endl; for(i=0;in;i+) coutpi ; coutendl; delete p; /* Note:Your choice is C IDE */#include using namespace std;float a=2.4;void main() int a=8; coutaendl; cout:aendl; /* Note:Your choice is C IDE */#include void main() int num=50; int &ref=num; ref+=10; coutnum=numendl; coutref=refendl; num+=
5、40; coutnum=numendl; coutrefrefendl; /* Note:Your choice is C IDE */#include void main() int num; int &ref=num; num=5; coutnum=numendl; coutref=refendl; cout&num=&numendl; cout&ref=&refendl; /* Note:Your choice is C IDE */#include using namespace std;void swap(int &x,int &y);void main() int x=5,y=6;
6、 coutbefore swap, x:x ,y:yendl; swap(x,y); coutafter swap, x:x ,y:y;void swap(int &rx,int &ry) int t=rx; rx=ry; ry=t;#include/using namespace std;void main()/* double radius; coutradius; double result=radius*radius*3.14*4; coutThe result is (double)resultn;*/double radius;std:coutradius;std:coutThe
7、result is radius*radius*3.14*4n;/* Note:Your choice is C IDE */#include using namespace std;int array64=60,80,90,75,75,85,65,77,80,88,90,98,89,100,78,81,62,68,69,75,85,85,77,91;int &level(int grade,int size,int &tA,int &tB );void main() int typeA=0,typeB=0; int student=6; int gradesize=4; for(int i=
8、0;istudent;i+) level(arrayi,gradesize,typeA,typeB)+; coutnumber of type A is typeAendl; coutnumber of type B is typeBendl; int &level(int grade,int size,int &tA,int &tB) int sum=0; for(int i=0;i=80) return tA; else return tB;/* Note:Your choice is C IDE */#include using namespace std;float &fn2(floa
9、t r) float t; t=3.14*r*r; return t;void main() fn2(5.0)=12.4; coutfn2(5.0)endl; /* Note:Your choice is C IDE */#include #include using namespace std;void main() string s,t; coutplease input a zifuchuan:s; t=I like programming!; coutzifuchuan output:endlsendltendl; couts.append( OK!)endl;/* Note:Your
10、 choice is C IDE */#include using namespace std;inline double circumference(double radius);void main() double r=3.0,s; s=circumference(r); coutthe circumference is s.endl; inline double circumference(double radius) return 2*3.1415926*radius;/* Note:Your choice is C IDE */#include int add(int x,int y
11、) int sum; sum=x+y; return sum;int add(int x,int y,int z) int sum; sum=x+y+z; return sum;void main() int a,b; a=add(5,10); b=add(5,10,20); couta=aendl; coutb=bendl; /* Note:Your choice is C IDE */#include templateT min(T a,int n) int i; T minv=a0; for(i=1;iai) minv=ai; return minv; void main() int a
12、=1,3,0,2,7,6,4,5,2; double b=1.2,-3.4,6.8,9.8; int c=1,9,5,-6,7,8; couta de shuzu zhong min zhi wei:min(a,9)endl; coutb de shuzu zhong min zhi wei:min(b,4)endl; coutc de shuzu zhong min zhi wei:min(c,6)endl; /* Note:Your choice is C IDE */#include #define PI 3.1415926535#define CS Circle_Squaretempl
13、atedouble Circle_Square(T x) return x*x*PI;double Circle_Square(long x) return x*x*PI;void main() int r1=1; double r2=2.0; long r3=3; coutThe first cs is CS(r1)endl; coutThe second cs is CS(r2)endl; coutThe third cs is CS(r3)endl; /* Note:Your choice is C IDE */#include void main() int i=0,&l=i,&k=l
14、; i=+l-k; couti=iendl; /* Note:Your choice is C IDE */#include class Tdatepublic:void set(int,int,int);int isLeapYear();void print();private:int month;int day;int year;void Tdate:set(int m,int d,int y) month=m;day=d;year=y;int Tdate:isLeapYear() return(year%4=0&year%100!=0)|(year%400=0);void Tdate:p
15、rint() coutmonth/day/yearendl; coutisLeapYear()endl;void main() Tdate x; x.set(10,23,2000); x.isLeapYear(); x.print(); /* Note:Your choice is C IDE */#include class Tdatepublic:void set(int,int,int);int isLeapYear();void print();private:int month;int day;int year;void Tdate:set(int m,int d,int y) mo
16、nth=m;day=d;year=y;int Tdate:isLeapYear() return(year%4=0&year%100!=0)|(year%400=0);void Tdate:print() coutyear/month/dayendl;void someFunc(Tdate& refs) refs.print(); if(refs.isLeapYear() couterrorendl; else coutrightprint(); if(*pTdate).isLeapYear() couterrorendl; else coutrightendl; someFunc(s); #
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 程序设计 编程 实例 大全 106
限制150内