C++期末

华侨大学   面向对象程序设计(二)  试卷(A)
系别 计算机、软件工程、网络工程08  考试日期 2009年 06月29日

姓名                                学号            成绩          
一、选择题 (20分,每小题2分)
(1)关于重载函数在调用时匹配依据的说法中,错误的是  (1) D  。
A)参数个数            B)参数的类型        
C)函数名字            D)函数的类型

(2)下面对友元函数描述正确的是(2)C。
A)友元函数的实现必须在类的内部定义
B)友元函数是类的成员函数
C)友元函数破坏了类的封装性和隐藏性
D)友元函数不能访问类的私有成员

(3)(3)B不是面向对象系统所包含的要素。?
A)对象     B)内联      C)类       D)继承

(4)在C++语言中函数返回值的类型是由(4)C决定的。
A)调用该函数时系统临时                    B) return语句中的表达式类型
C)定义该函数时所指定的函数类型             D)调用该函数时的主调函数类型

(5)在C++语言中,对函数参数默认值描述正确的是(5)D。
A) 函数若有多个参数,只能为一个参数设定默认值(函数参数的默认值只能设定一个)
B)一个函数的参数若有多个,则参数默认值的设定可以不连续
C)函数参数必须设定默认值
D)在设定了参数的默认值后,该参数后面定义的所有参数都必须设定默认值

(6)在C++中,数据封装要解决的问题是(6)D。
A)数据的规范化               B)便于数据转换
C)避免数据丢失               D)实现数据隐蔽(防止不同模块之间数据的非法访问)

(7) C++语言规定,程序中各函数之间  A(7)  
A) 既允许直接递归调用也允许间接递归调用
B) 不允许直接递归调用也不允许间接递归调用
C) 允许直接递归调用不允许间接递归调用
D) 不允许直接递归调用允许间接递归调用

(8)以下关于派生类特性的叙述中,错误的叙述是 (8)A 。
A)派生类中只能继承基类成员而不能重定义基类成员。
B) 对于私有继承,基类成员的访问权限在派生类中全部变成私有。
C) 派生类对基类的继承具有传递性。
D) 初始化从基类继承来的数据成员,必须通过调用基类的构造函数来完成。

(9)以下关于指针函数的叙述中,正确的是(9)C  。 
A) 指针函数用来存放函数名              B) 指针函数用来存放函数调用结果的地址
C) 指针函数用来指示函数的入口       D) 指针函数就是函数指针的别名

