ImageVerifierCode 换一换
格式:DOCX , 页数:39 ,大小:20.17KB ,
资源ID:3125637      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-3125637.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c题库编程题.docx)为本站会员(b****1)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

c题库编程题.docx

1、c题库编程题/2-5#include#include#includeusing namespace std;class Triangle int a,b,c;public: double Area() double s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c); ; int Perimeter() return a+b+c; void Input() cinabc; ; void main() Triangle t1; t1.Input(); coutt1.Area() t1.Perimeter(); /2-3#includeinline int m

2、ax(int a,int b) if(ab)return a; else return b; inline int max(int a,int b,int c) return max(a,max(b,c); void main() int x=21,y=15,z=22,d; d=max(x,max(y,z); coutd;/2-4#includeint overload(int n);char overload(char n);void main() int n; char s; coutn; coutn=overload(n)endl; cout输入as; couta=; coutoverl

3、oad(s)endl;int overload(int n) return n;char overload(char n)coutbendl;return 0;/2-2#includeiostreamusing namespace std;inline char trans(char ch);int main() char ch; while(ch=getchar()!=n) couttrans(ch); cout=a&ch=z) return ch-32; else return ch+32;/3-1#includeusing std:cout;using std:endl;int Min(

4、int a,int b) return (aba:b);int Min(int a,int b,int c) return (Min(a,b)cMin(a,b):c);int Min(int a,int b,int c,int d) return (Min(a,b,c)dMin(a,b,c):d);void main(void) coutMIN(1,2)=Min(1,2)endl; coutMIN(3,4,5)=Min(3,4,5)endl; coutMIN(4,5,6,7)=Min(4,5,6,7)endl;/3-2#includeusing namespace std;void Area(

5、float r) coutthe circles area is: 3.14*r*rendl;void Area(float a,float b) coutthe rectangles(squares) area is: a*bendl;void Area(float a,float b,float h) coutthe trapzoids area is: (a+b)*h/2endl;void main() Area(5); Area(3,3); Area(3,5,4);/3-3#includeusing namespace std;void Sort(int a,int n) bool f

6、lag; for(int i=0;in-1;i+) flag=false; for(int j=1;jaj) int temp=aj-1; aj-1=aj; aj=temp; flag=true; if(!flag) break; for(int m=0;mn;m+) coutam ; coutendl;void Sort(float b,int n) bool flag; for(int i=0;in-1;i+) flag=false; for(int j=1;jbj) float temp=bj-1; bj-1=bj; bj=temp; flag=true; if(!flag) break

7、; for(int m=0;mn;m+) coutbm ; coutendl;void main() int a10=3,5,1,2,9,0,8,6,4,7; float b10=0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0; Sort(a,10); Sort(b,10);/3-4#includeusing namespace std;class Rectangle float a,b;public: Rectangle() coutinput the two side of the rectangle:ab; Rectangle(float x,float

8、y):a(x),b(y) float Cir() return (2*(a+b); float Area() return (a*b); ;void main() Rectangle Re; coutthe rectangles circumference is:Re.Cir()endl the rectangles area is:Re.Area()endl;/3-5#includeusing namespace std;class Circle float r;public: Circle() coutinput the radius of the circle:r; Circle(flo

9、at x):r(x) float Cir() return 2*3.14*r; float Area() return 3.14*r*r;void main() Circle C(5); cout the Circles circumference is:C.Cir()endl the Circles Area is:C.Area()endl;/4-1class student int no; char name20;public: student(); int getno()const; char*getname();#includestudent:student() no=1; strcp

10、y(name,wang);int student:getno ()const return no; char*student:getname() return name;int main() student s1; s1.getno(); s1.getname(); const student s2; s2.getno(); return 0;/4-3#includeclass object float a; float weight;public: object(float w); object()coutdestruct weightendl;class box:public object

11、 float b; float height,widt;public: box(float w,float h,float wi):object(w),height(h),widt(wi)coutconstruct heightendl;coutconstruct widtendl; box()coutdestruct heightendl;coutdestruct widtendl;object:object(float w) weight=w; coutconstruct weightendl;int main() box b(1.1,2.2,3.3); return 0;/4-4#inc

12、ludeiostreamusing namespace std;class baseclasspublic: baseclass()couta.cendl; virtual baseclass()couta.dendl;class derivedclass:public baseclasspublic: derivedclass()coutb.cendl; derivedclass()coutb.dendl;int main() derivedclass obj; baseclass *p; p=&obj; return 0;/4-5#includeiostream#includeusing

