- 最後登錄
- 2024-4-29
- 在線時間
- 344 小時
- 註冊時間
- 2008-11-25
- 閱讀權限
- 30
- 精華
- 0
- UID
- 5370941
- 帖子
- 247
- 積分
- 3811 點
- 潛水值
- 35071 米
| - #include "stdafx.h"
- #include "conio.h"
- #include "iostream"
- #include "string"
- using namespace std;
- void main()
- {
- struct grade
- {
- string Name,ss;
- float Chinese;
- float English;
- float Mathtic;
- float Sum;
- float Average;
- };
- int student_1,i,j;
- grade Average_1,temp_grade;
- cout<<"輸入學生人數:";
- cin>>student_1;
- cout<<endl;
- grade *student=new grade[student_1];
- for(i=0;i<student_1;i++)
- {
- cout<<"請輸入第"<<i+1<<"位學生姓名:";
- cin>>student[i].Name;
- cout<<"請輸入第"<<i+1<<"位國文成績:";
- cin>>student[i].Chinese;
- cout<<"請輸入第"<<i+1<<"位英文成績:";
- cin>>student[i].English;
- cout<<"請輸入第"<<i+1<<"位數學成績:";
- cin>>student[i].Mathtic;
- cout<<endl;
- }
- for(i=0;i<student_1;i++)
- {
- student[i].Sum=student[i].Chinese+student[i].English+student[i].Mathtic;
- student[i].Average=student[i].Sum/3;
- cout<<"第"<<i+1<<"位\t"<<student[i].Name<<"學生總分"<<student[i].Sum<<"\t平均分數"<<student[i].Average<<endl;
- }
- cout<<endl;
- Average_1.Chinese=0;
- Average_1.English=0;
- Average_1.Mathtic=0;
- for(i=0;i<student_1;i++)
- {
- Average_1.Chinese=(Average_1.Chinese+student[i].Chinese);
- Average_1.English=(Average_1.English+student[i].English);
- Average_1.Mathtic=(Average_1.Mathtic+student[i].Mathtic);
- }
- Average_1.Chinese=Average_1.Chinese/student_1;
- Average_1.English=Average_1.English/student_1;
- Average_1.Mathtic=Average_1.Mathtic/student_1;
- cout<<"國文平均成績:"<<Average_1.Chinese<<endl;
- cout<<"英文平均成績:"<<Average_1.English<<endl;
- cout<<"數學平均成績:"<<Average_1.Mathtic<<endl;
- cout<<endl;
- for(i=0;i<student_1;i++)
- {
- for(j=i+1;j<student_1;j++)
- {
- if(student[j].Average>student[i].Average)
- {
- temp_grade=student[i];
- student[i]=student[j];
- student[j]=temp_grade;
- }
- }
- }
- cout<<"成績排名"<<endl;
- for(i=0;i<student_1;i++)
- {
- cout<<"第"<<i+1<<"名 "<<"\t學生姓名"<<student[i].Name<<"\t平均成績:"<<student[i].Average<<endl;
- }
- system("pause");
- }
複製代碼
這是本來的程式,但是老師說沒交過struct,就堅持說是抄別人的。
求大大幫個忙 ... |
|