万分火急的求教,会的进C++简单运行结果题
1、 写出下列程序的结果#include <iostream.h>
Class Myclass
{
Public:
Myclass(int a){x=a;}
Void fun1(){x++;}
Void fun2(){x+=2;}
Void fun3(){x+=3;}
Void print(){cout<<”x=”<<x<<endl;}
Private:
Int x;
};
Void main()
{
Myclass my(8);
Void(Myclass::*pf)();
my.print();
pf=Myclass::fun2;
(my.*pf)();
my.print();
pf=Myclass::fun3;
(my.*pf)();
my.print();
}
运行结果为:
2、写出下列程序的运行结果。
#include<iostream.h>
int Div(int x,int y)
{
if(y= =0)
throw y;
retrun x/y;
}
viod main()
{
try
{
cout<<"7/3="<<Div(7,3)<<endl;
cout<<"9/0="<<Div(9,0)<<endl;
cout<<"8/4=""<<Div(8,4)<<endl;
}
catch(int)
{
cout<<"Exception of dividing zero. "<<endl;
}
cout<<"It is OK."<<endl;
}
运行结果为: