1、三 程序分析题阅读以下程序,写出其运行结果。1#include int a 10 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;int fun( int i );void main() int i ,s = 0;for( i = 0; i = 10 )throw i ;return ai ;2#include void f();class T public:T() cout class Bclass public:Bclass( int i, int j ) x = i; y = j; virtual int fun() return 0 ; protected:int x
2、, y ;class Iclass:public Bclass public :Iclass(int i, int j, int k):Bclass(i, j) z = k; int fun() return ( x + y + z ) / 3; private :int z ;void main() Iclass obj( 2, 4, 10 );Bclass p1 = obj;cout fun() class BASE public:virtual void getxy( int i,int j = 0 ) x = i; y = j; virtual void fun() = 0 ;prot
3、ected:int x , y; ;class A: public BASE public:void fun() cout getxy( 10 );pb - fun();pb = pb - getxy( 100, 20 );pb - fun();5. #include class BASE1 public:BASE1( int i ) cout class T public :T() a = 0; b = 0; c = 0; T( int i , int j , int k ) a = i; b =j ; c = k; void get( int j = b; k = c; T operato
4、r * ( T obj );private:int a , b , c;T T:operator * ( T obj ) T tempobj;tempobj.a = a * obj.a;tempobj.b = b * obj.b;tempobj.c = c * obj.c;return tempobj;void main() T obj1( 1,2,3 ), obj2( 5,5,5 ), obj3;int a , b , c;obj3 = obj1 * obj2;obj3.get( a, b, c );cout class vector public:vector() vector(int i
5、,int j) x = i ; y = j ; friend vector operator + ( vector v1, vector v2 ) vector tempvector ;tempvector.x = v1.x + v2.x ;tempvector.y = v1.y + v2.y ;return tempvector ;void display() cout struct data int n ;int score ; ;void main() data a3 = 1000,83,1005,70,1009,95 , *p = a ;cout score score score c
6、lass A public :int f1();int f2();void setx( int m ) x = m ; cout class T public :T( int x, int y ) a = x ; b = y ;cout class T public:T(int x) a=x; b+=x;static void display(T c) coutclass A public :A() a = 25 ; void printa() cout class A public:A( ) cout f( ); delete pB;14. class Myclasspublic:Mycla
7、ss(int a,int b,int c);void PrintNumber( );void PrintSum( );private:int A,B,C;static int Sum;#include int Myclass:Sum=10;Myclass:Myclass(int a,int b,int c) A=a; B=b; C=c;Sum+=A+B+C;void Myclass:PrintNumber() cout “Number=“A“,“B“,“Cendl;void Myclass:PrintSum( )cout“Sum=“Sumendl;void main( )Myclass M(3,7,10), N(14,9,1);M.PrintNumber( ); N.PrintNumber( );M.PrintSum( ); N.PrintSum( );