【期末高分题集】[东北农业大学]《面向对象程序设计》考核必备36

奥鹏期末考核

81611–《面向对象程序设计》2022年东北农业大学期末复习题集

单选题:
(1)在下面的函数声明中,存在着语法错误的是( )。.
A.void BC(int a, int);
B.void BD(int, int);
C.void BE(int, int=5);
D.int BF(int x; int y);
答案问询微信:424329

(2)软件产品在需求发生变化、运行环境发生变化或发现软件产品本身的错误或不足时进行相应的软件更新的难易程度叫做软件的( )。
A.可维护性
B.可复用性
C.兼容性
D.正确性
答案问询微信:424329

(3)假定AA是一个类,“AA* abc()const;”是该类中一个成员函数的原型,若该函数返回this值,当用x.abc()调用该成员函数后,x的值( )。.
A.已经被改变
B.可能被改变
C.不变
D.受到函数调用的影响
答案问询微信:424329

(4)当一个类对象离开它的作用域时,系统自动调用该类的( )。
A.无参构造函数
B.带参构造函数
C.拷贝构造函数
D.析构函数
答案问询微信:424329

(5)一个类的成员函数也可以成为另一个类的友元函数,这时的友元说明( )。
A.需加上类域的限定
B.不需加上类域的限定
C.类域的限定可加可不加
D.不需要任何限定
答案问询微信:424329

(6)如果是类B在类A的基础上构造,那么,就称( )。.
A.类A为基类或父类,类B为超类或子类
B奥鹏期末考核.类A为基类、父类或超类,类B为派生类或子类
C.类A为派生类,类B为基类
D.类A为派生类或子类,类B为基类、父类或超类
答案问询微信:424329

(7)当派生类中有和基类一样名字的成员时,一般来说,( )。.
A.将产生二义性
B.派生类的同名成员将覆盖基类的成员
C.是不能允许的
D.基类的同名成员将覆盖派生类的成员
答案问询微信:424329

(8)如果表达式++a中的“++”是作为成员函数重载的运算符,若采用运算符函数调用格式,则可表示为( )。.
A.operator++(1)
B.operator++(a)
C.operator++(a,1)
D.operator++()
答案问询微信:424329

(9)假设所有变量均为整型,表达式(a=2,b=5,a>b?a++:b++,a+b)的值是( ) 。
A.7
B.8
C.9
D.2
答案问询微信:424329

(10)一个类的成员函数也可以成为另一个类的友元函数,这时的友元说明( )。.
A.需加上类域的限定
B.不需加上类域的限定
C.类域的限定可加可不加
D.不需要任何限定
答案问询微信:424329

(11)由C++源程序文件编译而成的目标文件的缺省扩展名为( )。
A.cpp
B.exe
C.obj
D.lik
答案问询微信:424329

(12)假设所有变量均为整型,表达式(a=2,b=5,ab?a++:b++,a+b)的值是( )。
A.7
B.8
C.9
D.2
答案问询微信:424329

(13)引入友元的主要目的是为了( )。
A.增强数据安全性
B.提高程序的可靠性
C.提高程序的效率和灵活性
D.保证类的封装性
答案问询微信:424329

问答题:
(1)请写出下面程序的运行结果:
程序:
# include “iostream.h”
template
T max (T x ,T y)
{ return (x>y)?(x): (y);
}
void main ( )
{
int x=3 ,y =4;
double a =1.1 ,b =3.4;
cout << max(x ,y)<<endl;
cout << max(a,b)<<endl;
}
答案问询微信:424329

(2)下列程序段中,A_class的成员函数Variance()可求出两数的平方差,请改写该程序段,把Variance()函数从A_class类中分离出来,用友元函数来实现该函数的功能。
class A_class {
private:
int x,y,t;
public:
A_class(int i,int j):x(i),y(j) {
if(y>x){t=x;x=y;y=t;}
}
int Variance(){return x*x-y*y;}
//其它函数从略
};
void main() {
A_class A_obj(3,5);
cout<<"Result:"<<A_obj.Variance()<<endl;
}
答案问询微信:424329

(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

问答编程题:
(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

程序题:
(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

程序设计题:
(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

编程题:
(3)程序:
#include
class complex{ private: int real ; int imag ;
public: complex(float r=0,float i=0);
complex operator + (complex
complex operator – (complex
complex operator – ( ); void print( );};
complex::complex(float r=0,float i=0){real=r; imag=i}
complex complex::operator + (complex& c){
float r= real + c.real ;float i= imag + c.imag ;return complex(r ,i );}
complex complex::operator – (complex& c){
float r= real – c.real ;float i= imag – c.imag ;return complex(r ,i );}
complex operator – ( ){return complex(-real,-img);}
void complex::print( ){cout<<"("<<real<<","<<imag<<")"<<endl;}
void main(){complex x(2.5,3.8),y(4.7,5.4),z;
z=x+y; z.print();z=x-y; z.print();z=-x; z.print();}
问题:本例是使用类的成员函数来实现复数类的运算符重载,请在不改变主函数的情况下,采用友元的形式来实现复数类的运算符重载。写出相应的程序。
答案问询微信:424329

简答题:
(1)简述什么是浅拷贝和深拷贝。
答案问询微信:424329

(2)简述静态数据成员的主要应用。
答案问询微信:424329

(3)简述静态成员函数与一般成员函数的主要差别。
答案问询微信:424329

(4)简述类对其成员的三种存储控制及作用结果。
答案问询微信:424329

(5)简述静态成员函数与一般成员函数的主要差别。
答案问询微信:424329

(6)简述C中结构与C++中类的区别。
答案问询微信:424329

(7)简述C++程序在内存中的分配格局。
答案问询微信:424329

(8)简述静态数据成员的主要应用。
答案问询微信:424329

(9)类的派生方式共有几种,基类成员权限在派生类中的权限怎样变化?
答案问询微信:424329

(10)简述多继承中构造函数被调用顺序。
答案问询微信:424329

(11)简述C中结构与C++中类的区别。
答案问询微信:424329

其他题:
(1)请写出下列程序的运行结果。
程序:# include
void fun ()
{
static int i=25;
i++ ;
cout<< “i=”<<i<<endl;
}
void main ()
{
for (int j=0;j<2;j++)
fun ();
}
答案问询微信:424329

(2)根据下面类中Count函数成员的原型和注释写出它的类外定义。
class AA {
int* a;
int n;
int MS;
public:
void InitAA(int aa[], int nn, int ms) {
if(nn>ms) {cout<<"Error!"<<endl; exit(1);}
MS=ms;
n=nn;
a=new int[MS];
for(int i=0; i<MS; i++) a[i]=aa[i];
}
int Count(int x); //从数组a的前n个元素中统计出其
//值等于x的个数并返回。
};
答案问询微信:424329

(3)请写出下面程序的运行结果:
#include
class Tdate{
public:
Tdate();
Tdate(int d);
Tdate(int m,int d);
Tdate(int m,int d,int y);
//其他公共成员
protected:
int month;
int day;
int year;
};

Tdate::Tdate()
{
month=4; day=15; year=1995;
cout <<month <<"/" <<day <<"/" <<year <<endl;}
Tdate::Tdate(int d)
{
month=4; day=d; year=1996;
cout <<month <<"/" <<day <<"/" <<year <<endl;}
Tdate::Tdate(int m,int d)
{
month=m; day=d; year=1997;
cout <<month <<"/" <<day <<"/" <<year <<endl;}
Tdate::Tdate(int m,int d,int y)
{
month=m; day=d; year=y;
cout <<month <<"/" <<day <<"/" <<year <<endl;}

void main()
{
Tdate aday;
Tdate bday(10);
Tdate cday(2,12);
Tdate dday(1,2,1998);
答案问询微信:424329

(4)根据下面类中Reverse1函数成员的原型和注释写出它的类外定义。
class AA {
int* a;
int n;
int MS;
public:
void InitAA(int aa[], int nn, int ms) {
if(nn>ms) {cout<<"Error!"<<endl; exit(1);}
MS=ms;
n=nn;
a=new int[MS];
for(int i=0; i<MS; i++) a[i]=aa[i];
}
AA* Reverse1(); //通过动态存储分配得到一个对象,并动态分配
//a[MS]数组空间,要求该对象中的n和MS的值与*this中的
//对应成员的值相同,数组元素的值是按照*this中数组元
//素的相反次序排列得到的,要求该函数返回动态对象的地址。
};
答案问询微信:424329

提供优质的教育资源

公众号: 超前自学网