全國2009年10月自學考試C++程序設(shè)計試題_第4頁
三、改錯題(本大題共5小題,每小題4分,共20分)
下面的每個程序都有一處錯誤,請用下橫線標出錯誤所在行并給出修改意見。
41.#include
using namespace std;
int main ( ){
int num; max=10; num =1
while (num < max) num + + ;
cout <<″Num = ″<< num;
return 0;
}
42.#include
using namespace std;
class A {
void show ( ) {
cout<<″Hello!″;
}
};
int main ( ) {
A a;a. show ( );
return 0;
}
43.#include
using namespace std;
int main ( ) {
const int num = 20;
int scores[num];
for (int i=1;i<=num;i + +){
scores[i]=i;
}
return 0;
}
44.#include
using namespace std;
class CMax {
private:
int xx; int yy;
public:
CMax(int x,int y)
{ xx = x;yy = y ; }
void setValue(int x,int y)
{ xx = x;yy = y;}
int max( ){
return xx > yy? xx:yy;
}
};
void main( ){
CMax m( );
m.setValue(20,30);
cout <<″Max=″<}
45.#include
using namespace std;
class A{
public:
char name[255];
private:
char * getName( )
{ return name; }
};
class B:public A{
public:
B(char * n){
strcpy ( name,n);
}
};
void main( ){
B b(″Hello!″);
cout <<″Name:″<}
責編:admin