/*
*Copyright (c) 2014, 烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作者:于凯
*完成日期:2014年 11 月 27日
*版本号:v1.0
*
*问题描述:
*/
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int num=8;
int main()
{
int i,j,t;
string temp;
string name[num]= {"zhao","qian","sun","li","zhou","wu","zheng","wang"};
double score[num]= {79,84,65,89,60,92,78,56};
for(i=0; i<=7; i++)
for(j=0; j<=6-i; j++)
if(score[j]<score[j+1])
{
t=score[j];
score[j]=score[j+1];
score[j+1]=t;
temp=name[j];
name[j]=name[j+1];
name[j+1]=temp;
}
cout<<"按成绩排序后同学的名单:"<<endl;
cout<<"姓名:";
for(i=0; i<=7; i++)
cout<<setw(8)<<name[i];
cout<<endl;
cout<<"成绩";
for(i=0; i<=7; i++)
cout<<setw(8)<<score[i];
cout<<endl;
for(i=0; i<=7; i++)
for(j=0; j<=6-i; j++)
if(name[j]<name[j+1])
{
t=score[j];
score[j]=score[j+1];
score[j+1]=t;
temp=name[j];
name[j]=name[j+1];
name[j+1]=temp;
}
cout<<"按姓名排序后同学的名单:"<<endl;
cout<<"姓名:";
for(i=0; i<=7; i++)
cout<<setw(8)<<name[i];
cout<<endl;
cout<<"成绩";
for(i=0; i<=7; i++)
cout<<setw(8)<<score[i];
cout<<endl;
return 0;
}
运行结果: