第十五周项目3-带姓名的成绩单

  1. /* 
  2.  * Copyright (c) 2013, 烟台大学计算机学院 
  3. * All rights reserved. 
  4. * 作    者:王英华 
  5. * 完成日期:2013 年 12 月 6日 
  6. * 版 本 号:v1.0 
  7. * 
  8. * 输入描述: 无 
  9. * 问题描述:带姓名的成绩单 
  10. * 程序输出:略 
  11. * 问题分析:略 
  12. * 算法设计:略 
  13. */  
  14. #include <iostream>
    
    #include<string>
    
    using namespace std;
    
    int main()
    {
        int i,j,t;
        string s;
        double score[20]= {20,30,40,50,60,70,80,90,88,66};
        string name[20]= {"zhao","wang2","shi","ji","wang","shen","liu","ma","sun","xu"};
        for(i=0; i<10; i++)
        {
            for(j=0; j<10-i; j++)
            {
                if(score[i]<score[i+1])
                {
                    t=score[i];
                    score[i]=score[i+1];
                    score[i+1]=t;
                    s=name[i];
                    name[i]=name[i+1];
                    name[i+1]=s;
                }
    
    
            }
    
        }
        cout<<"按成绩排序为:"<<endl;
        for(i=0; i<10; i++)
            cout<<name[i]<<'\t'<<score[i]<<endl;
        for(j=0; j<10; j++)
            for(i=0; i<10-j; i++)
            {
                if(name[i]<name[i+1])
                {
                    s=name[i];
                    name[i]=name[i+1];
                    name[i+1]=s;
                    t=score[i];
                    score[i]=score[i+1];
                    score[i+1]=t;
                }
            }
        cout<<"按姓名排序为:"<<endl;
        for(i=0; i<10; i++)
            cout<<name[i]<<"\t"<<score[i]<<endl;
    
    
    }
    

    运行结果:

你可能感兴趣的:(第十五周项目3-带姓名的成绩单)