全國(guó)2009年10月自學(xué)考試C++程序設(shè)計(jì)試題_第6頁(yè)
48.將下面程序補(bǔ)充完整,使程序可以輸入學(xué)生信息并計(jì)算平均成績(jī)。
#include
#include
using namespace std;
class Student{
private:
char name[255];
int score[10];
public:
Student(char n[ ],int s[ ]){
___________;
for(int i=0;i<10;i++){
score[i]=s[i];
}
}
void Show( ){
int sum=0;
for(int i=0;i<10;i++){
_______________;
}
cout<<″名字:″< < name<<″,平均成績(jī):″<}
};
void main( ){
char name[255];
int score[10];
cout<<″姓名:″;cin>>name;
for(int i=0;i<10;i++){
cout<<″成績(jī)″<cin>>score[i];
}
Student s(name,score);
s.Show( );
}
49.將下面程序補(bǔ)充完整,使程序可以正常運(yùn)行,并釋放內(nèi)存。
#include
_______
class A {
private:
T * data;
int length;
public:
A (int len){
length=len;
data=new T[len];
}
~A( ){
_________
}
T& operator[](int i){
return data[i];
}
};
int main( ){
A obj(2);
obj[0]=1;
obj[1]=2;
cout<cout<return 0;
}
責(zé)編:admin