#include
#include

using namespace std;
using std::setw;
int main()
{
int id[10]={1,2,3,4,5,6,7,8,9,10};
int chinese[10]={64,95,80,64,90,76,88,75,81,90};
int english[10]={55,60,67,50,75,66,32,58,60,81};
int math[10]={40,68,53,51,48,77,84,57,80,45};

int type;
int tempid;
int tempc;
int tempe;
int tempm;
while(1)
{
cout << "-1: 結束 " << endl;
cout << "0: 列印 " << endl;
cout << "1: 搜尋 " << endl;
cout << "2: 由小到大排序 " << endl;
cout << "3: 由大到小排序 " << endl;
cin >> type;

switch(type)
{
case -1:
return 0;
break;
case 0:
cout << " id " << setw(10) << " chinese " << setw(10) << "english " << setw(10) << "math " << endl;
for(int i=0;i<=9;i++)
{
cout << setw(10) << i << setw(10) << chinese[i] << setw(10) << english[i] << setw(10) << math[i] << endl;

}
break;
case 1:
int x;
cout << "請輸入學生號碼 0-9 : " << endl;
cin >> x;
cout << "中文成績:" << chinese[x] << "英文成績:" << english[x] << "數學成績:" << math[x] << endl;


break;
case 2:


for(int i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{
if(english[i]>english[j])
{
tempid=id[i];
id[i]=id[j];
id[j]=tempid;

tempc=chinese[i];
chinese[i]=chinese[j];
chinese[j]=tempc;

tempe=english[i];
english[i]=english[j];
english[j]=tempe;

tempm=math[i];
math[i]=math[j];
math[j]=tempm;



}
}
}
cout<<"id"<<" " << "chinese" << " "<< "english" << " "<< "math" << endl;
for(int i=0;i<10;i++)
cout <
break;
case 3:
for(int i=0;i<10;i++)
{
for(int j=i+1;j<10;j++)
{
if(english[i] {
tempid=id[i];
id[i]=id[j];
id[j]=tempid;

tempc=chinese[i];
chinese[i]=chinese[j];
chinese[j]=tempc;

tempe=english[i];
english[i]=english[j];
english[j]=tempe;

tempm=math[i];
math[i]=math[j];
math[j]=tempm;



}
}
}
cout<<"id"<<" " << "chinese" << " "<< "english" << " "<< "math" << endl;
for(int i=0;i<10;i++)
cout <
break;
default:
cout << "輸入錯誤!!" << endl;
}
}



system("PAUSE");
return 0;

}
創作者介紹
創作者 微醺 的頭像
noteheaven

微醺

noteheaven 發表在 痞客邦 留言(0) 人氣( 1 )