位置:首页 > 题库频道 > 其它分类 > 计算机其它 > 二级二级C++全国计算机等级考试历年真题 &2007年9月计算机二级考试C++语言笔试试题

有如下程序:#include <iostream>using namespace std;class Base{public:void output(){cout<<1;}virtual void Print(){cout<<'B';}};class derived:public Base{public:void output(){cout<<2;}void Print(){cout<<'D';}};int main(){Base *ptr=new Derived;ptr->output();ptr->Print();delete ptr;return 0;}程序的输出结果是

发布时间:2024-07-09

A.1B

B.1D

C.2B

D.2D

试卷相关题目

  • 1若有如下类定义class B{void fun1(){}protected:double var1;public:void fun2(){}};class D:public B{protected:void fun3(){}};已知obj是类D的对象,下列语句中不违反类成员访问控制权限的是

    A.obj.fun1();

    B.obj.var1;

    C.obj.fun2();

    D.obj.fun3();

    开始考试点击查看答案
  • 2有如下程序:#include <iostream>using namespace std;class Base{public:Base(int x=0){cout<<x;}};class Derived:public Base{public:Derived(int x=0){cout<<x;}private:Base val;};int main(){Derived d(1);return 0;}程序的输出结果是

    A.0

    B.1

    C.01

    D.001

    开始考试点击查看答案
  • 3有如下程序:#include <iostream>using namespace std;class Part{public:Part(int x=0):val(x){cout<<val;}~Part(){cout<<val;}private:int val;};class Whole{public:Whole(int x,int y, int z=0):p2(x),p1(y),val(z){cout<<val;}~Whole(){cout<<val;}private:Part p1,p2;int val;};int main(){Whole obj(1,2,3);return 0;}程序的输出结果是

    A.123321

    B.213312

    C.213

    D.123123

    开始考试点击查看答案
  • 4有如下程序:#include <iostream>using namespace std;class MyClass{public:MyClass(int x):val(x){}void Print() const {cout<<"const:val="<<val<<'t';}void Print(){cout<<"val="<<val<<'t';}private:int val;};int main(){const MyClass obj1(10);MyClass obj2(20);obj1.Print();obj2.Print();return 0;}程序的输出结果是

    A.val=10          const:val=20

    B.const:val=10       const:val=20

    C.const:val=10       val=20

    D.val=10           val=20

    开始考试点击查看答案
  • 5有如下程序:#include <iostream>using namespace std;class MyClass{public:MyClass(){++count;}~MyClass(){--count;}static int getCount(){return count;}private:static int count;};int MyClass::count=0;int main(){MyClass obj;cout<<obj.getCount();MyClass *ptr=new MyClass;cout<<MyClass:getCount();delete ptr;cout<<MyClass::getCount();return 0;}程序的输出结果是

    A.121

    B.232

    C.221

    D.122

    开始考试点击查看答案
  • 6下列是重载惩罚运算符的函数原型生命,其中错误的是

    A.MyClass operator *(double,double);

    B.MyClass operator * (double,MyClass);

    C.MyClass operator * (MyClass,double);

    D.MyClass operator * (MyClass,MyClass);

    开始考试点击查看答案
  • 7如下函数的作用是以双倍行距输出文件:void double_space(ifstream&amp; f,ofstream&amp; t){char c;while (__________){____________;if(c=='n') t.out(c);}}画线处缺失的部分是

    A.f.get(c)与t.put(c)

    B.f.put(c)与t.get(c)

    C.t.get(c)与f.put(c)

    D.t.put(c)与f.get(c)

    开始考试点击查看答案
  • 8有如下程序:#include <iostream>using namespace std;class B{public:virtual void show(){cout<<"B";}};class D:public B{public:void show(){cout<<"D";}};void fun1(B *ptr){ptr->show();}void fun2(B &amp;ref){ref.show();}void fun3(B b){b.show();}int main(){B b,*p=new D;D d;fun1(p);fun2(b);fun3(d);return 0;}程序的输出结果是

    A.BBB

    B.BBD

    C.DBB

    D.DBD

    开始考试点击查看答案
返回顶部