C++程序设计综合练习题读程序写结果题.docx

上传人:b****4 文档编号:27246586 上传时间:2023-06-28 格式:DOCX 页数:21 大小:162.79KB
下载 相关 举报
C++程序设计综合练习题读程序写结果题.docx_第1页
第1页 / 共21页
C++程序设计综合练习题读程序写结果题.docx_第2页
第2页 / 共21页
C++程序设计综合练习题读程序写结果题.docx_第3页
第3页 / 共21页
C++程序设计综合练习题读程序写结果题.docx_第4页
第4页 / 共21页
C++程序设计综合练习题读程序写结果题.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

C++程序设计综合练习题读程序写结果题.docx

《C++程序设计综合练习题读程序写结果题.docx》由会员分享,可在线阅读,更多相关《C++程序设计综合练习题读程序写结果题.docx(21页珍藏版)》请在冰豆网上搜索。

C++程序设计综合练习题读程序写结果题.docx

C++程序设计综合练习题读程序写结果题

 

C++程序设计综合练习题-读程序写结果题(总13页)

C++程序设计模拟题

三、用C++语言描述下列命题

1、A小于B并且A大于C

2、A和B中有—个小于C

3、A是奇数

4、B和C中较大者与A相等

5、年份Y是闰年

四、写出下列程序的执行结果

1.

#include

voidmain()

{

intb[3][5]={11,12,13,14,15,21,22,23,24,25,31,32,33,34,35};

int(*p)[5];

p=b;

for(intj=0;j<5;j++)

cout<<*(*p+j)<<",";

cout<

}

2.

#include<>

voidswapl(inta,intb)

{

inttemp=a;

a=b;

b=temp;

}

voidswap2(int*a,int*b)

{

inttemp=*a;

*a=*b,*b=temp;

}

voidswap3(int*a,int*b)

{

int*temp=a;

a=b,b=temp;

}

voidswap4(int&a,int&b)

{

inttemp=a;

a=b;b=temp;

}

voidmain()

{

inta=10,b=20;

swapl(a,b);

cout<

"<

swap2(&a,&b);

cout<

"<

swap3(&a,&b);

cout<

"<

swap4(a,b);

cout<

"<

}

3.&&&

#include

voidprint(intw)

{

inti;

if(w!

=0)

{

print(w-1);

for(i=1;i<=w;i++)

cout<

cout<

}

}

voidmain()

{

print(4);

}

4.

#include<>

#definesw(x,y){x^=y;y^=x;x^=y;}

voidmain()

{

inta=10,b=01;

sw(a,b);

cout<

}

5.假定输入10个整数:

32,64,53,87,54,32,98,56,98,83。

下列程序的输出结果是什么&&&

#include<>

voidmain()

{

inta,b,c,x;

a=b=c=0;

for(intk=0;k<10;k++)

{

cin>>x;

switch(x%3)

{

case0:

a+=x;break;

case1:

b+=x;break;

case2:

c+=x;break;

}

}

cout<

}

6.***

#include<>

voidmain()

{intj,k;

for(j=5;j>0;j--)

{for(k=j;k>0;k--)

cout<<"*";

cout<

}

}

7.

#include<>

voidmain()

{

intnNumber;

int*pPointer;

nNumber=15;

pPointer=&nNumber;

cout<<"nNumberisequalto:

"<

*pPointer=25;

cout<<"nNumberisequalto:

"<

}

8.

#include<>

int*pPointer;

voidSomeFunction()

{

pPointer=newint;

*pPointer=25;

}

voidmain()

{

SomeFunction();

cout<<"Valueof*pPointer:

"<<*pPointer<

deletepPointer;

}

9.

#include<>

voidAddFive(int*Number)

{

*Number=*Number+5;

}

voidmain()

{

intnMyNumber=18;

cout<<"Myoriginalnumberis"<

AddFive(&nMyNumber);

cout<<"Mynewnumberis"<

}

10.

#include<>

voidmain()

{

intArray[3];

Array[0]=10;

Array[1]=20;

Array[2]=30;

int*pArray;

pArray=&Array[0];

cout<<"pArraypointstothevalue."<

cout<<*pArray<

cout<<*(pArray+1)<

}

11.***

#include<>

inti=4;

voidmain()

{

cout<<"i="<

i=5;

{

inti;

i=7;

cout<<"i="<

}

cout<<"i="<

}

12.***

#include<>

voidfun();

voidmain()

{

fun();

fun();

}

voidfun()

{

staticinta=1;

inti=5;

a++;

i++;

cout<<"i="<

}

13.&&&

#include<>

classPoint

