niusouti.com

有以下程序: #include 〈iostream〉 #include 〈string〉 using namespace std; class visited { private: int number; char *name; public: static int glob; void set mes(char *a); }; void visited::set mes(char *a) { name=new char[strlen(A) +1]; strcpy(name,A) ; number=++g

题目

有以下程序: #include 〈iostream〉 #include 〈string〉 using namespace std; class visited { private: int number; char *name; public: static int glob; void set mes(char *a); }; void visited::set mes(char *a) { name=new char[strlen(A) +1]; strcpy(name,A) ; number=++glob; } int visited::glob-O; int main() { visited person[10]; int i; char str[8]; for(i=0;i<5;i++) { cin>>str; person[i] .set mes(str); } cout<

A.5

B.4

C.3

D.2


相似考题
更多“有以下程序:#include 〈iostream〉#include 〈string〉using namespace std;class visited{private: ”相关问题
  • 第1题:

    有以下程序:includeincludeusing namespace std; class point{private:double

    有以下程序: #include<iostream> #include<math> using namespace std; class point { private: double x; double y; public: point(double a,double B) { x=a; y=b; } friend double distance (point a,point B) ;

    A.1

    B.5

    C.4

    D.6


    正确答案:C
    解析:本题考核友元函数的应用。分析程序:类point中定义了两个私有成员x和y,以及一个友元函数distance。从而,函数distance可以访问类point中的任何成员。在函数distance中,返回值为sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y))。由此可知,函数distance的功能是计算a、b两点之间的距离。在主函数main中,先定义两点:p1(1,2)和p2(5,2)。然后调用函数distance计算两点之间的距离为4,所以程序最后输出为4。

  • 第2题:

    以下程序的运行结果是【】。 include include using namespace std; void main()

    以下程序的运行结果是【 】。

    include<iostream>

    include<string>

    using namespace std;

    void main(){

    chara[10]="China",b[]="Chin",c[]="ese";

    cout<<strlen(strcat(strcpy(a,b),c))<<endl;

    }


    正确答案:7
    7 解析:本题主要考查C++中字符串函数的使用。strcpy(s1,s2)将s2的内容赋值到s1中; strcat(s1,s2)连接s1和s2两个字符串;strlen(s)返回字符数组s的长度。因此最后输出的结果是b和c进行连接后的字符串长度,即7。

  • 第3题:

    有以下程序:includeincludeusxng namespace std;int main(){ char p[] = "a

    有以下程序: #include <iostream> #include <string> usxng namespace std; int main() { char p[] = "abcdefgh"; cout<<strlen(strcpy(p,"12345"))<<end1; return 0; } 执行后输出的结果是( )。

    A.8

    B.12

    C.5

    D.7


    正确答案:C
    解析:本题考查对字符串函数的熟悉程度。本题主要考查strlen和strcpy两个函数,先来了解这两个函数。①函数strcpy()的函数原型为:char*strcpy(char*strDest,constchar*strSrC);其功能是复制strSrc所有字符到strDest,并返回strDest。②函数strlen()的函数原型为:size_tstrlen(constchar*string);,其功能是返回string的长度,不包括结束字符'\0'。在了解函数的原型和功能后,再分析本程序。程序首先定义了字符数组p,并赋初值"abcdefg",然后将字符串"12345"复制到数组p中,此时数组中元素变为字符串"12345",然后调用函数strlen求出数组p中的字符数为5(不包括结束标志符'\0')。

  • 第4题:

    有以下程序:includeusing namespace std;class BASE{private: char c;public: BASE(c

    有以下程序: #include <iostream> using namespace std; class BASE { private: char c; public: BASE(char n):c(n);{} virtual~BASE() { cout<<c; } }; class DERIVED:public BASE { char c; p

    A.XY

    B.YX

    C.X

    D.Y


    正确答案:A
    解析:在C++中,由于析构函数不能被继承,因此在执行派生类的析构函数时,基类的析构函数也将被调用。执行顺序是先执行派生类的析构函数,再执行基类的析构函数,其顺序与执行构造函数的顺序正好相反。在此题的程序中,在主函数结束时,派生类DERIVED对象obj将被删除,所以就会调用对象的析构函数。先调用派生类的析构函数,输出X,然后调用基类的析构函数,输出Y。

  • 第5题:

    有以下程序:include using namespace std;define PI 3.14class Point{ private:int

    有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; }

    A.314

    B.157

    C.78.5

    D.153.86


    正确答案:A
    解析:本题考核派生类的定义和应用。本程序设计了一个点类Point,包含了横、纵两个坐标数据x和y,由它派生出了圆类Circle,并加入了新的数据成员,即一个半径r和一个求圆面积的函数成员area。在主函数main中,首先定义了一个圆Circle类的对象c1,并通过它的构造函数初始化其数据成员。由此可知,其半径r的值为10,所以其面积为PI*10'10=314,即对象c1的函数成员area的返回值为314。