主题:[讨论]、确定下面三个的执行程序段的执行结果 紧急需要谢谢
[1] class Person
{
public:
void Speak() const {cout<<
”Person Speak\n”;}
virtual void Run() const {cout<<
”Person Run\n”;}
};
class Man:public Person
{
public:
void Speak() const {cout<<
”Man Speak\n”;}
void Run() const {cout<<
”Man Run\n”;}
};
void Func(Person & obj)
{
obj.Speak();
obj.Run();
}
void main()
{
Person * pt1=new Person;
Person * pt2=new Man;
Man * pt3=new Man;
Func(*pt1);
Func(*pt2);
Func(*pt3);
delete pt1;
delete pt2;
delete pt3;
}
[2] class Test
{
public:
int x;
static int y;
Test(int data=0){x=data;}
~Test(){};
void function(){x++;y++}
};
int Test::y=0;
void main()
{
Test one;
Test two;
Test three;
one.function();
cout<<”x=”<<one.x<<”y=”
<<one.y<<endl;
two.function();
cout<<”x=”<<two.x<<”y=”
<<two.y<<endl;
three.function();
cout<<”x=”<<three.x<<”y=”
<<three.y<<endl;
}
[3] void main()
{
int x=5;
int * px=&x;
int & z=x;
int y=20;
x++;
(*px)++;
y++;
z++;
cout<<x<<” “<<y<<” ”
<<z<<” ”<<(*px)<<endl;
px=&y;
x--;
y--;
(*px)--;
z--;
cout<<x<<” “<<y<<” ”
<<z<<” ”<<(*px)<<endl;
}
{
public:
void Speak() const {cout<<
”Person Speak\n”;}
virtual void Run() const {cout<<
”Person Run\n”;}
};
class Man:public Person
{
public:
void Speak() const {cout<<
”Man Speak\n”;}
void Run() const {cout<<
”Man Run\n”;}
};
void Func(Person & obj)
{
obj.Speak();
obj.Run();
}
void main()
{
Person * pt1=new Person;
Person * pt2=new Man;
Man * pt3=new Man;
Func(*pt1);
Func(*pt2);
Func(*pt3);
delete pt1;
delete pt2;
delete pt3;
}
[2] class Test
{
public:
int x;
static int y;
Test(int data=0){x=data;}
~Test(){};
void function(){x++;y++}
};
int Test::y=0;
void main()
{
Test one;
Test two;
Test three;
one.function();
cout<<”x=”<<one.x<<”y=”
<<one.y<<endl;
two.function();
cout<<”x=”<<two.x<<”y=”
<<two.y<<endl;
three.function();
cout<<”x=”<<three.x<<”y=”
<<three.y<<endl;
}
[3] void main()
{
int x=5;
int * px=&x;
int & z=x;
int y=20;
x++;
(*px)++;
y++;
z++;
cout<<x<<” “<<y<<” ”
<<z<<” ”<<(*px)<<endl;
px=&y;
x--;
y--;
(*px)--;
z--;
cout<<x<<” “<<y<<” ”
<<z<<” ”<<(*px)<<endl;
}