资源描述
全国1月高等教育自学考试
面对对象程序设计试题
一、单项选择题(本大题共10小题,每题2分,共20分)
在每题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多项选择或未选均无分。
1.一个函数功效不太复杂,但要求被频繁调用,选用( )
A.内联函数 B.重载函数
C.递归函数 D.嵌套函数
2.C++的继承性允许派生类继承基类的( )
A.部分特性,并允许增加新的特性或重定义基类的特性
B.部分特性,但不允许增加新的特性或重定义基类的特性
C.所有特性,并允许增加新的特性或重定义基类的特性
D.所有特性,但不允许增加新的特性或重定义基类的特性
3.在C++中,封装是借助什么达成的?( )
A.结构 B.类
C.数组 D.函数
4.建立包括有类对象组员的派生类对象时,自动调用结构函数的执行次序依次为( )
A.自己所属类、对象组员所属类、基类的结构函数
B.对象组员所属类、基类、自己所属类的结构函数
C.基类、对象组员所属类、自己所属类的结构函数
D.基类、自己所属类、对象组员所属类的结构函数
5.类的析构函数是对一个对象进行如下哪种操作时自动调用的?( )
A.建立 B.撤消
C.赋值 D.引用
6.下列不是描述类的组员函数的是( )
A.结构函数 B.析构函数
C.友元函数 D.拷贝结构函数
7.所有在函数中定义的变量,连同形式参数,都属于( )
A.全局变量 B.局部变量
C.静态变量 D.存储器变量
8.假定AB为一个类,则执行AB x;语句时将自动调用该类的( )
A.有参结构函数 B.无参结构函数
C.拷贝结构函数 D.赋值结构函数
9.假定AA为一个类,a()为该类公有的函数组员,x为该类的一个对象,则访问x对象中函数组员a()的格式为( )
A.x.a B.x.a()
C.x->a D.x->a()
10.对于任一个类,用户所能定义的结构函数的个数至多为( )
A.0 B.1
C.2 D.任意个
二、填空题(本大题共10小题,每题2分,共20分)
请在每题的空格中填上正确答案。错填、不填均无分。
11.对象的四大基本特性是多态性、继承性、______和封装性。
12.为了使类中的组员不能被类外的函数通过组员操作符访问,则应把该组员的访问权限定义为______。
13.C++程序的源文献扩展名为______。
14.所有模版都是以______核心字和一个形参表开头的。
15.在#include命令中所包括的头文献,能够是系统定义的头文献,也能够是______定义的头文献。
16.一个const对象只能访问______组员函数。
17.C++是通过引用运算符______来定义一个引用的。
18.若y是x的引用,则对y的操作就是对______的操作。
19.执行______操作将释放由p所指向的动态分派的数据空间。
20.C++的流库预定义了4个流,它们是cin、cout、______和clog。
三、改错题(本大题共2小题,每题6分,共12分)
21.假定下面程序将分数a和b相加,其和赋值给c并输出,要求输出成果为“13/18”,其主函数5到8行之间存在着三行语句错误,请指犯错误行的行号并更正。
#include<iostream.h>
class Franction{ //定义分数类
int nume; //定义分子
int deno; //定义分母
public:
//把*this化简为最简分数,详细定义在另外文献中实现
void FranSimp();
//返回两个分数*this和x之和,详细定义在另外文献中实现
Franction FranAdd(const Franction& x);
//置分数的分子和分母分别0和1
void InitFranction() {nume=0; deno=1;}
//置分数的分子和分母分别n和d
void InitFranction(int n,int d) {nume=n; deno=d;}
//输出一个分数
void FranOutput() {cout<<nume<<′/′<<deno<<endl;}
};
void main() //1行
{ //2行
Franction a,b,c; //3行
a.InitFranction(7,18); //4行
b.InitFranction(1); //5行
c.InitFranction(); //6行
c=FranAdd(a,b); //7行
cout<<c.nume<<′/′<<c.deno<<endl; //8行
} //9行
错误行的行号为______、______和______。
分别更正为______、______和______。
22.下面是一个类的定义,在5到12行之间有3行存在语法错误,请指犯错误行的行号并更正。
class CE { //1行
private: //2行
int a,b; //3行
int getmin() {return (a<b?a:b);} //4行
public //5行
int c; //6行
void SetValue(int x1,int x2,int x3) { //7行
a=x1;b=x2;c=x3; //8行
}; //9行
int GetMin(); //10行
}; //11行
int GetMin(){ //12行
int d=getmin(); //13行
return(d<c? d:c); //14行
} //15行
错误行的行号为______、______和______。
分别更正为______、______和______。
四、程序填空题(本大题共3小题,每题6分,共18分)
请按提示要求完成如下程序段的填空。
23.class A {
int a,b;
public:
____(1)____ //定义结构函数,使参数aa和bb的默认值为0,
//在函数体中用aa初始化a,用bb初始化b
};
main(){
A *p1,*p2;
____(2)____; //调用无参结构函数生成由p1指向的动态对象
____(3)____; //调用带参结构函数生成由p2指向的动态对象,
//使a和b组员分别被初始化为4和5
}
(1) (2) (3)
24.一个类定义如下:
#include<iostream.h>
#include<string.h>
class Books
{
private:
char bk_name[20]; //书的名称
int price; //书的价格
static int totalprice; //同类书总价格
public:
Books(char*str,int p){ //结构函数
strcpy(bk_name,str); //strcpy函数将str字符串的内容拷贝到bk_name
price=p;
totalprice+=price;
}
~Books(){totalprice-=price;}
char*GetN(){____(4)____;}//返回书名称
int GetP(){return price;}
____(5)____GetTotal_Price(){ //定义静态组员函数
____(6)____; //返回总价格
}
};
(4) (5) (6)
25.已知一个类的定义如下:
#include<iostream.h>
class AA {
int a[10];
int n;
public:
void SetA(int aa[],int nn); //用数组aa初始化数据组员a,
//用nn初始化数据组员n
int MaxA(); //从数组a中前n个元素中查找最大值
void SortA(); //采取选择排序的措施对数组a中前n个元素
//进行从小到大排序
void InsertA(); //采取插入排序的措施对数组a中前n个元素进行从小到大排序
void PrintA(); //依次输出数组a中的前n个元素
};
voidAA::SortA()
{
int i,j;
for(i=0; ____(7)____;i++){
int x=a[i],k=i;
for(j=i+1; j<n;j++)
if(a[j]<x){
x=a[j];
k=____(8)____;
}
a[k]=a[i];
a[i]=____(9)____;
}
}
(7) (8) (9)
五、程序分析题(本大题共6小题,每题5分,共30分)
阅读如下程序,写出其运行成果。
26.#include<iostream.h>
const int N=6;
void fun();
void main()
{
for(int i=1;i<N;i++)
fun();
}
void fun()
{
static int a=2;
cout<<(a+=3)<<′ ′;
}
27.#include<iostream.h>
#include<iomanip.h>
class fun{
friend ostream& operator<<(ostream&,fun);
}ff;
ostream& operator<<(ostream& os,fun f){
os.setf(ios::left);
return os;
}
void main()
{
cout<<setfill(′*′)<<setw(10)<<12345<<endl;
cout<<ff<<setw(10)<<54321<<endl;
}
28.#include<iostream.h>
class a
{
public:
virtual void func(){cout<<"func in class a"<<endl;}
};
class b
{
public:
virtual void func(){cout<<"func in class b"<<endl;}
};
class c:public a,public b
{
public:
void func(){cout<<"func in class c"<<endl;}
};
void main()
{
c c;
a &pa=c;
b &pb=c;
pa.func();
pb.func();
}
29.#include<iostream.h>
class testa{
public:
testa(){a1=0;}
testa(int i){a1=i;}
void printout(){cout<<a1;}
private:
int a1;
};
class testb:public testa{
public:
testb(){b1=0;};
testb(int i,int j,int k);
void printout();
private:
int b1;
testa aa;
};
testb::testb(int i,int j,int k):testa(i),aa(j){b1=k;}
void testb::printout(){
testa::printout();
cout<<endl;
}
void main(){
testb tt[2];
tt[0]=testb(9,3,5);
tt[1]=testb(8,4,7);
for(int i=0;i<2;i++)
tt[i].printout();
}
30.#include<iostream.h>
void main()
{
for(int i=-1;i<4;i++)
cout<<(i ? ′ 0′:′*′);
}
31.#include<iostream.h>
class Date
{
int Year,Month,Day;
public:
void SetDate(int y,int m,int d){Year=y;Month=m;Day=d;}
void PrintDate(){cout<<Year<<"/"<<Month<<"/"<<Day<<endl;}
Date(){SetDate(,1,1);}
Date(int y,int m,int d){SetDate(y,m,d);}
};
class Time
{
int Houre,Minutes,Seconds;
public:
void SetTime(int h,int m,int s){Houre=h;Minutes=m;Seconds=s;}
void PrintTime(){cout<<Houre<<":"<<Minutes<<":"<<Seconds<<endl;}
Time(){SetTime(0,0,0);}
Time(int h,int m,int s){SetTime(h,m,s);}
};
class Date_Time:public Date,public Time
{
public:
Date_Time():Date(),Time(){};
Date_Time(int y,int mo,int d,int h,int mi,int s):
Date(y,mo,d),Time(h,mi,s){}
void PrintDate_Time(){PrintDate();PrintTime();}
};
void main()
{
Date_Time dt_a,dt_b(,10,1,6,0,0);
dt_a.PrintDate_Time();
dt_b.SetTime(23,59,59);
dt_b.PrintDate_Time();
dt_a.SetDate(,12,31);
dt_a.PrintDate_Time();
}
展开阅读全文