有如下类定义,请将Sample类的复制构造函数补充完整。class Sample{public:Sample( ){ }~Sample( ){if(P)delete P;)Sample(const Samples){______}void SetData(int datA) {P=new int(datA) ;}private:int*P:};

有如下类定义,请将Sample类的复制构造函数补充完整。

class Sample{

public:

Sample( ){ }

~Sample( ){if(P)delete P;)

Sample(const Sample&s){______}

void SetData(int datA) {P=new int(datA) ;}

private:

int*P:

};


相关考题:

下列程序中的重载函数disp( )发生错误,错误原因是【 】。 includeclass Sample {priva 下列程序中的重载函数disp( )发生错误,错误原因是【 】。include<iostream, h>class Sample{private:int m;static int sr;public:Sample(int a) {m=a; st+=a; }static void disp(){cout<<m<<end1; }static void disp(Sample input){cout<<input. m<<end1;}};int Sample: : st=2;void main(){Sample Eirst(2), Second(4)Sample: :disp( );Sample: :disp (Second);}

类Sampie的构造函数将形参data赋值给数据成员data。请将类定义补充完整。class Sample{public:Sample(int data=0);priVate:int data:};Sample::Sample(int datA) {______}

( 10 )类 Sample 的构造函数将形参 data 赋值给数据成员 data 。请将类定义补充完整。class Sample{public:Sample(int data=0);Private:Int data;};Sample::Sample(int data){【 10 】}

( 11 )有如下类定义:class Sample{public:Sample();~Sample();Private:Static int date;};将静态数据成员 data 初始化为 0 的语句是 【 11 】 。

有以下程序: include using namespace std; class sample {int x; public:void setx( 有以下程序:include <iostream>using namespace std;class sample{int x;public:void setx(int i){x=i;}int putx (){return x;}};int main ( ){sample *p;sample A[3];A[0] .set>:(5);A[1] .setx(6);A[2] .setx(7);for (int j=0;j<3;j++){p=A[j];cout<<p->putx () <<", ";}cout<<end1;return 0;}执行后的输出结果是【 】。

在下面的类定义中,this指针的用途是______。 include class Sample { int x,y; publi 在下面的类定义中,this指针的用途是______。include<iostream.h>class Sample{int x,y;public:Sample(int i,int j){x=i;y=j;}void assign(Sample sa);};void Sample::assign(Sample p){if(this!=p){x=p.x;y=p.y;}}

已知一个类Sample,( )是定义指向类Sample成员函数的指针,假设类有三个公有成员:voidf1(int),void f2(int)和int a。A.Sample*pB.Int Samale::*pc=Sample::aC.Void(Sample::*Pa)()D.Sample*P[10]

有如下程序:include using namespace std;class sample{private:int x,y;public: sam 有如下程序: #include <iostream> using namespace std; class sample { private: int x,y; public: sample(int i,int j) { x=i; y=j; } void disp () { cout<<"disp1"<<end1; } void disp() const { cout<<"disp2"<<end1; };int main () { const sample a(1,2); a.disp(); return 0; } 该程序运行后的输出结果是A.disp1B.disp2C.disp1 disp2D.程序编译时出错

在下面的类定义中,错误的语句是class Sample { public: Sample(int val); //①~Sample(): //②private: int a=2.5; //③Sample(); //④ };A.①②③④B.②C.③D.①②③

下列类的构造函数不能通过编译,正确的构造函数应该是______。 include class Sample 下列类的构造函数不能通过编译,正确的构造函数应该是______。include<iostream.h>class Sample{public:int n;const int con;Sample(int m) {con=m+1;n=m;}void disp( ) {cout<<"normal:n="<<n<<endl;}void disp( )const {cout<<"static:n="<<n<<endl;}};void main( ){const Sample a (12);Sample b (13);a.disp( );b.isp( );cout<<a.n<<","<<b.con<<endl;}

已知一个类Sample,( )是定义指向类Sample成员函数的指针,假设类有三个公有成员:voidfl(int),void f2(int)和int a。A.Sample*pB.Int Samale::*pc=Sample::aC.Void (Sample::*Pa) ()D.Sample *P[10]

下面程序的运行结果是()。includeclass Sample{int x, y;public:Sample() { x=y=0; 下面程序的运行结果是( )。#include<iostream.h>class Sample{int x, y;public:Sample() { x=y=0; }Sample(int a, int b) { x=a; y=b; }void (lisp(){cout<<"x="<<x<<",y="<<y<<end1;}};void main(){Sample s(2,3), *p=s;p->disp();}A.x=1, y=2B.x=2, y=4C.x=2, y=3D.x=4, y=3

有如下类定义,请将Sample类的拷贝构造函数补充完整。class Sample{public:Sample(){)~Sample(){if(p)delete p;)Sample(const Sample s){______}void SetData(int data) {p=new int(data);}private:int*p;};

下列程序的运行结果是【 】。includeclass Sample{int a;public: Sample(int aa=0) {a 下列程序的运行结果是【 】。include<iostream, h>class Sample{int a;public:Sample(int aa=0) {a=aa;}~Sample() {cout<<"Sample="<<a<<;}class Derived: public Sample{int b;public:Derived(int aa=0, int bb=0): Sample(aa) {b=bb;}~De rived() {cout <<"Derived="<<b<<'';}void main(){Derived dl (9)}

使用VC6打开考生文件夹下的工程test12_1,此工程包含一个源程序文件test_12.cpp,但该程序运行有问题,请改正程序中的错误,使该程序的输出结果如下:fun (Sample p) 1 2fun (Sample *p) 3 420 10源程序文件test12_1清单如下:include<iostream .h>class Sample{private:int x,y;static int z;public:Sample(int a,int b){ x=a;y=b; }void fun(Sample p);void fun(Sample *p);static void print(Sample s);};/*************** found ***************/int z=10;void Sample::fun(Sample p){x=p.K;y=p.y;cout<<"fun(Sample p)"<<" "<<x<<" "<<y<<endl;}void Sample::fun(Sample *p){/************** found **************/x=p.x; y=p.y;cout<<"fun(Sample *p) "<<" '<<x<<" "<<y<<endl;}void Sample::print (Sample s){/*************** found *****************/x=20;cout<<s. x<<" "<<z<<endl;}void main(){Sample p(1,2),q(3,4);p. fun(p);p. fun(q);p. print(p);}

有以下程序:includeusing namespace std;class sample{private:int x;public:sample( 有以下程序: #include<iostream> using namespace std; class sample { private: int x; public: sample(int A) { x=a; friend double square(sample s); }; double square(sample s) { return S.X*S.K; } int main() { saA.20B.30C.900D.400

若有以下程序: include usingnamespace std; class Sample { private: const int n; 若有以下程序:include <iostream>using namespace std;class Sample{private:const int n;public:Sample(int i) :n(i) {)void print(){cout<<"n="<<n<<end1;}};int main(){sample a(10);a.print();return 0;}上述程序运行后的输出结果是【 】。

有以下程序:include using namespace std;class sample{private: int x; static int 有以下程序:#include <iostream>using namespace std;class sample{private: int x; static int y;public: sample(int a); static void print(sample s);};sample:: sample(int a){ x=a; y+=x;}void sample:: print(sample s){ cout<<"x="<<s. x<<",y="<<y<<end1;}int sample:: y=0;int main(){ sample s1(10); sample s2(20); sample:: print(s2); return 0;}程序运行后的输出结果是( )。A.x=10,y=20B.x=20,y=30C.x=30,y=20D.x=30,y=30

有以下程序:includeusing namespace std;class sample{private:int x;static int y; 有以下程序: #include<iostrearn> using namespace std; class sample { private: int x; static int y; public: sample (int A) ; static void print (sample s); }; sample::sample(int A) { x=a; y+=x; }A.x=10,y=20B.x=20,y=30C.x=30,y=20D.x=30,y=30

有如下类声明: class SAMPLE { int n; public: SAMPLE(int i=0):n(i) { } void setValue(int nO); }; 下列关于getValue 成员函数的实现中,正确的是A.SAMPLE::setValue(int nO){ n=nO;}B.void SAMPLE::setValue(int nO){ n=nO;}C.void setValue(int nO){ n=nO;}D.(int nO){ n=nO;}

有以下程序:include using namespace std;class sample{private: int x;public: void 有以下程序: #include <iostream> using namespace std; class sample { private: int x; public: void setx(int i) { x=i; } int putx () { return x; } }; int main ( ) { sample *p; sample A[3]; A[0] .setx(5); A[1] .setx (6); A[2] .setx(7); for (int j=0;j<3;j++) { p=A[j]; cout<<p->putx () <<", "; } cout<<end1; return 0; } 执行后执行结果是( )。A.5,6,7,B.5,5,5,C.6,6,6,D.7,7,7,

有以下程序:includeusing namespace std;Class sample{private:int n;public:sample( 有以下程序: #include<iostream> using namespace std; Class sample { private: int n; public: sample(){} sample(int m) { n=m; } sample add(sample s1,samplc s2) { this-->n=s1.n+s2.n; return(*this); } void disp(A.n=10B.n=5C.n=20D.n=15

以下程序段有()处错误。include using namespaces std;class Sample{private: int n;p 以下程序段有( )处错误。 #include <iostream> using namespaces std; class Sample { private: int n; public: Sample (int i} { n=i; } void setvalue(int i) { n=i; } void display() { cout<<"n="<<n<<end1; } }; int main ( ) { const Sample a(lO); a. setvalue (5)'; a.display(); return 0; }A.1B.2C.3D.4

有如下类声明: class SAMPLE { int n: public: SAMPLE(int i=0):n(i){} void setValue(int nO); }; 下列关于9etValue成员函数的定义中,正确的是( )。A.SAMPLE::setValue(int nO){n=n0;}B.void SAMPLE::setValue(int胡){n=n0;C.void setValue(int nO){n=n0;}D.setValue(int nO){n=n0;}

若有如下程序: include using namespaces std;int s=O;class sample {static int n;p 若有如下程序: #include <iostream> using namespaces std; int s=O; class sample { static int n; public: sample(int i) { n=i; } static void add() { s+=n; } }; int sample::s=O; int main() { sample a(2),b(5); sample: :add(); cout<<s<<end1; return 0; } 程序运行后的输出结果是A.2B.5C.7D.3

请在下列程序中的横线处填写正确的语句:class Sample{public:Sample()()~Sample(){}void SetData(int data){//将Sample类成员变量data设置成形参的值______}private:int data;};

有如下类定义:class Sample{public:Sample();~Sample();private:static int data;};将静态数据成员data初始化为0的语句是【 】。