13、namespace std;class Doument char *name;public: Doument(char *na) name=new char strlen (na)+1; strcpy(name,na); virtual void print() const cout姓名:nameendl;class Book:public Doument int pagecount; char *name;public: Book(int p,char *na):Doument(na) p=pagecount; name=new char strlen (na)+1; strcpy(name

14、,na); void print() const cout页码:pagecount姓名:nameendl;void disp(Doument& i) i.print();int main() Book b(23,小明); disp(b); return 0;/5-1#includeiostreamusing namespace std;class pointprivate: int x; int y; int z; static int num;public: point(int a,int b,int c); int print();int point:num=0;int main() po

15、int p1(1,2,3); p1.print(); point p2(5,3,2); p1.print(); point p3(3,6,4); p1.print(); return 0; point:point(int a,int b,int c) x=a; y=b; z=c; num+; int point:print() cout第num个点x,y,zendl; return 0;/5-2#include#includeusing namespace std;class Stu char name15; int age; float score;public: static int co

16、unt; static float sum; Stu(char *p,int a,float s):age(a),score(s) strcpy(name,p); count+; sum+=score; Stu() coutinput the students name,age,score:nameagescore; count+; sum+=score; ;int Stu:count=0;float Stu:sum=0;void main() Stu p(子机,19,98),q; coutthe number of students is: Stu:countendl the total s

17、core is: Stu:sumendl;/5-3#includeusing namespace std;class Point float x,y,z;public: Point(float a=0,float b=0,float c=0):x(a),y(b),z(c) Point operator +(); Point operator -(); Point operator +(int); Point operator -(int); void show() cout( x , y , z ) = ( x , y , z )endl; ;Point Point:operator +()

18、return Point(+x,+y,+z);Point Point:operator -() return Point(-x,-y,-z);Point Point:operator +(int) Point temp; temp.x=x+; temp.y=y+; temp.z=z+; return temp;Point Point:operator -(int) Point temp; temp.x=x-; temp.y=y-; temp.z=z-; return temp;void main() Point a(1,1,1),b(2,2,2),c,d; couta :; a.show();

19、 coutb :; b.show(); coutendl; c=a+; coutc = a+n; coutc :; c.show(); coutendl; d=+b; coutd = +bn; coutd :; d.show(); coutNew a and b :n; a.show(); b.show(); coutendl; c=a-; coutc = a-n; coutc :; c.show(); coutendl; d=-b; coutd = -bn; coutd :; d.show(); coutNew a and b :n; a.show(); b.show();/5-4#incl

20、udeusing namespace std;class Complex float real,image;public: Complex(float a,float b):real(a),image(b) Complex() friend bool operator =(Complex &x,Complex &y) return (x.real=y.real&x.image=y.image);void main() Complex Cp1(1,2),Cp2(3,4),Cp3(1,2); cout(Cp1=Cp2)endl (Cp1=Cp3)endl;/6-1#includeusing nam

21、espace std;class Complex float real,image;public: Complex(float x,float y):real(x),image(y) Complex() Complex operator +(Complex &a) return Complex(real+a.real,image+a.image); Complex operator -(Complex &b) return Complex(real-b.real,image-b.image); friend ostream & operator (ostream &output,Complex

22、 &c) output(c.real,c.image); return output; ;void main() Complex Cp1(1,-2),Cp2(2,5),Cp3,Cp4; Cp3=Cp1+Cp2; Cp4=Cp1-Cp2; coutCp1+Cp2=Cp3endl Cp1-Cp2=Cp4endl;/6-2#includeusing namespace std;class computer float x,y;public: computer(float a=0,float b=0):x(a),y(b) computer operator +(); computer operator

23、 -(); computer operator +(int); computer operator -(int); void show() cout( x , y ) = ( x , y )endl; ;computer computer:operator +() return computer(+x,+y);computer computer:operator -() return computer(-x,-y);computer computer:operator +(int) computer temp; temp.x=x+; temp.y=y+; return temp;compute

24、r computer:operator -(int) computer temp; temp.x=x-; temp.y=y-; return temp;void main() computer a(1,1),b(2,2),c,d; couta :; a.show(); coutb :; b.show(); coutendl; c=a+; coutc = a+n; coutc :; c.show(); coutendl; d=+b; coutd = +bn; coutd :; d.show(); coutNew a and b :n; a.show(); b.show(); coutendl; c=a-; coutc = a-n; coutc :; c.show(); coutendl; d=-b; coutd = -bn; coutd :; d.show(); coutNew a and b :n; a.show(); b.show();/6-3#include#include

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2