全國2011年10月高等教育自學(xué)考試C++程序設(shè)計試題_第4頁
三、改錯題(本大題共5小題,每小題4分,共20分)
下面的每題中有一處錯誤,請用下橫線標(biāo)出錯誤所在行并給出修改意見
41. #include < iostream. h >
void main( ){
float * p;
p = new float[ 5 ] ;
for( i =0;i <5 ;i + + )
{ cin > > * (p + i) ;cout << * (p + i) << endl; }
delete [ ] p;
}
42. #include < iostream.h >
template < class T >
class f{
private: T x,y;
public: void fl(T a,T b){x=a;y=b;}
T max(){retum(x>y)? x:y;}
};
void main( ){
f <int> a;
a. fl(3.5,3.8) ;
cout << a. max( ) << endl;
}
43. #include < iostream. h >
class test{
private: static int x; int y;
public: void testl ( int a, int b) { x = a; y = b; }
};
void main() {
test a;
a. testl (2,3) ;
}
44. #include < iostream, h >
class f{
private: float x, y;
public: void fl ( float a, float b) { x = a; y = b; }
f() {x=0;y=0;}
void move(float a,float b){x =x +a;y =y-b;}
void get ( ) { cout << x <<"<< y << endl; }
};
void main( ){
f *p,a;
a. f1(1.6,3.8) ;
p=&a;
p. get( ) ;
}
45. #include < iostream. h >
class point{
int x;
public: void init ( int a) { x = a; }
int getx( ){ return x;}
void setx ( int a) { x = a; }
};
void main( ){
point a;
a. init (20,30) ;
cout << a. getx( ) << endl;
}
責(zé)編:snrvge