有如下程序:#includeiostreamusingnamespacestd;classMyClass{public:MyClass(intx):val(x){}voidPrint()const{coutconst:val=val\t;}voidPrint(){coutval=valt;}private:intval;};intmain(){constMyClassobj1(10);MyClassobj2(20);obj1.Print();obj2.Print();return0;}程序的输出结果是( )。A.va1=10const:va1=20B.const:va1=10const:va1=20C.const:va1=10val=20D.val=10va1=20
有如下程序:
#include<iostream>
usingnamespacestd;
classMyClass{
public:
MyClass(intx):val(x){}
voidPrint()const{cout<<"const:val="<<<val<<'\t';}
voidPrint(){cout<<"val="<<val<<'t';}
private:
intval;
};
intmain(){
constMyClassobj1(10);
MyClassobj2(20);
obj1.Print();
obj2.Print();
return0;
}
程序的输出结果是( )。
A.va1=10const:va1=20
B.const:va1=10const:va1=20
C.const:va1=10val=20
D.val=10va1=20
相关考题:
有如下程序: nclude using namespace Std; Class MyClass{ public: 有如下程序: #nclude<iostream> using namespace Std; Class MyClass{ public: MyClass(int i=0){cout<<1;} MyClass(constMyClassx){cout<<2;} MyClass perator=(const MyClassx){cout<<3;return*this;} ~MyClass(){cout<<4;} }; int main(){ MyClass obj1(1),obj2(2),obj3(obj1); return 0: } 运行时的输出结果是( )。A.112444B.11114444C.121444D.11314444
有如下程序: include using namespace std; class MyClass { public: 有如下程序: #include <iostream> using namespace std; class MyClass { public: MyClass() { ++count; } ~MyClass() { --count; } static int getCount() { return count; } private: static int count; }; int MyClass::count=0; int main() { MyClass obj; cout<<obj.getCount(); MyClass *ptr=new MyClass; cout<<MyClass::getCount(); delete ptr; cout<<MyClass::getCount(); return 0; }程序的输出结果是A.121B.232C.221D.122
有如下程序:includeusing namespace std;class MyClass{public:MyClass(int x):val(x 有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x){} void Print()const{cout<<“const:val=”<<<val<<‘\’;} void Print(){cout<<“val=”<<val<<‘t’;} private: int va1; }; int main(){ consA.val=10 const:val=20B.const:val=10 const:val=20C.const:val=10 val=20D.val=10 val=20
类的说明如下,请指出错误的地方 ______。 class Myclass { int a=111; public: Myclass(int x, int y); Myclass(int val); ~Myclass(); }A.int a=111;B.Myclass(Int x, int y);C.Myclass(int val);D.~Myclass();
有以下程序:includeusing namespace std;class MyClass{public:MyClass(int n){numbe 有以下程序: #include<iostream> using namespace std; class MyClass { public: MyClass(int n){number=n;} //拷贝构造函数 MyClass(MyClassother) {number=other.number;} ~MyClass() {} private: int number; }; MyClass fun(MyClass p)A.5B.4C.3D.2
有如下程序:includeusing namespace std;class MyClass{public: MyClass(int x):val( 有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(int x):val(x) {} void Print() const {cout<<"const:val="<<val<<'\t';} void Print() {cout<<"val="<<val<<'t';} private: int val; }; int main() const MyClass obj1(10); MyClass obi2(20); obj1.Print(); obj2.Print(); return 0; } 程序的输出结果是( )。A.val=10 const:val=20B.const:val=10 const:val=20C.const:val=10 val=20D.val=10 val=20
有如下程序include include using namespace std;class MyClass {public:M 有如下程序#include <iostream>#include <iomanip>using namespace std; class MyClass {public:MyClass(){ cout<<'A'; }MyClass(char c){ cout<<c; }~MyClass(){ cout<<'B'; }};int main() {MyClass p1,*p2;p2=new MyClass('X');delete p2;return 0;}执行这个程序屏幕上将显示输出( )。A.ABXB.ABXBC.AXBD.AXBB
有如下程序:includeusing namespace std;class MyClass{public:MyClass(){++count;}~ 有如下程序: #include<iostream> using namespace std; class MyClass{ public: MyClass(){++count;} ~MyClass(){--count;} static int getCount(){return count;} private: static int count; }; int MyClass::count=0; int main(){ MyClA.121B.232C.221D.122
如下程序的输出结果是includeusing namespace std;class MyClass{public:MyClass(int 如下程序的输出结果是 #include<iostream> using namespace std; class MyClass{ public: MyClass(int i=0){cout<<1;} MyClass(const MyClass&x)}cout<<2;} }; int main( ){ MyClass objl(1),obj2(2),ohj3(objl); return 0; }A.112B.111C.121D.113
有如下程序:includeusing namespace std;class MyClass{public:MyClass(int x):val( 有如下程序: #include<iostreanl> using namespace std; class MyClass{ public: MyClass(int x):val(x){ } void Set(int x){val=x;} void Print( )eonst{eout<<"val="<<val<<'\t';} private: int val; }; int main( ){ eonst MyClass objl(10); MyClass obj2(20); objl.Print(); //语句1 obj2.Print( ); //语句2 objl.Set(20); //语句3 obj2.Set(30); //语句4 return 0; } 其主函数中错误的语句是A.语句1B.语句2C.语句3D.语句4