面向对象程序设计期末综合练习四运行结果含答案Word文件下载.docx
- 文档编号:17700082
- 上传时间:2022-12-08
- 格式:DOCX
- 页数:32
- 大小:21.75KB
面向对象程序设计期末综合练习四运行结果含答案Word文件下载.docx
《面向对象程序设计期末综合练习四运行结果含答案Word文件下载.docx》由会员分享,可在线阅读,更多相关《面向对象程序设计期末综合练习四运行结果含答案Word文件下载.docx(32页珍藏版)》请在冰豆网上搜索。
i++)
for(j=1;
j<
=N;
j++)
s+=i*j;
”s=”<
s<
4.#include<
inta=2,b=5,c=0;
if(a+b>
10)c=a*b;
elsec=3*a+b;
if(c<
=20)cout<
c*c;
elsecout<
4+c-5;
a=a+b;
b=a+b;
c+=a+b;
a,b,c="
'
c<
5.#include<
intx=5;
switch(2*x-3){
case4:
cout<
x<
’’;
case7:
2*x+1<
case10:
3*x-1<
break;
default:
default"
switchend."
6.#include<
iomanip.h>
math.h>
inta[4]={36,-5,73,8};
inti,y;
for(i=0;
4;
if(a[i]<
0)y=1;
elseif(a[i]<
10)y=a[i]*a[i]+3;
60)y=4*a[i]-5;
elsey=int(sqrt(a[i]));
//sqrt(x)为取x的平方根函数
setw(5)<
a[i]<
y;
7.#include<
inta[8]={36,25,20,43,12,70,66,35};
ints0,s1,s2;
s0=s1=s2=0;
switch(a[i]%3){
case0:
s0+=a[i];
break;
case1:
s1+=a[i];
case2:
s2+=a[i];
}
s0<
’’<
s1<
s2<
8.#include<
constintN=5;
inti,p=1,s=0;
N;
p=p*i;
s=s+p;
p;
9.#include<
constintM=20;
intc2,c3,c5;
c2=c3=c5=0;
for(inti=1;
if(i%2==0)c2++;
if(i%3==0)c3++;
if(i%5==0)c5++;
c2<
c3<
c5<
10.#include<
inti,j;
5;
i++){
for(j=i;
j++)cout<
’*’;
11.#include<
for(inti=1,s=0;
20;
if(i%2==0||i%3==0)continue;
s+=i;
12.#include<
constintT=6;
=T;
i+=2)
for(j=2;
j+=2){
if(i+j<
T)cout<
’+’;
elsecout<
13.#include<
inta,b,c=0;
for(a=1;
a++)
for(b=6;
b>
1;
b-=2){
if((a+b)%2==0)c+=a+b;
elsec+=a*b;
if(b==2)cout<
14.#include<
constintB=2;
intp=1,s=1;
while(s<
50){
p*=B;
s+=p;
s="
15.#include<
intx=24,y=88;
inti=2,p=1;
do{
while(x%i==0&
&
y%i==0){
p*=i;
x/=i;
y/=i;
i++;
}while(x>
=i&
y>
=i);
p*x*y<
16.#include<
constintN=3;
inta[N][N]={{7,-5,3},{2,8,-6},{1,-4,-2}};
intb[N][N]={{3,6,-9},{2,-8,3},{5,-2,-7}};
inti,j,c[N][N];
for(i=0;
i++)//计算矩阵C
for(j=0;
c[i][j]=a[i][j]+b[i][j];
i++){//输出矩阵C
c[i][j];
17.#include<
inta=5;
voidmain(){
intb=a+20;
inta=10;
{inta=0,b=0;
for(inti=1;
6;
a+=i;
b+=a;
18.#include<
intf1(intx,inty)
x=x+y;
y=x+y;
x="
y="
y<
returnx+y;
intx=5,y=8;
intz=f1(x,y);
z="
z<
19.#include<
voidf2(int&
x,int&
y)
intz=x;
x=y;
y=z;
voidf3(int*x,int*y)
intz=*x;
*x=*y;
*y=z;
intx=10,y=26;
x,y="
"
f2(x,y);
f3(&
x,&
y);
cout<
x++;
y--;
f2(y,x);
20.#include<
voidf4(inta[],intn,int&
s)
{
s=0;
for(inti=0;
n;
i++)s+=a[i];
voidmain()
{
intb[8]={4,8,6,9,2,10,7,12};
intx;
f4(b,5,x);
inty;
f4(b+3,4,y);
x+y<
21.#include<
inta[8]={36,25,48,14,55,40,50,24};
intb1,b2;
b1=b2=a[0];
i++)
if(a[i]>
b1){b2=b1;
b1=a[i];
}
elseif(a[i]>
b2)b2=a[i];
b1<
b2<
22.#include<
voidmain(){
chara[]="
abcdabcabfgacd"
inti1=0,i2=0,i=0;
while(a[i]){
if(a[i]==’a’)i1++;
if(a[i]==’b’)i2++;
i1<
i2<
23.#include<
inta[10]={76,83,54,62,40,75,90,92,77,84};
intb[4]={60,70,90,101};
intc[4]={0};
10;
intj=0;
while(a[i]>
=b[j])j++;
c[j]++;
i++)cout<
c[i]<
24.#include<
string.h>
chara[5][10]={"
student"
"
worker"
soldier"
cadre"
peasant"
};
chars1[10],s2[10];
strcpy(s1,a[0]);
strcpy(s2,a[0]);
if(strcmp(a[i],s1)>
0)strcpy(s1,a[i]);
if(strcmp(a[i],s2)<
0)strcpy(s2,a[i]);
25.#include<
voidfun();
for(inti=1;
i++)
fun();
voidfun()
staticinta;
intb=2;
(a+=3,a+b)<
26.#include<
chars[3][5]={"
1234"
abcd"
+-*/"
char*p[3];
for(intI=0;
I<
3;
I++)p[I]=s[I];
for(I=2;
I>
=0;
I--)cout<
p[I]<
27.#include<
inti,j,len[3];
chara[3][8]={"
year"
month"
day"
for(j=0;
if(a[i][j]=='
\0'
len[i]=j;
}
:
len[i]<
28.#include<
classCD{
char*a;
intb;
public:
voidInit(char*aa,intbb)
a=newchar[strlen(aa)+1];
strcpy(a,aa);
b=bb;
char*Geta(){returna;
intGetb(){returnb;
voidOutput(){cout<
}dx;
voidmain()
{
CDdy;
dx.Init("
abcdef"
30);
dy.Init("
shenyafen"
3*dx.Getb()+5);
dx.Output();
dy.Output();
29.#include<
a=newchar[strlen(aa)+1];
strcpy(a,aa);
b=bb;
};
CDdx,dy;
chara[20];
strcpy(a,dx.Geta());
strcat(a,"
xyz"
);
dy.Init(a,dx.Getb()+20);
30.#include<
classCE{
private:
inta,b;
intgetmax(){return(a>
b?
a:
b);
intc;
voidSetValue(intx1,intx2,intx3){
a=x1;
b=x2;
c=x3;
intGetMax();
intCE:
GetMax(){
intd=getmax();
return(d>
c?
d:
c);
intx=5,y=12,z=8;
CEex,*ep=&
ex;
ex.SetValue(x,y,z);
ex.GetMax()<
ep->
SetValue(x+y,y-z,20);
ep->
GetMax()<
31.#include<
intgetmin(){return(a<
intGetMin();
GetMin(){
intd=getmin();
return(d<
CE*ep;
ep=newCE;
SetValue(x+y,y-z,10);
GetMin()<
CEa=*ep;
a.GetMin()*3+15<
32.#include<
classFranction{//定义分数类
intnume;
//定义分子
intdeno;
//定义分母
//把*this化简为最简分数,具体定义在另外文件中实现
voidFranSimp();
//返回两个分数*this和x之和,具体定义在另外文件中实现
FranctionFranAdd(constFranction&
x);
//置分数的分子和分母分别0和1
voidInitFranction(){nume=0;
deno=1;
//置分数的分子和分母分别n和d
voidInitFranction(intn,intd){nume=n;
deno=d;
//输出一个分数
voidFranOutput(){cout<
nume<
/'
deno<
voidmain()
Franctiona,b,c,d;
a.InitFranction(7,12);
b.InitFranction(-3,8);
c.InitFranction();
c=a.FranAdd(b);
d=c.FranAdd(a);
a:
"
a.FranOutput();
b:
b.FranOutput();
c:
c.FranOutput();
d:
d.FranOutput();
33.#include<
a.InitFranction(6,15);
b.InitFranction(3,10);
34.
#include<
classA{
char*a;
public:
A(char*s){
a=newchar[strlen(s)+1];
strcpy(a,s);
~A(){
delete[]a;
Destructor!
voidmain(){
Ax("
xuxiaokai"
A*y=newA("
weirong"
deletey;
35.
int*a;
A(intx=0):
a(newint(x)){}
~A(){deletea;
intgetA(){return*a;
voidsetA(intx
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 面向 对象 程序设计 期末 综合 练习 运行 结果 答案