{public:

Point(intxx=0,intyy=0){X=xx;Y=yy;countP++;}

Point(Point&p);

intGetX(){returnX;}

intGetY(){returnY;}

voidGetC(){cout<<"Objectid="<

private:

intX,Y;

staticintcountP;

};

Point:

:

Point(Point&p)

{X=;

Y=;

countP++;

}

intPoint:

:

countP=0;

voidmain()

{PointA(4,5);

cout<<"PointA,"<<()<<","<<();

();

PointB(A);

cout<<"PointB,"<<()<<","<<();

();

}

14.***

#include<>

intaddDefault(intx=1,inty=2);

voidfun(void);

voidmain(void)

{

intaddDefault(intx=3,inty=4);

cout<

fun();

}

intaddDefault(intx,inty)

{

cout<

returnx+y;

}

voidfun(void)

{

cout<

}

15.***

#include<>

voidmain()

{intm,n,a=3,b=3,number;

number=237;

m=number/5;

n=number%5;

cout<<"m="<

cout<<"n="<

a+=m;

b*=n;

cout<<"a="<

cout<<"b="<

}

16.***

#include<>

voidmain()

{intwidth,height,result1,result2,result3;

height=3;width=5;

result1=height>3&&width>=5;

result2=height>3||width>=5;

result3=!

(width>=5);

cout<<"result1"<

cout<<"result2"<

cout<<"result3"<

}

17.***

#include<>

voidmain()

{inti=32,j=6;

doubledf;

df=i/j+;

cout<<"df="<

i=df/3;

cout<<"i="<

}

18.&&&

#include

intc[10];

voidadd(intx,inty)

{staticinti=0;

c[i]=x+y;

i++;

}

voidmain()

{inta[10]={1,2,3,4,5,6,7,8,9,10};

intb[10]={10,9,8,7,6,5,4,3,2,1};

inti=0,k=0;

for(i=0;i<10;i++)

add(a[i],b[i]);

for(i=0;i<10;i++)

cout<

}

19.

#include<>

voidmain()

{chars[30]="computer,mouse,key";

inti=0,k=0;

cout<

while(s[i]!

='\0')

{if(s[i]=='m')athscore;

average/=10;

cout<<"average="<

for(i=0;i<5;i++)

if(st[i].mathscore<60)

{k++;

cout<

cout<<""<

}

cout<

}

20.

#include<>

voidmain()

{intb[3][4]={23,38,16,12,56,89,66,34,58,12,90,100};

inti,j,m=3,n=4;

for(i=0;i

{for(j=0;j

cout<<*(*(b+i)+j)<<"";

cout<

}

for(i=0;i<20;i++)cout<<"-";cout<

for(i=0;i

{for(j=n-1;j>=00;j--)

cout<<*(b[i]+j)<<"";

cout<

}

for(i=0;i<20;i++)cout<<"-";cout<

for(i=m-1;i>=0;i--)

{for(j=0;j

cout<

cout<

}

}

21.

#include<>

voidmain()

{inta[]={12,22,32,42,52,62,72,82,92,102};

inti,m=5;

int*p=a;

for(i=0;i

cout<<*p++<<"";

cout<

for(i=m-1;i>=0;i--)

cout<

cout<

}

22.

#include<>

voidmain()

{intb[2][4]={12,36,62,14,56,98,74,63};

int(*p)[4]=b;

inti,j;

for(i=0;i<2;i++)

{for(j=0;j<4;j++)

cout<<*(*(p+i)+j)<<"";

cout<

}

for(i=0;i<20;i++)cout<<"-";cout<

for(i=0;i<2;i++)

{for(j=3;j>=0;j--)

cout<

cout<

}

}

23.

#include<>

#include<>

voidmain()

{intfunc(inta,intb,charop);

int(*fptr)(inta,intb,charop);

fptr=func;

cout<

cout<

}

intfunc(inta,intb,charop)

{

switch(op)

{

case'+':

cout<

case'-':

cout<

case'*':

cout<

default:

cout<<"Operatorerror!

"<

}

}

24.

#include<>

structstudent

{char*num;

char*name;

intage;

};

voidmain()

{int*ip;float*fp;char*cp;

structstudent*stp;

fp=newfloat;

cp=newchar;

*cp='A';

ip=newint[10];

for(inti=0;i<10;i++)

ip[i]=2*i+2;

stp=newstructstudent;

stp->num="12";

stp->name="Li";

stp->age=18;

cout<<*fp<<""<<*cp<<""<

cout<<"num="<num<<"name="<name<<"age="<age<

for(i=0;i<10;i++)

cout<

cout<

deletecp;

deletefp;

delete[]ip;

deletestp;

}

25.***

#include<>

classPoint

{

public:

Point(intxx=0,intyy=0)

{X=xx;Y=yy;cout<<"构造函数被调用"<

Point(Point&p);

intGetX(){returnX;}

intGetY(){returnY;}

private:

intX,Y;

};

Point:

:

Point(Point&p)

{

X=;

Y=;

cout<<"拷贝构造函数被调用"<

}

Pointfun2()

{PointA(1,2);

returnA;

}

voidfun1(Pointp)

{cout<<()<

}

voidmain()

{PointA(1,2);

fun1(A);

PointB(A);

cout<<()<

B=fun2();

cout<<()<

}

26.***

#include<>

#include<>

classPoint

{

public:

Point(intxx=0,intyy=0)

{

X=xx;Y=yy;

cout<<"构造函数被调用"<

}

Point(Point&p);

intGetX(){returnX;}

intGetY(){returnY;}

private:

intX,Y;};

Point:

:

Point(Point&p)

{

X=;

Y=;

cout<<"Point拷贝构造函数调用"<

}

classDistance

{

public:

Distance(Pointxp1,Pointxp2);

doubleGetDis(){returndist;}

private:

Pointp1,p2;

doubledist;

};

Distance:

:

Distance(Pointxp1,Pointxp2)

:

p1(xp1),p2(xp2)

{

cout<<"Distance构造函数调用"<

doublex=double()());

doubley=double()());

dist=sqrt(x*x+y*y);

}

voidmain()

{

Pointmyp1(1,1),myp2(4,5);

Distancemyd(myp1,myp2);

cout<<"Thedistanceis:

";

cout<<()<

}

27.

#include<>

classBase{

public:

Base(intx,inty){a=x;b=y;}

voidShow(){cout<<"Base:

"<

private:

inta,b;

};

classDerived:

publicBase{

public:

Derived(intx,inty,intz):

Base(x,y),c(z){}

voidShow(){cout<<"Derived:

"<

private:

intc;

};

voidmain()

{

Baseb(50,50),*pb;

Derivedd(10,20,30);

pb=&b;

pb->Show();

pb=&d;

pb->Show();

}

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

当前位置:首页 > 高等教育 > 理学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1