c++试题库编程题.docx

上传人:王** 文档编号:1070159 上传时间:2024-03-24 格式:DOCX 页数:22 大小:35.11KB
下载 相关 举报
c++试题库编程题.docx_第1页
第1页 / 共22页
c++试题库编程题.docx_第2页
第2页 / 共22页
c++试题库编程题.docx_第3页
第3页 / 共22页
c++试题库编程题.docx_第4页
第4页 / 共22页
c++试题库编程题.docx_第5页
第5页 / 共22页
c++试题库编程题.docx_第6页
第6页 / 共22页
c++试题库编程题.docx_第7页
第7页 / 共22页
c++试题库编程题.docx_第8页
第8页 / 共22页
c++试题库编程题.docx_第9页
第9页 / 共22页
c++试题库编程题.docx_第10页
第10页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《c++试题库编程题.docx》由会员分享,可在线阅读,更多相关《c++试题库编程题.docx(22页珍藏版)》请在优知文库上搜索。

1、/2-5#include#include#includeusingnamespacestd;classTriangleinta,b,c;public:doubleArea()(doubles=(a+b+c)2;returnsqrt(s*(s-a)*(s-b)*(s-c););intPerimeterOreturna+b+c;)voidInput()cinabc;);voidmain()Triangletl;tl.Input();couttl.Area(),tl.Perimeter();)/2-3#includeinlineintmax(intajntb)(if(ab)returna;elser

2、eturnb;Jinlineintmax(inta,intb,intc)(returnmax(a,max(b,c);)voidmain()(intx=2l,y=15,z=22,d;d=max(x,max(y,z);coutd;)/2-4#includeintoverload(intn);charoverload(charn);voidmain()(intn;chars;CoUtn;coutn=,overload(n)endl;COUt”输入a,s;couta=;coutoverload(s)endl;)intoverload(intn)(returnn;)charoverload(charn)

3、(coutbendl;returnO;)/2-2#includeiostreamusingnamespacestd;inlinechartrans(charch);intmain()(charch;while(ch=getchar()!=n,)couttrans(ch);cout=aAfcch=,z,)returnch-32;elsereturnch+32;)/3-l#inc1udeusingstd:cout;usingstd:endl;intMin(inta,intb)(return(ab?a:b);)intMin(inta,intb,intc)return(Min(a,b)c?Min(a,

4、b):c);intMin(inta,intb,intc,intd)(return(Min(a,b,c)d?Min(a,b,c):d);)voidmain(void)(coutMIN(l,2)=,Min(l,2)endl;coutMIN(3,4,5)=,Min(3A5)endl;coutMIN(4,5,6,7)=,Min(4,5,6,7)endl;)/3-2#includeusingnamespacestd;voidArea(floatr)(coutthecirclesareais:3.14*r*rendl;)voidArea(floata,floatb)(couttherectangles(s

5、quare,s)areais:,a*bendl;)voidArea(floata,floatb,floath)(coutthetrapzoid,sareais:,(a+b)*h2endl;)voidmain()(Area(5);Area(3,3);Area(3,5,4);)/3-3#includeusingnamespacestd;voidSort(inta,intn)(boolflag;fbr(inti=0jn-l;i+)(flag=false;fbr(intj=l;jaj)inttemp=aj-l;aj-l=aj;ajj=temp;flag=true;)if(!flag)break;1fo

6、r(intm=O;mn;m+)coutam;coutendl;)voidSort(floatblJ,intn)(boolflag;fr(inti=0;in-l;i+)(flag=false;fbr(intj=l;jbUD(floattemp=bj-l;bj-l=bj;bj=temp;flag=true;)if(!flag)break;1for(intm=0;mn;m+)coutbm,;coutendl;)voidmain()(intal0=3,5,2,9,0,8,6,4,7;floatbl10=0.1,0.2,03A4,0.5,0.6,0.7,0.8,0.9,1.0);Sort(a,10);S

7、ort(b,10);)/3-4#includeusingnamespacestd;classRectanglefloata,b;public:RectangleO(coutinputthetwosideoftherectangle:ab;1Rectangle(floatx,floaty):a(x),b(y)floatCir()(return(2*(a+b);1floatArea()(return(a*b);11;voidmain()(RectangleRe;couttherectanglescircumferenceis:Re.Cir()endltherectanglesareais:Re.A

8、rea()endl;)/3-5#includeusingnamespacestd;classCircle(floatr;public:Circle()(coutinputtheradiusofthecircle:,r;1Circle(floatx):r(x)floatCir()(return2*3.14*r;)floatArea()(return3.l4*r*r;)1;voidmain()CircleC(5);couttheCirclescircumferenceisfC.Cir()endltheCirclesAreais:C.Area()endl;)/4-lclassstudent(intn

9、o;charname20;public:student();intgetno()const;char*getname();1;#includestudent:student()(no=l;strcpy(name,wang);)intStudentzrgetno()const(returnno;)char*student:getname()(returnname;)intmain()(studentsi;sl.getno();sl.getname();conststudents2;s2.getno();returnO;)/4-3#includeclassobject(floata;floatwe

10、ight;public:object(floatw);object()coutdestructweightendl;);classbox:publicobject(floatb;floatheight,widt;public:box(floatw,floath,floatwi):object(w),height(h),widt(wi)coutnconstructheightHendl;coutconstructwidtendl;-box()coutdestructheightendl;coutndestructwidtendl;1;object:object(floatw)(weight=w;

11、coutconstructweightendl;)intmain()(boxb(1.1,2.2,3.3);return0;)/4-4#includeiostreamusingnamespacestd;classbaseclass(public:baseclass()cout,a.cendl;Jvirtual-baseclass()coutadendl;);classderivedclass:publicbaseclass(public:derivedclass()coutb.cendl;)derivedclass()cout,b.dendl;);intmain()(derivedclassob

12、j;baseclass*p;P=&obj;return0;/4-5#includeiostream#includeusingnamespacestd;classDoument(char*name;public:Doument(char*na)(name=newcharstrlen(na)+l;strcpy(name,na);1virtualvoidprint()COnStcout姓名:,nameendl;);classBookipublicDoument(intpagecount;char*name;public:Book(intp,char*na):Doument(na)(p=pagecount;name=newcharstrlen(na)+l;strcpy(name,na);)voidprint()ConStcout页码:pagecount姓名:nameendl;1;voiddisp(Doument&i)(i.print();)intmain()(Bookb(23,“小明”);disp(b);returnO;)/5

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 习题/试题

copyright@ 2008-2023 yzwku网站版权所有

经营许可证编号:宁ICP备2022001189号-2

本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!