有如下程序: #inc1ude<iostream> #inc1ude<cstring>. using namespace std; class XCD{ char*a: int b: public:

admin2019-06-12  25

问题 有如下程序:
    #inc1ude<iostream>
    #inc1ude<cstring>.
    using namespace std;
    class XCD{
    char*a:
    int b:
    public:  
    XCD(char* aa,int bb){
    a=new char[strlen(aa)+1];
    strcpy(a,aa),
    b=bb;
    }
    char* Geta(){ return a;}
    int Getb(){return b;}
    };
    int main(){
    char *p1="abcd",*p2="weirong";
    int d1=6,d2=8;
    XCD x(p1, d1), y(p2, d2);
    cout<<strlen(x.Geta())+y.Getb()<<end1;
    return0;
    }
    运行时的输出结果是(     )。

选项 A、12
B、16
C、14
D、11

答案A

解析 由类XCD的定义可知,成员函数Geta()返回的是字符串的长度,Getb0返回的是参数b的值。在主函数中strlen(x.Geta(》的值等于4,y.Getb()的值等于8,所以输出两者的和为12。
转载请注明原文地址:https://kaotiyun.com/show/OU8p777K
0

最新回复(0)