C程序的设计编程实例大全.doc
《C程序的设计编程实例大全.doc》由会员分享,可在线阅读,更多相关《C程序的设计编程实例大全.doc(105页珍藏版)》请在课桌文档上搜索。
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;void
2、 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; e
3、*it(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; e*it(1); for(int i=0;in;i+) pi=i*i+1; coutNow output the a
4、rray: 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+=40
5、; 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 &*,int &y);void main() int *=5,y=6; c
6、outbefore swap, *:* ,y:yendl; swap(*,y); coutafter swap, *:* ,y:y;void swap(int &r*,int &ry) int t=r*; r*=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 re
7、sult 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=0;
8、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(float
9、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 c
10、hoice 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 *,int y)
11、int sum; sum=*+y; return sum;int add(int *,int y,int z) int sum; sum=*+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=1,
12、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_Squaretemplate
13、double Circle_Square(T *) return *PI;double Circle_Square(long *) return *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; i=+l-k;
14、 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:print() co
15、utmonth/day/yearendl; coutisLeapYear()endl;void main() Tdate *; *.set(10,23,2000); *.isLeapYear(); *.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) month=m;day
16、=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); #includeus
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 程序 设计 编程 实例 大全
链接地址:https://www.desk33.com/p-6343.html