( 30 )有如下程序:#include<iostream>using namespace std;class AA{lilt k;protected:int n;void setK ( int k ) { this->k=k;}public:void setN ( int n ) { this->n=n;}};class BB: public }{/* 类体略 */};int main () {BB x_ ; //1x .n=1; //2x.setN ( 2 ) ; //3x.k=3; //4x .se

题目

( 30 )有如下程序:

#include<iostream>

using namespace std;

class AA{

lilt k;

protected:

int n;

void setK ( int k ) { this->k=k;}

public:

void setN ( int n ) { this->n=n;}

};

class BB: public }{/* 类体略 */};

int main () {

BB x_ ; //1

x .n=1; //2

x.setN ( 2 ) ; //3

x.k=3; //4

x .setK ( 4 ) ;

return 0;

}

在标注号码的四条语句中正确的是

A ) 1

B ) 2

C ) 3

D ) 4


相似考题
更多“( 30 )有如下程序:#include&lt;iostream&gt;using namespace std;class AA{lilt k;protected:int ”相关问题
  • 第1题:

    有如下程序:includeusing namespace std;class XX{protected;int k;public:XX(int n=

    有如下程序: #include<iostream> using namespace std; class XX{ protected; int k; public: XX(int n=5):k(n){} ~XX(){cout<<"XX";} Virtual void f()cons=0; }; inline void XX::f()const{cout<<k+3;} class YY:public XX{ public:

    A.28XX

    B.28YYXX

    C.-33XX

    D.-33XXYY


    正确答案:A

  • 第2题:

    有如下程序:includeusingnamespacestd;classXX{protected: intk;public: XX(intn=5):

    有如下程序: #include <iostream> using namespace std; class XX { protected: int k; public: XX(int n=5):k(n){} ~XX() { cout<<"XX"; } virtual void f() const=0; }; inline void XX::f()

    A.28XX

    B.28YYXX

    C.-33XX

    D.-33XXYY


    正确答案:A
    解析:本题中,&p是一个对象指针,通过使用new运算符变成了指向派生类YY的对象指针。所以当建立并初始化对象指针&p时,程序将调用基类XX的构造函数,给私有数据成员k赋值5。然后调用派生类YY的常成员函数f(),输出值2和8。最后调用基类XX的析构函数输出XX。

  • 第3题:

    00330038003000301585067361821下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)

    A.<class 'int'> <class 'float'> <class 'str'>

    B.<class 'float'> <class 'int'> <class 'str'>

    C.<class 'str'> <class 'float'> <class 'int'>

    D.<class 'str'> <class 'int'> <class 'float'>


    A

  • 第4题:

    以下程序的输出结果是#include <conio.h>#include <stdio.h>#define M 100void fun(int m, int *a, int *n){ int i,j=0; for(i=1;i<=m;i++) if(i%7==0||i%11==0) a[j++]=i; *n=j;}main(){ int aa[M],n,k; clrscr(); fun(100,aa,&n); for(k=0;k<n;k++) if((k+1)%20==0)printf("\n"); else printf("%d",aa[k]); printf("\n"); }


    正确答案:77
    在本题中,程序首先定义一个宏M,然后定义一个fun函数,函数带有三个形参,分别是一个整型形参m和两个整型指针形参a、n。在函数体中,首先定义两整型变量i和j,并给j赋初值为0,然后执行循环,循环体中首先是一个条件判断语句,如果结果为真,则说明变量i能同时被7和11整除,并将变量i保存到数组中,循环结束后,将数组中元素的个数通过指针变量n进行返回。通过分析可以知道,fun函数的作用是求取1到m中能同时被7和11整除的整数,并将结果保存到数组a中。
    在主函数中,首先定义了两个整型变量和一个整型数组aa,然后调用clrscr()函数对文本模式窗口进行清除操作。接着调用fun函数,根据上面我们对fun函数的分析,要计算1~100之间能同时被7和11整除的整数,很显然,这样的数只有77一个,那么此时数组aa中只有一个元素为77,而n的值是1。
    接着执行for循环,从程序中不难看出循环的作用是将数组aa中的元素按一定的规则输出,其规则为每行最多只能输出20个值。结合上面的分析,数组aa中只有一个元素为77,因此,本题程序的最终输出结果为77。

  • 第5题:

    阅读下列说明和C++代码,填写程序中的空(1)~(6),将解答写入答题纸的对应栏内。
    【说明】
    以下C++代码实现一个简单绘图工具,绘制不同形状以及不同颜色的图形。部分类及其关系如图6-1所示。



    【C++代码】
    #include?#include?using?namespace?std;class?DrawCircle?{??????//绘制圆形,抽象类? ? ? public: (1);//定义参数为?int?radius,?int?x,?inty? ?virtual~DrawCircle()?{?}};class?RedCircle:public?DrawCircle?{????//绘制红色圆形? ? ? ? public: void?drawCircle(intradius,?int?x,?int?y)?{cout?<?drawCircle?=?drawCircle;? }? ?virtual~shape()?{?}? public:? ?virtual?void?draw()?=?0;};class?Circle:public?Shape?{????//圆形? ? private:? ? ?int?x,y,radius;? ? public:? Circle(int?x,inty,int?radius,DrawCircle?*drawCircle)? (3)? {? this->x?=?x;? ?this->y?=?y;? ? this->radius?=?radius; }? ? ? public:? void?draw(){? drawCircle?-> (4); }};int?main(){Shape?*redCirclenew?Circle(100,100,10,????(5)????);//绘制红色圆形? Shape?*greenCircle=new?Circle(100,100,10, (6)??);//绘制绿色圆形redCircle >draw();? ?greenCircle?->draw();? ?return?0;}


    答案:
    解析:
    (6)(1)void drawCircle (int radius,int x,int y)
    (2)DrawCircle*drawCircle
    (3)drawcircle
    (4)drawCircle(radius,x,y)
    (5)new RedCircle()
    (6)new GreenCircle()【解析】
    第一空是填接口里面的方法,在接口的实现里面找,可以发现应该填void drawCircle (int radius,int x,int y)。
    第二空可以根据后面this drawCircle=drawCircle判断,这里应该有一个drawCircle属性,因此应该填)DrawCircle drawCircle。
    第三空这里填drawcircle,用-> drawcircle来引用父类的成员。
    第四空调用drawCircle(radius,x,y)方法。
    第五、六空分别创建一个红色圆形对象和一个绿色圆形对象作为Circle里面的实参。

  • 第6题:

    下列程序段执行结果是___________。 x = 1 print(type(x)) x = 1.0 print(type(x)) x = '1.0' print(type(x)

    A.<class 'int'> <class 'float'> <class 'str'>

    B.<class 'float'> <class 'int'> <class 'str'>

    C.<class 'str'> <class 'float'> <class 'int'>

    D.<class 'str'> <class 'int'> <class 'float'>


    C.循环执行1次