#include”iostream.h”
C1ass CCouter
{
int value;
public:
CCounter();
CCounter(int val);
~CCounter();
};
class CExample
{
intvalue;
public:
CCounter car;
CExample();
cexample(int val);
void DISplay();
~CExample();
};
CCounter::CCounter()
{
cout<<”ccounter Constructorl”<<endl;
value=o;
}
CCounter::CCounter(int val)
毛
cout<<”CCounter constructor2”<<endl;
value=val;
}
CCounter::~CCounter()
{
cout<<”CCounter Destructor”<<endl;
}
CExarnple::CExample()
{
cout<<”CExample constructorl”<<endl;
value=0;
}
CExample::CExample(int val)
{
cout<<”CExamPle Constructorl”<<endl;
value=val;
}
void CExample::Display()
{
cout<<”value=” <<value<<endl;
}
CExample::~CExample()
{
cout<<”CExample Destructor”<<endl;
}
void main()
{
CExample e(2);
e.Display();
}
答:ccounter Constructor2
CExample Constructor2
Value=2;
CExample Destmctor
CCoullter Destructor
14.以下程序运行的结果为。
#include<iostream.h>
Class B
{
public:
B(){};
B(int i , int j);
void Printb ();
private:
int a,b;
};
classA
{
public:
A(){};
A(int i,int j);
void printa();
private:
B C;
};
A::A(int i,int D):c(i,j)
{ };
void A::printa()
{
c.printb();
}
B::B(int i,int j)
{
a=i;b=j;
}
void B:: printb()
{
cout <<”a=” <<a<<”,b=” <<b <<endl;
}
void main()
{
A m(7’8);
m.printa();
}
C1ass CCouter
{
int value;
public:
CCounter();
CCounter(int val);
~CCounter();
};
class CExample
{
intvalue;
public:
CCounter car;
CExample();
cexample(int val);
void DISplay();
~CExample();
};
CCounter::CCounter()
{
cout<<”ccounter Constructorl”<<endl;
value=o;
}
CCounter::CCounter(int val)
毛
cout<<”CCounter constructor2”<<endl;
value=val;
}
CCounter::~CCounter()
{
cout<<”CCounter Destructor”<<endl;
}
CExarnple::CExample()
{
cout<<”CExample constructorl”<<endl;
value=0;
}
CExample::CExample(int val)
{
cout<<”CExamPle Constructorl”<<endl;
value=val;
}
void CExample::Display()
{
cout<<”value=” <<value<<endl;
}
CExample::~CExample()
{
cout<<”CExample Destructor”<<endl;
}
void main()
{
CExample e(2);
e.Display();
}
答:ccounter Constructor2
CExample Constructor2
Value=2;
CExample Destmctor
CCoullter Destructor
14.以下程序运行的结果为。
#include<iostream.h>
Class B
{
public:
B(){};
B(int i , int j);
void Printb ();
private:
int a,b;
};
classA
{
public:
A(){};
A(int i,int j);
void printa();
private:
B C;
};
A::A(int i,int D):c(i,j)
{ };
void A::printa()
{
c.printb();
}
B::B(int i,int j)
{
a=i;b=j;
}
void B:: printb()
{
cout <<”a=” <<a<<”,b=” <<b <<endl;
}
void main()
{
A m(7’8);
m.printa();
}
