沒東西可以抓
#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]編譯就不行 .......