2009年3月计算机等级考试二级C++真题(文字版)

来源:计算机等级考试    发布时间:2012-08-29    计算机等级考试视频    评论

    二、填空题(每空2分,共30分)

    (1)假设用一个长度为50的数组(数组元索的下标从0到49)作为栈的存化空间,栈底指针bottom指间栈底元素,栈顶指针top指向栈顶元素,如果bottom=49,top=30(数组下标),则栈中具有【1】个元素。   

    (2)软件测试可分为白盒测试和黑盒测试。基本路径测试属于【2】测试。   

    (3)符合结构化原则的三种基本控制结构是:选择结构、循环结构和【3】。   

    (4)数据库系统的核心是【4】。   

    (5)在E-K图中,图形包括矩形框、菱形框、椭圆框。其中表示实体联系的是【5】框。   

    (6)有如下程序段:
    int x=1,Y=2,z=3;
    x=x^z;
    y=y^z;
    z=x^y;
    cout<    执行这个程序段的输出是【6】。   

    (7)有如下程序段:
    fer(int i=1; i<=50;i++){
    if(i%3 != 0)
    continue;
    else
    if(i%5!=0)
    continue;
    tout<    }
    执行这个程序段的输出是【7】。   

    (8)有如下程序段:
    Char  c [20]=“examination”;
    c[4]=0;
    cout<    执行这个程序段的输出是【8】。   

    (9)下面的函数利用递归实现了求1+2+3+……+n的功能:
    int sum(int n){
    if(n==0)
    return 0;
    else
    return n+sum(n-1);
    }
    在执行sum(10)的过程中,递归调用sum函数的次数是【9】。   

    (10)非成员函数应该声明为类【10】函数才能访问该类的私有成员。   

   (11)有如下程序:
    #include
    using namespace std;
    class Monitor{
    public:
    Monitor(char t):type (t){}
    void print( ) const
    {cout<<“The type of monitor is”<    private:
    char type;
    };
    class Computer{
    public:
    Computer(int i,char c): 【11】{}
    void Print()const
    {cout<<“The computer is”<    private:
    int id;
    Monitor mon;
    };
    const Computer myComputer(101,'B‘);
    myComputer .Print();
    return 0;
    }
    请将程序补充完整,使程序在运行时输出:
    The computer is 101
    'The type of monitor i.s 8   

    (12)有如下程序:
    #include
    using namespace std
    class Animal{
    public:
    virtual char* getType()const { return “Animal”;}
    virtual char* getVoice()const { return “Voice”;}
    };
    Class Dog : public Animal {
    public:
    char* getType ( ) const {return “Dog”;}
    char* getVoice ( ) const {return “Woof”}
    };
    void type(Animal& a) {cout<    void speak(Animal a) {cout<    int main( ) {
    Dog d; type (d);cout<<“ speak”;speak(d);cout<    return 0;
    }
    运行时的输出结果是【12】。   

    (13)补充完整下面的类定义:
    const double PI=3 .14;
    class Circle{   //圆形物体的抽象基类
    protected:
    double r;      //半径
    public:
    Circle(double radius=0):r(radius){}
    【13】;//计算圆形物体表面积的纯虚函数声明
    };
    class Cylinder:public Circle {  //圆柱体类
    double h;       //高度
    public:
    Cylindr(double radius=0, doubli height=0):
    Circle(radius),h (height){}
    Virtual double Area() { //计算圆柱体的表面积
    return 2*PI*r*(r+h);
    }
    };   

    (14)补充完整下面的类定义:
    class XCH{
    char* a;
    public:
    XCH(char* as) { //构造函数
    a=new char[strlen(aa)+1];
    strcpy(a,aa);
    }
    XCH& operator=(const XCH& x)     //重载赋值函数
    Delele []a;
    A=new char[strlen(x.a)+l];
    strcpy(a, x .a)
    【14】;
    }
    ~XCH() {delete []a;}
    };   

    (15)补充完整下面的模板定义:
    template  //Type为类型参数
    class Xtwo{    //由两个Type类型的数据成员构成的模板类
    Type a;
    Type b;
    public:
    Xtwe(Type aa=0, Type bb=0):a(aa),b(bb){}
    int Ccmpare  (){//比较a和b的大小
    if (a>b)returm 1;
    else if(a==b) return 0;
    else return -1;
    }
    Type Snm() {return a+b;} //返回a和b之和
    Type Mult();         //函数声明,返回a和b之乘积
    };
    Template
    【15】::Mult(){return a*b;} //Mult 函数的类外定义

上一页456下一页

视频学习

我考网版权与免责声明

① 凡本网注明稿件来源为"原创"的所有文字、图片和音视频稿件,版权均属本网所有。任何媒体、网站或个人转载、链接转贴或以其他方式复制发表时必须注明"稿件来源:我考网",违者本网将依法追究责任;

② 本网部分稿件来源于网络,任何单位或个人认为我考网发布的内容可能涉嫌侵犯其合法权益,应该及时向我考网书面反馈,并提供身份证明、权属证明及详细侵权情况证明,我考网在收到上述法律文件后,将会尽快移除被控侵权内容。

最近更新

社区交流

考试问答