c++题库编程题Word文档下载推荐.docx
- 文档编号:17059222
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:34
- 大小:20.27KB
c++题库编程题Word文档下载推荐.docx
《c++题库编程题Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《c++题库编程题Word文档下载推荐.docx(34页珍藏版)》请在冰豆网上搜索。
d;
//2-4
intoverload(intn);
charoverload(charn);
intn;
chars;
输入5"
;
cin>
n;
n="
overload(n)<
endl;
输入a"
s;
a="
overload(s)<
intoverload(intn)
returnn;
charoverload(charn)
cout<
b"
return0;
//2-2
#include"
iostream"
inlinechartrans(charch);
intmain()
charch;
while((ch=getchar())!
='
\n'
)
cout<
trans(ch);
return0;
inlinechartrans(charch)
if(ch>
a'
&
ch<
z'
returnch-32;
else
returnch+32;
//3-1
usingstd:
:
cout;
intMin(inta,intb)
return(a<
b?
a:
b);
intMin(inta,intb,intc)
return(Min(a,b)<
c?
Min(a,b):
c);
intMin(inta,intb,intc,intd)
return(Min(a,b,c)<
d?
Min(a,b,c):
d);
voidmain(void)
MIN(1,2)="
Min(1,2)<
MIN(3,4,5)="
Min(3,4,5)<
MIN(4,5,6,7)="
Min(4,5,6,7)<
//3-2
voidArea(floatr)
thecircle'
sareais:
3.14*r*r<
voidArea(floata,floatb)
therectangle'
s(square'
s)areais:
a*b<
voidArea(floata,floatb,floath)
thetrapzoid'
(a+b)*h/2<
Area(5);
Area(3,3);
Area(3,5,4);
//3-3
voidSort(inta[],intn)
boolflag;
for(inti=0;
i<
n-1;
i++)
flag=false;
for(intj=1;
j<
n-i;
j++)
if(a[j-1]>
a[j])
{
inttemp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
flag=true;
}
if(!
flag)
break;
for(intm=0;
m<
m++)
a[m]<
'
'
voidSort(floatb[],intn)
if(b[j-1]>
b[j])
floattemp=b[j-1];
b[j-1]=b[j];
b[j]=temp;
b[m]<
inta[10]={3,5,1,2,9,0,8,6,4,7};
floatb[10]={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
classRectangle
floata,b;
Rectangle()
inputthetwosideoftherectangle:
cin>
b;
Rectangle(floatx,floaty):
a(x),b(y){}
floatCir()
return(2*(a+b));
floatArea()
return(a*b);
};
RectangleRe;
scircumferenceis:
Re.Cir()<
endl
<
Re.Area()<
//3-5
classCircle
floatr;
Circle()
inputtheradiusofthecircle:
r;
Circle(floatx):
r(x){}
{return2*3.14*r;
{return3.14*r*r;
CircleC(5);
cout<
theCircle'
C.Cir()<
sAreais:
C.Area()<
//4-1
classstudent
intno;
charname[20];
student();
intgetno()const;
char*getname();
string.h>
student:
student()
no=1;
strcpy(name,"
wang"
);
intstudent:
getno()const
returnno;
char*student:
getname()
returnname;
students1;
s1.getno();
s1.getname();
conststudents2;
s2.getno();
//4-3
classobject
floata;
floatweight;
object(floatw);
~object(){cout<
destructweight"
classbox:
publicobject
floatb;
floatheight,widt;
box(floatw,floath,floatwi):
object(w),height(h),widt(wi){cout<
constructheight"
constructwidt"
~box(){cout<
destructheight"
destructwidt"
object:
object(floatw)
weight=w;
constructweight"
boxb(1.1,2.2,3.3);
//4-4
classbaseclass
baseclass(){cout<
a....c"
virtual~baseclass(){cout<
a......d"
classderivedclass:
publicbaseclass
derivedclass(){cout<
b....c"
~derivedclass(){cout<
b....d"
derivedclassobj;
baseclass*p;
p=&
obj;
//4-5
classDoument
char*name;
Doument(char*na)
name=newchar[strlen(na)+1];
strcpy(name,na);
virtualvoidprint()const{cout<
姓名:
name<
classBook:
publicDoument
intpagecount;
Book(intp,char*na):
Doument(na)
p=pagecount;
strcpy(name,na);
voidprint()const{cout<
页码:
pagecount<
姓名:
voiddisp(Doument&
i)
i.print();
Bookb(23,"
小明"
disp(b);
//5-1
classpoint
{private:
intx;
inty;
intz;
staticintnum;
point(inta,intb,intc);
intprint();
intpoint:
num=0;
pointp1(1,2,3);
p1.print();
pointp2(5,3,2);
pointp3(3,6,4);
point:
point(inta,intb,intc)
x=a;
y=b;
z=c;
num++;
intpoint:
print()
第"
num<
个点"
x<
"
y<
z<
//5-2
cstring>
classStu
charname[15];
intage;
floatscore;
staticintcount;
staticfloatsum;
Stu(char*p,inta,floats):
age(a),score(s)
strcpy(name,p);
count++;
sum+=score;
Stu()
inputthestudent'
sname,age,score:
name>
age>
score;
intStu:
count=0;
floatStu:
sum=0;
Stup("
子机"
19,98),q;
thenumberofstudentsis:
Stu:
count<
thetotalscoreis:
sum<
//5-3
classPoint
floatx,y,z;
Point(floata=0,floatb=0,floatc=0):
x(a),y(b),z(c){}
Pointoperator++();
Pointoperator--();
Pointoperator++(int);
Pointoperator--(int);
voidshow()
(x,y,z)="
<
("
"
)"
PointPoint:
operator++()
returnPoint(++x,++y,++z);
operator--()
returnPoint(--x,--y,--z);
operator++(int)
Pointtemp;
temp.x=x++;
temp.y=y++;
temp.z=z++;
returntemp;
operator--(int)
temp.x=x--;
temp.y=y--;
temp.z=z--;
Pointa(1,1,1),b(2,2,2),c,d;
a:
a.show();
b:
b.show();
c=a++;
c=a++\n"
c:
c.show();
d=++b;
d=++b\n"
d:
d.show();
Newaandb:
\n"
c=a--;
c=a--\n"
d=--b;
d=--b\n"
//5-4
classComplex
floatreal,image;
Complex(floata,floatb):
real(a),image(b){}
Complex(){}
friendbooloperator==(Complex&
x,Complex&
y)
{return(x.real==y.real&
x.image==y.image);
ComplexCp1(1,2),Cp2(3,4),Cp3(1,2);
(Cp1==Cp2)<
(Cp1==Cp3)<
//6-1
Complex(floatx,floaty):
real(x),image(y){}
Complexoperator+(Complex&
a)
{returnComplex(real+a.real,image+a.image);
Complexoperator-(Complex&
b)
{returnComplex(real-b.real,image-b.image);
friendostream&
operator<
(ostream&
output,Complex&
c)
output<
('
c.real<
'
c.image<
)'
returnoutput;
ComplexCp1(1,-2),Cp2(2,5),Cp3,Cp4;
Cp3=Cp1+Cp2;
Cp4=Cp1-Cp2;
Cp1<
+'
Cp2<
Cp3<
-'
Cp4<
//6-2
classcomputer
floatx,y;
computer(floata=0,floatb=0):
x(a),y(b){}
computeroperator++();
computeroperator--();
computeroperator++(int);
computeroperator--(int);
(x,y)="
computercomputer:
returncomputer(++x,++y);
returncomputer(--x,--y);
computertemp;
computera(1,1),b(2,2),c,d;
//6-3
#in
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 题库 编程