一起答
单选

有关多态性说法不正确的是()

  • A.C++语言的多态性分为编译时的多态性和运行时的多态性
  • B.编译时的多态性可通过函数重载实现
  • C.运行时的多态性可通过模板和虚函数实现
  • D.实现运行时多态性的机制称为动态多态性
参考答案
查看试卷详情
相关试题
  1. 下面Shape类是一个表示形状的抽象类,Are()为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)圆形类(Circle)三角形类(Triangle)并给出具体的求面积函数。其中所有派生类计算面积需要用到的参数由构造函数给出,梯形面积计算需要上底、下底和高,三角形面积需要底和高,圆形面积需要半径。

    状的抽象类声明如下:

    class Shape{

    public:

     virtual double Area( )=0;

    };

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

    #include

    int min(int a,int b)

    {if(a

    else return b;

    return 0;

    }

    void main()

    {cout<

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

    #include< iostream.h>

    class example

    {int a;

    public:

    example(int b=5){a=b++;}

    void print(){a=a+1;cout<

    void print()const

    {cout<

    };

    void main()

    {example x;

    const example y(2);

    x.print();

    y.print();

    }

  4. 有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字

    符串。

    #include

    using namespace std;

    void copystr(_________)

    {int n=0;

    while(n

    {n++;

    P1++;

    }

    while(*p1!='\0')

    {*p2=*p1;

    p1++;

    p2++;

    }

    *p2=’\0’;

    }

    void main()

    {int m;

    char strl[20],str2[20];

    cout<"输入字符串1:";

    ____________

    cout<<从第m个字符开始复制,请输入m:”;

    cin>>m:

    if(strlen(strl)

    cout<<"输入超过str1的长度"<

    else

    {copystr(str1,str2,m);

    cout<<"复制的字符串是:"<

    }

    }

  5. 在下面程序横线处填上适当的语句,使其输出结果为0,15,15。

    #include

    class base

    {public:

    __________f(){return 0;}

    };

    class derived:public base

    {public:

    int a,b,c;

    __________set(int x,int y,int z){a=x;b=y;c=z;}

    int f(){return a+b+c;}

    };

    void main()

    {base b;

    derived d;

    cout<

    d.set(3,5,7);

    cout<

    base &p=d;

    cout<

    }

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

    #include

    class vehicle

    {protected:

    int size;

    int speed;

    public:

    void set( int s){speed =s;}

    _________get(){return speed/10;}

    };

    class car:public vehicle

    {public:

    int get(){return speed;}

    };

    class truck:public vehicle

    {public:

    int get(){return speed;}

    };

    class car:public vehicle

    {public:

    int get(){return speed/2;}

    };

    int max(_________)

    return 1;

    else

    return 2;

    }

    void main()

    {truck t;

    car c;

    t.set(160);

    c.set(80);

    cout<

    }

  7. 在下面程序的横线处填上适当内容,以使该程序执行结果为:50 4 34 21 10 0  7.1  8.1  9.1  10.1  11.1

    #include

    template

    void f(____________)

    {____________

    for(int i=0;i

    {t=a[i];a[i]=a[n-1-i;a[n-1-i]=t;}

    void main()

    {int a[5]=10,21,34,4,50};

    double[6]=11.1,10.1,9.1,8.1,7.1};

    f(a,5);f(d,6);

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

    cout<

    cout<

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

    cout<

    cout< endl;

    }

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

    #include

    template

    class f

    {private:

    T x,y,s;

    public:

    f(T a=0,T b=0){x=a;y=b;}

    void sum()

    {s=x+y;

    T gets();

    };

    template

    ____________

    {

    return s;

    }

    void main()

    {____________a(1.5,3.8);

    cout<

    }

  9. 运行程序,从键盘上输入“This is a C++ prog!”后输出到一个文件中,并显示在屏幕上,显示结果:This is a C++ prog!。

    #include

    #include

    #include

    using namespace std;

    void main()

    {char str[20];

    ofstream outf("D:\tem.dat", ios::trunc);

    Cin>>str;

    outf<

    Outf.close();

    int i=0;

    while(str[i]! ='\0')

    {cout<

    i++;

    }

    cout<

    }

  10. #include

    class B

    {int a,b

    const int c;

    Public;

    B(int i=0,int j=0){a=i;b=j;c=i-j;}

    };

    void main()

    {B a,b(3,5);

    B x=a,z(5,9);

    }