没东西可以抓
#include <iostream> using namespace std; struct person // 定义一个结构资料型态Student { char name[100][10]; char id[100][10]; int score[100][3]; }student; void main() { int number,i,j; int total=0; float average; int max; int min; int maxaddress=0; //记录该科目分数最高的人的阵列位置 int minaddress=0; //记录该科目分数最低的人的阵列位置 cout <<"Exercise 3"<<endl; cout <<"Class : 二子三A Name : 吴建锋 ID : D93232109 " << endl; cout <<"How many students in class: "; cin >> number; for( i=0 ; i<number; i++) { cout << "Name of student " << i+1 << ": ";//输入姓名 cin >> student.name[i]; cout << "Id of student "<< i+1 <<": "; //输入ID cin >> student.id[i]; for( j=0 ; j<3 ; j++) { cout << "Score " << j+1 << " of student "<< i+1 <<": "; //输入科目的成绩 cin >> student.score[i][j]; } } cout << "\nName\tID\tScore1\tScore2\tScore3\taverage\n"; //输出成绩表 for( i=0 ; i<number ; i++) { cout<<student.name[i]<<"\t"<<student.id[i]<<"\t"; for( j=0; j<3 ; j++) { cout<<student.score[i][j]<<"\t"; total+=student.score[i][j]; } average=total/3; total=0; cout<< average <<endl; } cout<<endl; for( j=0 ; j<3 ; j++) //比较科目的最高分,低分 { max = student.score[0][j]; min = student.score[0][j]; cout<<student.score[0][j]<<endl; maxaddress=0; minaddress=0; for( i=1 ; i<number ; i++) { if (student.score[i][j]>max) { maxaddress = i; max = student.score[i][j]; } if (student.score[i][j]<min) { minaddress = i; min = student.score[i][j]; } } cout <<"Course"<< j+1<< ":\n"; cout <<"Highest Score:"<<endl; //输出该科目的最高分 cout <<"Name: "<<student.name[maxaddress]<<"\t"; cout <<"Id: "<<student.id[maxaddress]<<"\t"; cout <<"Score: "<<student.score[maxaddress][j]<<endl; cout <<"Lowest Score:"<<endl; //输出该科目的最低分 cout <<"Name: "<<student.name[minaddress]<<"\t"; cout <<"Id: "<<student.id[minaddress]<<"\t"; cout <<"Score: "<<student.score[minaddress][j]<<endl; cout <<"Fail List:"<<endl; for( i=0 ; i<number ; i++) //印出该科不及格的人 { if(student.score[i][j]<60) { cout <<"Name: "<<student.name[i]<<"\t"; cout <<"Id: "<<student.id[i]<<"\t"; cout <<"Score: "<<student.score[i][j]<<endl; } } cout <<endl; } system("pause"); }
for( j=0 ; j<3 ;j++) //比较科目的最高分,低分 { for( i=0 ; i<n ; i++) { [color=crimson]big = small =student.score[i][j][0]; if(student.score[i+1][j][0]>big) max=i+1; if(student.score[i+1][j][0]<small) min=i+1;[/color] }
for( i=1 ; i<n ; i++) { if(student.score[i][j][0]>max) { maxaddress=i; max=student.score[i][j][0]; cout<<max<<endl; } if(student.score[i][j][0]<min) { minaddress=i; min=student.score[i][j][0]; cout<<min<<endl; }
下面是引用jianfengtw于2005-04-6 15:58发表的 : 再次请教唐大大如果我要把static char *name =new char[n]; char *id =new char[n]; int *score=new int[n][3][2]; float *average=new float[n]; .......
下面是引用jianfengtw于2005-04-6 17:34发表的 : static char (*name)[10] = new char[n][10];// 定义一个结构资料型态Student char (*id)[10] = new char[n][10]; int (*score)[3][2] = new int[n][3][2]; float *average = new float[n];那我要释放记忆体是不是只要下delete *name,*id..........照一维的阵列就会释放了因为我刚用delete (*name)[10],(*score)[3][2]编译就不行 .......