一起答

自考C++程序设计模拟试题及答案(四)

如果您发现本试卷没有包含本套题的全部小题,请尝试在页面顶部本站内搜索框搜索相关题目,一般都能找到。
  1. 求n(n=3)个学生的最高分和最低分及姓名,已有 student类声明和main函数,完成 student类的实现部分。

    #include

    #include< string.h>

    class student

    {char name[10];

    int deg;

    public:

    student(char na[]="",int d=0);

    char*getname();

    friend int compare(student &s1,student &s2);

    int getdeg();

    };

    void main()

    {student st[]={student("王强",74), student("李刚",68), student("张雪",84)};

    int i=0, min=0, max=0;

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

    {if(compare(st[max],st[i])==-1)

    max=i;

    if(compare(st[min],st[i])==1)

    min=i;

    }

    cout<"最高分:"<

    cout<<"最低分:"<<(*(st+min)).getdeg()<"姓名:"

    }

  2. 给出下面程序输出结果。

    #include

    class Base

    {private:

    int Y;

    public:

    Base(int y=0){Y=y;cout<<"Base("<

    ~Base(){cout<<"~Base()\n";}

    void print(){cout<

    };

    class Derived:public Base

    {private:

     int Z;

     public:

     Derived(int y,int z):base(y)

    {Z=z;

    cout<<"Derived("<

    }

     ~Derived(){cout<<"~Derived()\n";

     void print()

    {base::print()

    cout<

    };

    void main()

    {Derive d(10,20);

    d.print();

    }

  3. 给出下面程序的输出结果。

    #include

    class A

    {public:

    A(){al=0;}

    A(int i)al=i;}

    void printout(){cout<

    private:

    int al;

    };

    class B:public A

    {public:

    B(){b1=0;}

    B(int i,int j,int k);

    void printout();

    private:

    int bl;

    A aa;

    };

    B::B(int i,int j,int k):A(i),aa(j)

    {bl=k;}

    void B::printout()

    {A::printout();

    cout<

    void main()

    {B tt2];

    tt [0=B(9,3,5);

    t[1]=B(8,4,7);

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

    tt[i].printout();

    }

  4. #include

    #include

    class arr

    {____________

    int s;

    public:

    Arr(int a[],int n)

    {v=a;

    s=n;

    }

    int size(){return s;}

    int&operator()(int n);

    };

    ____________()(int n)

    {if(n>s)

    {cerr<<"下标越界!"<

    exit(1);

    }

    return v[n];

    }

  5. 程序的输出结果如下:

    30

    9

    请根据输出数据在下面程序中的下横线处填写正确的语句。

    #include

    class Test

    {private:

    int m;

    public:

    Test(int i=0)

    {m=i;}

    void show()

    {cout<

    void set(int i)

    {m=i;}

    };

    void main()

    {Test*p1= new Test[2],*p2;

    p2=p1;

    p1->set(30);

    p1->show();

    Test[2]={1,9};

    ___________

    p1->show();

    pl=p2;

    ___________//释放空间

    }

  6. 在下面程序的横线处填上适当内容,完成类的定义。

    class line;

    class box

    {private:

    int color;

    int upx, upy;

    int lowx, lowy;

    public:

    ____________

    void set_color (int c){color=c;}

    void define_box (int xl, int yl, int x2, int y2)

    {upx=x1;upy=y1;lowx=x2;lowy=y2;}

    };

    class line

    {private:

    int color;

    int startx, starty;

    int endx, endy;

    public:

    friend int same_color( line 1, box b);

    void set_color (int c){color=c;}

    void define_line(____________)

    {startx =x1;starty =yl;endx =x2;endy =y2;}

    };

    int same_color( line 1, box b)

    {if (1.color =b.color)return 1;

    return 0;

    }

  7. #include

    #include

    class dis

    {private:

    double x,y;

    public:

    dis(________){x=x1;y=y1;}

    double getx(){return x;}

    double gety(){return y;}

    ________double log(dis&,dis&);

    };

    double dis::log(dis&a,dis&b)

    double px=a.x-b.x;

    double py=a.y-b.y;

    return sqrt(px*px+py*py);

    }

    void main()

    dis pl(3.5,4.5),p2(5.5,6.5);

    double d=dis::log(p1,p2);

    cout<<"The distance is"<

    }

  8. 在下列程序的横线处填上适当的语句,使输出为:0,2,10

    #include

    #include

    class Magic

    {double x;

    public:

    Magic(double d=0.00)(fabs(d))

    {}

    Magic operator+(___________)

    {

    return Magic(srt(x*x+c.x*c.x));

    }

    ___________operator<<(ostream& stream,Magic &c)

    {stream<

    return stream;

     }

    };

    void main()

    {Magic ma;

    cout<

    }

  9. #include

    class Test

    {int x,y;

    public:

    void fun(int i,int j)

    {x=i;y=j;}

    void show()

    {cout<<"x="<

    if(y)

    cout<<",y="<

    };

    void main()

    {Test a;

    A.fun(1);

    A.show();

    A.fun(2,4);

    A.show();

    }

  10. #include 

    class A 

    {int i; 

    public: 

    virtual void fun()

    cout<<"A:fun()"<

    A(int a){i=a;}

    }; 

    class B:public A 

    {int j;public: 

    void fun(){cout<<"B::fun()\n";}

    B(int b,int c){j=c;}

    };

    void main()

    {A*p;

    B b(3,5);

    p=&b;

    p->fun();

    }

  11. #include

    class f{

    private:

    int x,y;

    public:

    void f1(int a,int b){x=a;y =b;}

    void print(cout<

    };

    void main(){

    f a;

    a.f1(1.5,1.8);

    a.print();

    }

  12. #include

    class fract

    {private:

    int den;

    int num;

    public:

    fract(int d=0,int n=1):den(),num(n){}

    friend fract &operator+=(fract &,fract &);

    void show(){cout<

    };

    friend fract &operator+=(fract&f1,fract&f2)

    {f1.den=f1.den*f2.num+f1.num*f2.den;

    f1.num*=f2.num;

    return f1;

    }

    void main()

    fract fr(3,4);

    fr+=fract(5,7);

    Fr.show();

    cout<

    }

  13. #include 

    #include 

    using namespace std;

    Class MyClass

    {public:

    MyClass (int i=0){member=i;}

    void SetMember(const string m){member="big"+m;m=member;}

    string GetMember(){return member;}

    void print()const{cout<<"Stu:"

    private:

    string member;

    };

    void main()

    {MyClass obj1,obj2;

    string="wang lin";

    obj2=&obj1;

    obj2->SetMember(i);

    objl.print();

    }

  14. 在C++中,编译指令都是以_________(符号)开始。

  15. 下列程序段的输出结果是_______。for(i=0,j=10,k=0;i<=j;i++,j-=3,k=i+j);cout<

  16. C++函数中传递对象地址值是使用_________作为参数。

  17. 使用关键字_______说明的函数是内联函数。

  18. 类的构造函数可以重载,类的析构函数_______重载。

  19. 返回向量中的最后一个对象的成员函数是________。

  20. vector类中用于删除向量中的所有对象的方法是_________。

  21. 决定C++语言中函数返回类型的是_______。

  22. 已知有20个元素的int型向量V1,若用V1初始化向量V2,语句是__________。

  23. 表达式operator+(x,y)还可以表示为_______。

  24. C++中只有两个逻辑常量:true和_______。

  25. 执行下列代码cout<<"oct:"<

  26. 静态数据成员初始化时,前面不加_______关键字,以免与一般静态变量或对象混淆。

  27. 在C++语言的面向对象设计框架中,________是程序的基本组成单元。

  28. vector类中向向量尾部插入一个对象的方法是_________。

  29. 执行代码:int a=96;cout<

  30. 在类中,________成员为类的所有对象所共享。

  31. 在建立派生类对象时,先执行_______的构造函数。

  32. C++程序是从_________函数开始执行的。

  33. 使用const关键字说明的成员函数为_________。

  34. 对类A,复制构造函数的原型是()

    • A.a::a(const A&);
    • B.A::A(const A*);
    • C.A::A(const A);
    • D.A::A();
  35. 声明友元使用的关键字为()

    • A.const
    • B.static
    • C.class
    • D.friend
  36. 关于纯虚函数,下列表述中正确的是()

    • A.纯虚函数是没有给出实现版本(即无函数体定义)的虚函数
    • B.纯虚函数的声明总是以“=0;”结束
    • C.派生类必须实现基类的纯虚函数
    • D.含有纯虚函数的类不可能是派生类
  37. C++语言建立类族是通过()

    • A.类的嵌套
    • B.类的继承
    • C.虚函数
    • D.抽象类
  38. 保证编译器正确调用成员函数的规则是()

    • A.赋值兼容
    • B.继承
    • C.作用域
    • D.支配
  39. 在C++程序中,对象之间的相互通信通过()

    • A.继承实现
    • B.封装实现
    • C.调用成员函数实现
    • D.函数重载实现
  40. 下列特征中,C和C++共有的是()

    • A.继承
    • B.函数定义不能嵌套
    • C.封装
    • D.多态性
  41. 析构函数的参数个数为()

    • A.0个
    • B.1个
    • C.至少1个
    • D.多于1个
  42. 下列关于友元的描述中,错误的是()

    • A.友元函数可以访问该类的私有数据成员
    • B.一个类的友元类中的成员函数都是这个类的友元函数
    • C.类与类之间的友元关系可以继承
    • D.友元可以提高程序的运行效率
  43. 设有定义int i;double=5;,则10+i+j值的数据类型是()

    • A.int
    • B.double
    • C.float
    • D.不确定
  44. 类的构造函数被自动调用执行的情况是在定义该类的()

    • A.成员函数时
    • B.数据成员时
    • C.对象时
    • D.友元函数时
  45. C++语言中所有在函数中定义的变量,连同形式参数,都属于()

    • A.全局变量
    • B.局部变量
    • C.静态变量
    • D.函数
  46. 下列访问成员的方式哪个是正确的()

    • A.对象名.对象成员名
    • B.对象指针名.对象成员名
    • C.对象名->对象成员名
    • D.类名->对象成员名
  47. C++对C语言做了很多改进,即从面向过程变成为面向对象的主要原因是()

    • A.增加了一些新的运算符
    • B.允许函数重载,并允许设置缺省参数
    • C.规定函数说明符必须用原型
    • D.引进了类和对象的概念
  48. 在int a=3;int*p=&a;中,*p的值是()

    • A.变量a的地址值
    • B.无意义
    • C.变量p的地址值
    • D.3
  49. 下列虚基类的声明中正确的是()

    • A.class virtual B:public A
    • B.virtual class B:public A
    • C.class B:public A virtual
    • D.class B:virtual public A
  50. 使用输入输出操控符setfill,可以设置()

    • A.输出精度
    • B.输出宽度
    • C.对齐方式
    • D.填充字符
  51. 友元关系不能()

    • A.提高程序的运行效率
    • B.是类与类的关系
    • C.是一个类的成员函数与另一个类的关系
    • D.继承
  52. 下列哪种情况不属于函数重载()

    • A.类中定义的运算符函数
    • B.同一个名字,参数个数不同
    • C.派生类中重新定义了一个和基类中的原型完全相同的函数
    • D.类中定义了两个同名,同参数表的函数,其中一个是常成员函数
  53. 静态成员函数没有()

    • A.返回值
    • B.this指针
    • C.指针参数
    • D.返回类型