一起答
主观

类和对象之间的关系是抽象和具体的关系类是对多个对象进行综合抽象的结果,对象是类的________。

参考答案
查看试卷详情
相关试题
  1. 声明一个交通工具(vehicle)基类,具有maxspeed、weight成员变量,run stop成员函数(简单输出提示“正在行进”,“停止”),同时编写vehicle类的构造函数和析构函数由此派生出自行车类(bicycle)、汽车类(motorcar),自行车类有高度(height)属性,汽车(motorcar)类有座位数(seatnum)。从bicycle和motorear派生出摩托车类(motorcycle)在继承过程中注意把vehicle设置为虚基类。

  2. 完成下面类中成员函数的定义。

    #include 

    #include 

    using namespace std;

    class str

    {private:

    char*st;

    public:

    str(char*a){set(a);}

    str&operator=(__________){

    delete st;

    set(a.st);

    return*this;}

    void show(){cout<

    ~str(){delete st;}

    void set(char*s) //初始化 st

    {_____________;

    strepy(st,s); }

    };

    void main()

    {str s1"he"),s2("she");

    s1show(),s2show();

    s2=s1;

    s1show(),s2show();

    }

  3. #include

    #include 

    struct Worker

    {char name[15];//姓名

    int age;//年龄

    float pay;//工资};

    void main(){

    Worker x;char*t="LiWei";

    int d=28;float f=9000;

    strcpy(x.name,t);

    x.age=d;x.pay=f;

    cout<

    }

  4. .#include

    using namespace std;

    class B

    {

    public:

    start(){cout<"B::s() called.\n";}

    virtual~B(){cout<<"B::~start()called.\n";}

    };

    class E:public B

    {

    public:

    E(int i){

    cout<<"E::E()called.\n";

    buf=new char[i];}

    virtual~E()

    {

    delete[]buf;

    cout<<"E::~E()called.\n";

    }

    private:

    char*buf;

    };

    void fun(B*a)

    cout<<"fun()called.\n";

    delete a;

    }

    void main()

    {

    B*a=new E(15);

    fun(a);

    }

  5. 用带有默认参数的函数实现求前两个及三个正整数中的最大数。

    #include 

    using namespace std;

    int main()

    {int max(int a,int b,int c=0); 

    int a,b,c,m1,m2;

    cin>>a>>b>>C:

    ____________

    m2=max(a,b);__________

    cout<<"a,b,c三个正整数中的最大数为:"<

    cout<"a,b两个正整数中的最大数为:"<

    return 0;

    }

    intmax(int a,int b,int c)

    {if(b>a)a=b;

    ____________

    return a;

    }

  6. 程序实现大写字母转换成小写字母。 

    #include 

    void main()

    {char a ;

    ______________;

    cin>>a;

    if(______________)

    a=a+i:

    cout<

    }

  7. 程序完成后的运行结果为:DERIVEDBASE 

    #include 

    class BASE{

    public:

    ~BASE(){__________}

    };

    class DERIVED:public BASE{

    public:

    ~DERIVED(){cout<<"DERIVED";}

    };

    void main()

    {__________}

  8. 程序完成后的运行结果为:*$*$# 

    #include 

    using namespace std;

    int main()

    {int i;

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

    {if(i%3)___________;

    else continue;

    ___________

    cout<<"#\n"; 

    return 0;

    }

  9. #include 

    using namespace std;

    class CTest

    {private: 

    int x;

    public:

    CTest(int x)

    {this->x=x;}

    int getX()

    {retunx;}

    };

    int main()

    {const CTest obj(5);

     cout<

    retum0;

    }

  10. 下面的程序在VC6.0上编提示error C2440: 'type cast' :cannot convert from 'class Complex'to 'float',No user-defined-conversion operator available that can perform. this conversion 

    #include 

    using namespace std; 

    class Complex{

    public:

    Complex(float r=0,float i=0)

    {real=r;imag=i;}

    void print()

    {cout<'('<

    private:

    float real,imag;

    };

    int main()

    {Complex a(2.2f,4.4f);

    a.print();

    cout<

    return 0;

    }