有如下程序:
#include<iostream>
usingnamespacestd;
classToy{
public:
Toy(char*_n){strcpy(name,_n);count++;)
~Toy( ){count一一;)
char*GetName( ){returnname;}
staticintgetCount( ){returncount;)
private:
charname[10];
staticintcount;
};
intToy::count=0;
intmain( ){
Toyt1("snoopy"),t2("Mickey"),t3("Barbie");
tout<<t1.getCount( )<<endl:
return0;
)
运行时的输出结果是( )。
A.1
B.2
C.3
D.运行时出错
第1题:
有如下程序: #include<iostream>#include<iosream> using namespace std; class BASE{ char c; public; BASE(char n):c(n){} virtual ~ BASE(){cout<<c;} }; class DERIVED; public BASE{ char c; public: DERIVED (char n): BASE (n+1)
A.XY
B.YX
C.X
D.Y
第2题:
有如下程序: #include<iostream> using namespace std; class Toy{ public: Toy(char*_n){strcpy(name,_n);count++;} ~Toy(){count--;} char*GetName( ){return name;} static int getCount( ){return count;} private: char name[10]; static int count; }; int Toy::count=0: int main( ){ Toy tl("Snoopy"),t2("Mickey"),t3("Barbie"); cout<<t1.getCount( )<<endl; return 0; } 程序的输出结果是
A.1
B.2
C.3
D.运行时出错
第3题:
有以下程序 #include<iostream> using namespace std; class Base { private: char c; public: Base(char n):c(n){} ~Base() { cout<<c; } }; class Derived:public Base { private: char c; public: Derived(char n):Base(n+1),c(n){} ~Derived() { cout<<c; } }; int main() { Derived obj('x'); return 0; } 执行后的输出结果是
A.xy
B.yx
C.x
D.y
第4题:
有如下程序:#include <iostream>using namespace std;class Base{private: char c;public: Base(char n) :c(n){} ~Base() { cout<<c; } };class Derived: public Base{private: char c; public: Derived(char n):Base(n+1),c(n) {} ~Derived() { cout<<c; }};int main (){ Derived obj ('x'); return 0;}执行上面的程序净输出
A.xy
B.yx
C.x
D.y
第5题:
有如下程序: #include<iostream> usingnamespacestd; classToy{ public: Toy(char*_n){strcpy(name,_n);count++;) ~Toy( ){count一一;) char*GetName( ){returnname;} staticintgetCount( ){returncount;) private: charname[10]; staticintcount; }; intToy::count=0; intmain( ){ Toyt1("snoopy"),t2("Mickey"),t3("Barbie"); tout<<t1.getCount( )<<endl: return0; ) 运行时的输出结果是( )。
A.1
B.2
C.3
D.运行时出错