东南大学c++复习三含答案Word格式.docx
《东南大学c++复习三含答案Word格式.docx》由会员分享,可在线阅读,更多相关《东南大学c++复习三含答案Word格式.docx(16页珍藏版)》请在冰豆网上搜索。
![东南大学c++复习三含答案Word格式.docx](https://file1.bdocx.com/fileroot1/2023-2/3/133c2610-b69b-4634-93ce-59b706391edc/133c2610-b69b-4634-93ce-59b706391edc1.gif)
B.floatp=(float)50;
C.int*p=new50;
D.float*p=newfloat[50];
10.已知某函数有如下定义:
intdata[4][3]={1,3,5,7,9,2,4,6,8,10,11,12};
int(*p)[3];
p=data;
则:
*(p+2) 表示 (10)。
A.数组data的元素4的地址;
B.数组data的元素5的地址;
C.数组data的元素8的地址;
D.数组data的元素9的地址。
11.设函数声明语句中的参数表为(int&
a,int&
b,intc),函数体中a,b,c三个变量的值都发生变化;
主函数中调用此函数的实参表为(x,y,z),调用函数语句执行后,以下叙述正确的是(11)。
A.变量x和y的值发生变化
B.变量x和y的值不发生变化
C.变量x、y、z的值都发生变化
D.只有变量z的值发生变化
12.this是分配给被调用的成员函数的指针,那么*this代表(12)。
A)调用成员函数的对象B)对象所调用的成员函数
C)成员函数中的数据成员D)成员函数的形参
13.设有如下定义语句charb[5],*p=b;
则正确的赋值语句是(13)。
A.b=”abcd”;
B.*b=”abcd”;
C.p=”abcd”D.*p=”abcd”
14.设有说明:
inta[][4]={1,2,3,4,5,6,7,8,9,10},*p=*(a+1);
则值为9的表达式是:
14。
A.p+=3,*p++B.p+=4,*(p++)C.p+=4,*++pD.p+=4,++*p
15.下列表示引用的方法中,15是正确的。
已知:
intm=10:
A.int&
x=m:
B.int&
y=10;
C.int&
z;
D.float&
t=&
m;
16.以下程序的输出结果是16
A)1B)7C)9D)11
#include<
iostream.h>
voidfut(int**s,intp[2][3])
{**s=p[1][1];
}
voidmain()
{staticinta[2][3]={1,3,5,7,9,11};
int*p;
p=newint;
fut(&
p,a);
cout<
<
*p<
endl;
17.执行以下程序后,y的值是17
A)17B)18C)10D)20
{staticinta[]={2,4,6,8,10};
inty=0,x,*p;
p=&
a[1];
for(x=0;
x<
3;
x++)
y+=*(p+x);
y<
18.若有说明:
intt[3][2],*p=t;
能正确表示t[2][1]的一组表达式是18
A)**(t+2)+1,*(p[0]+5),**t+3
B)**(t+2+1),*p[2][1],**(t[2]+1)
C)*(t+2)+1,*p[5],*(t[0]+2)+1
D)*(*(t+2)+1),p[5],*(t[2]+1)
19.设有说明:
int*p,*q,*t,x=5;
运行以下程序段,输出结果是19
A)5随机数B)随机数5C)出错D)55
q=&
x;
t=p;
p=q;
q=t;
deletep;
'
\t'
*q<
20.以下关于基类指针和派生类指针的叙述中不正确的是派生类指针的叙述中不正确的20。
A.基类指针可以指向公有派生类的对象
B.基类指针可以指向它的多次派生后的派生类的对象
C.派生类的指针不能指向基类的对象
D.若基类指针指向派生的对象,通过该基类指针可以访问派生类对象的所有成员
二.阅读程序,写出执行结果(总共30分)
1.写出下面程序的输出(8分)
#include<
voidmain(void)
{char*name="
newspaper"
;
cout<
char(name[0]+3)<
\n'
char(*name+3)<
*(name+3)<
name[4]<
}
2.写出下面程序的输出(6分)
#include"
iostream.h"
#definePR(ar)cout<
ar<
{
intj,a[]={1,3,5,7,9,11,13,15},*p=a+5;
for(j=3;
j;
j--)
{
switch(j)
{
case1:
case2:
PR(*p++);
break;
case3:
PR(*(--p));
default:
}
}
3.写出下面程序的输出(6分)
#include<
classA{
intx;
public:
A(inta){
x=a;
"
x="
A_1"
A(A&
s){
x=s.x+1;
A_2"
~A(){cout<
~A"
};
{
Af1
(2),f2(f1);
f2=A(f1);
f1=A(f2);
4.写出下面程序的输出(6分)
classX{
public:
voidvirtualf(){cout<
X:
11"
voidvirtualg(){cout<
22"
classA:
publicX{
voidf(){cout<
A:
:
33"
classB:
publicA{
B:
44"
voidg(inti=10){cout<
55"
Bb;
X*px=&
b;
b.g()
px->
f();
px->
g();
5.程序(4分)
iomanip.h>
char*f(char*s,charch){
char*p=s,*q=s;
while(*q=*p++)if(*q!
=ch)q++;
returns;
voidmain(){
chars1[]="
HelloHowareyou"
s2[]="
110010111"
f(s1,'
e'
)<
f(s2,'
0'
三.完善填空(20×
2分)
1.本程序被完善后输出以下结果。
C++langugeprogramming
Theendatthistimeofday!
[程序](5分)
string.h>
staticinti;
char*ps;
A(char1){
ps=newchar[strlen(s)+1];
strcpy(2,s);
~A(){
if(3)cout<
Theend"
elsecout<
atthistimeofday!
\n"
if(ps)delete[]ps;
i++;
}
A&
operator=(A&
b){
if(b.ps){
ps=newchar[strlen(4)+1];
strcpy(ps,b.ps);
elseps=0;
return5;
intA:
i;
As1("
programming"
),s2("
C++languge"
);
s2.ps<
s2=s1;
2.以下程序功能是:
从一个字符串str中删除或添加一个指定的字符,若指定的字符c出现在str中,则从str中删除第一个值为c的字符;
否则把字符c添加到str的尾部。
在程序中,函数dele()从字符串中删除一个字符;
函数add()添加一个字符到字符尾部;
函数search()用于查找指定的字符是否在字符串中,若在,则返回所在位置,否则返回0。
char*sercher(char*s,charch){
while(*s)
if(*s++==ch)return(6);
return0;
voiddele(char*s,charch){
char*p1=search(s,ch),*p2=p1+1;
while(*p2)*p1++=(7)
*p1='
\0'
voidadd(char*s,charch){
while(*s)s++;
(8)=ch;
*s='
charstr[80]="
abc12123"
c;
str<
输入一个字符"
cin>
>
c;
void(9);
if(search(str,c))fp=dele;
elsefp=add;
fp((10));
3.本程序用结构体建立某高校招生的考生档案(编号、总分)。
首先根据某省区投档人数创建档案链表,然后根据本校在某省区的分数线删除档案链中不达线的考生,最后调用print函数输出被录取的考生档案。
主函数中:
m表示在某省区的投档人数,n表示在该省区的最低录取总分。
创建档案链时,新的节点总是接在老节点之后。
提示:
链表中的节点(含编号、总分)并非按序排列,例如:
001号580分,011号586分,004号602分,021号578分,003号584分...,如果最低录取分为585分,那么编号为001、021、003...的节点都将被删除。
structstudent{
intnumber;
floatgrade;
student*next;
student*create(intm)
student*p1,*p2,*head;
head=0;
输入考生编号和总分:
\n"
for(intn=0;
11_;
n++)
p1=newstudent;
cin>
p1->
number>
grade;
if(head==0){head=p1;
p2=p1;
else{p2->
next=p1;
12;
}
13;
returnhead;
student*delete_student(student*head,intn)//删除节点
student*p1,*p2;
while(head->
grade<
n)
{p1=head;
head=head->
next;
deletep1;
p2=p1=head;
while(p2->
next!
=0)
p1=p2;
14;
if(p2->
{p1->
next=p2->
deletep2;
p2=p1}
voidprint(student*head)
{
conststudent*p;
p=head;
被录取的考生编号和总分:
while(p!
=0)
{cout<
p->
number<
15;
voidmain()
student*head;
intm,n;
m>
n;
head=create(m);
head=delete_student(head,n);
print(head);
4.以下程序定义了一个类list,然后用list类定义了函数creat,用来建立一个链表,链表结点有两个成员,其中数据成员是字符类型。
建立链表的特点是,新产生的结点总是插在链表的末尾。
string.h"
classlist{
(16)
chardata;
classlist*next;
list*creat()
list*h,*p;
charch;
h=newlist;
p=h;
cin.get(ch);
p->
data=ch;
while(ch!
='
?
)
(17)
p=p->
cin.get(ch);
p->
(18)
returnh;
list*head;
(19)
while(head)
cout<
head->
data;
20;
一、选择题(共30分)
1
2
3
4
5
B
6
C
7
8
9
10
A
11
12
13
14
15
16
17
18
D
19
20
二、阅读程序(每空1分,共26分)
1.q/q/s/p
2.9911
3.X=2A_1/A_2/A_2/3~AA_2/4~A3~A4~A
4.B:
55/B:
44/X:
22
5.HlloHowaryou/111111
注:
答案中的’/’代表换行
三、完善程序(每个填空2分,共44分)
1.
(1)*s
(2)ps(3)i==0(4)b.ps(5)*this
2.(6)s-1or--s(7)*p2++(8)*s++(9)(*fp)(char*,char)
(10)str,c
3.(11)n<
m(12)p2=p1(13)p2->
next=0(14)p2=p2->
next
(15)p=p->
4.(16)public:
(17)p=newnode(18)p->
next=newnode
(19)head=creat()
(20)node*p=head;
head=head->