(10) 将全局数据对象的存储类别限定为static,其目得是  (10) A 。
A) 为了解决同一程序中不同的源文件中全局量的同名问题;
B) 为了保存该变量的值;
C) 使该变量成为局部变量;
D) 使该变量能作为函数参数。
二、阅读以下程序并给出执行结果(20分,每小题5分)。
1、
#include<iostream>
using namespace std;
class A{
public:       A(){ cout<<"A-> "; }
         ~A(){ cout<<"<-~A; "; }
};
class B{
public:    B(){ cout<<"B-> "; }
         ~B(){ cout<<"<-~B; "; }
};
class C{
public:    C(){ cout<<"C-> "; }
         ~C(){ cout<<"<-~C; "; }
};
void func(){
  cout<<"
func: ";
  A a;
  static B b;
  C c;
}
int main(){
  cout<<"main: ";
  for(int i=1; i<=2; ++i){
      if(i==2) C c; else A a;
    B b;          }
  func(); func();
  return 1;
}
2、
#include <iostream>
using namespace std;
class B1
{public:
    B1(int i){    cout<<"constructing B1   "<<i<<endl;    }
    ~B1(){       cout<<"destructing B1"<<endl;    }
};
class B2
{public:
    B2(){    cout<<"constructing B2 *"<<endl;    }
    ~B2(){    cout<<"destructing B2"<<endl;    }
};
class C:public B2,public B1
{public:
    C(int a,int b):B1(a),b1(b)
    {    cout<<"constructing C"<<endl;  }
    ~C()
    {    cout<<"destructing C"<<endl;}
private:    
    B1 b1;
    B2 b2;
};
void main()
{
    C obj(1,2);
}
constructing B2 *
constructing B1
constructing C
destructing C
destructing B1
destructing B2
3、
#include <iostream>
using namespace std;
class A
{
private:
    //…其它成员
public:
    virtual void func(int data)
    {    cout<<"class A:"<<data<<endl;    }
}; 
class B: public A
{
    //…其它成员
public:
    void func() 
    {    cout<<"function in B without parameter! 
";    }
        void func(int data) 
    {    cout<<"class B:"<<data<<endl;    }
};
int main()
{
    A a,*p;
    A &p1=a;
    B b;
    p=&b;
    p1.func(1);
    p->func(100);
    return 1;
}
Class A:1
Class B:100
4、
#include <iostream>
using namespace std;
func(int a,int b);
int main()
{
    int k=4,m=1,p;
    p=func(k,m);    cout<<p<<endl;
    p=func(k,m);    cout<<p<<endl;
    return 1;
}
func(int a,int b)
{
    static int m=0,i=2;
    i+=m+1;
    m=i+a+b;
    return (m);
}
8,8
三、阅读以下程序(或函数)并简要叙述其功能(20分,每小题5分) 1int chnum (char *str) 
{
    int i,j,k,h,len,num=0;
    len=strlen(str);
    for(i=0; i<len ; i++) 
    {
        k=1;
        j=len-i;
        while(j>1) 
        {
            k=k*10;
            j--; 
        }
        h=str[i]-'0'; 
        num=num+h*k; 
    } 
    return num; 
}
输入:123
运行结果:?此题比较难,且没有主函数无法运行
功能:

1*10*10+2*10+3

2、
# include <iostream>
using namespace std;
int main() 
{
    char *a[5]={"student","worker","cadre","soldier","peasant"};
    char *p1,*p2;
    p1=p2=a[0];
    for (int i=0; i<5; i++) 
    {
        if (strcmp(a[i],p1)>0) p1=a[i];
        if (strcmp(a[i],p2)<0) p2=a[i];
    }
    cout <<p1<<' '<<p2<<endl;
    return 1;
}
运行结果:?
功能:
3、
#include <iostream>
using namespace std;
void func(int[],int);
int main()
{
    int array[]={48,91,83,75,36};
    int len=sizeof(array)/sizeof(int); 
    for (int i=0;i<len;i++)    
        cout<<array[i]<<",";
    cout<<endl<<endl;
    func(array,len);    
    return 1;
}
void func(int a[],int size)    
{    int i,temp;
    for(int pass=1;pass<size;pass++)    
    {
        for(i=0;i<size-pass;i++) 
            if (a[i]>a[i+1])
            {    temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
            }
    }
        for (i=0;i<size;i++)    
            cout<<a[i]<<",";
        cout<<endl;
}
请叙述函数func( )的功能。
4、
#include <iostream>
using namespace std;
int funp(const char* str1, const char* str2);
int main()
{
    char a[80],b[80];
    cout<<"Please input two string:";
    cin>>a>>b;
    cout<<"result="<<funp(a,b)<<endl;
    return 1;
}
int funp (const char* str1, const char* str2)
{
  while(*str1 && *str1==*str2)
  {
    str1++; str2++;
  }
  return *str1 - *str2;
}
请叙述函数funp( )的功能。

四、阅读以下程序并填空(填上正确的语法成分),使其成为完整的程序(10分,每空2分)
从已建立的学生链表中删除学号为number的学生结点。
struct Student
{
    long number;
    float score;
    Student * next;
};
Student * Delete (Student *head,long number) //删除链表结点
{
    Student *p,*pGuard;   //p指向要删除的结点,pGuard指向要删除的结点的前一结点
    if(           (1)            )    //原链表为空链表
    {
        cout<<"
List is null!
";
        return(head);
    }
if (             (2)            )    //要删除的结点为链表的第一个结点
    {
        p=head;
        head=head->next;
        delete p;
        cout<<number<<"the head of list have been deleted
";
        return(head);
    }
for(Student * pGuard=head;        (3)        ;pGuard=pGuard->next)
    {
        if (pGuard->next->number==number)    //找到要删除的结点
        {
                       (4)               
                       (5)              
            delete p;
            cout<<number<<"have been deleted 
";
            return(head);
        }
    }
    cout<<number<<"not found!
";    //未找到要删除的结点
    return (head);
}
五、编程题(30%1、编写函数char* copystr(char * dest,const char * source ,int m)将字符串source中第m个字符开始的全部字符(source的最右子串)复制成另一个字符串dest,并返回复制的串,请在主函数中输入字符串及m的值并输出复制结果。

2、设计并测试复数类(Complex)
(1)    设计一个复数类(Complex)包含两个数据成员:实部(real),虚部(imagin);
包含如下主要成员函数:
•    构造函数(用来初始化一个复数对象,默认实部、虚部均为0);
•    重载加、减法运算符(+、-)实现复数类的加、减法运算;
•    显示复数对象,按a+bi(a为实部、b为虚部)格式输出一个复数对象。
(2)    请在主函数中使用所设计的复数类定义两个复数对象,求其和、差并输出。
原文地址:https://www.cnblogs.com/herizai/p/3180619.html