?? 學生排行.txt
字號:
#include<iostream>
using namespace std;
class student
{
public:
friend class students;
private:
int id,mark;
};
class students
{
public:
void input(int n,int j,int k);
void rebuild(int n);
private:
student a[1000];
int tempmark;
int tempid;
student b[1000];
};
void students::rebuild(int n)
{
for(int z=0;z<n;z++)
{
b[z].id=a[z].id;
b[z].mark=a[z].mark;
}
for(int g=0;g<n;g++)
{
for(int i=0;i<n;i++)
{
if (a[i].mark<a[i+1].mark)
{tempmark=a[i].mark;
a[i].mark=a[i+1].mark;
a[i+1].mark=tempmark;
tempid=a[i].id;
a[i].id=a[i+1].id;
a[i+1].id=tempid;
}
}
}
cout<<"學生原始記錄為:"<<endl;
for(int k=0;k<n;k++)
{
cout<<"學號: "<<b[k].id<<" 成績: "<<b[k].mark<<endl;
}
cout<<"學生排序后記錄為:"<<endl;
for(int h=0;h<n;h++)
{
cout<<"學號: "<<a[h].id<<" 成績: "<<a[h].mark<<endl;
}
}
void students::input(int n,int j,int k)
{
a[n].id=j;
a[n].mark=k;
}
int main()
{
int n;
cout<<"輸入班上學生的人數:";
cin>>n;
students table;
struct
{
int mark;
int id;
} d[1000];
for(int e=0;e<n;e++)
{
cout<<"輸入第"<<e+1<<"個學生的學號:";
cin>>d[e].id;
cout<<"輸入成績:";
cin>>d[e].mark;
int x=d[e].id;int y=d[e].mark;
table.input(e,x,y);
}
table.rebuild(n);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -