第二周上机任务1

/*  
* Copyright (c) 2013, 烟台大学计算机学院                      
* All rights reserved.                      
* 文件名称:test.cpp                      
* 作者:孙永                     
* 完成日期:2013 年3月9日                      
* 版本号:v1.0                    
*                      
* 输入描述:已经在程序中初始化                    
* 问题描述:将学生成绩储存在结构体是组中,对结构体排序输出                 
* 程序输出: 
* 问题分析:                     
* 算法设计:略                      
*/           
#include<iostream>   
using namespace std;  
struct Score{  
    char num[14];  
    int cpp;  
    int math;  
    int english;  
};  
void sort1(Score [],int ); //要自定义函数 
void sort2(Score [],int );  
void output(Score [],int );  
int main(){  
    Score score[]={{"201152501104",65,69,68},  
    {"201152501114",94,89,63},  
    {"201152501138",67,62,84},  
    {"201152501204",100,65,91},  
    {"201152501202",59,80,55},  
    {"201152501115",92,84,60},  
    {"201152501201",80,92,71},  
    {"201152501145",88,56,67},  
    {"201152501203",62,62,95},  
    {"201152501140",80,60,86},  
    {"201152501205",73,90,94},  
    };  
    int stuNum=sizeof(score)/sizeof(score[0]); 
	sort1(score,stuNum);  
    cout<<"按C++降序排列后:"<<endl;  
    output(score,stuNum);  
    //将所有同学按学号升序排序后输出   
    sort2(score,stuNum);  
    cout<<"按学号升序后排列为:"<<endl;  
    output(score,stuNum);  
   
    return 0;  
}  
void sort1(Score score[],int ){  
    struct Score a[1];  
    int i,j;  
    for(i=0;i<=10;i++)  
    {  
        for(j=0;j<10;j++)  
            if(score[j].cpp<score[j+1].cpp)  
            {  
               a[0]=score[j];  
                score[j]=score[j+1];  
                score[j+1]=a[0];  
            }  
    }  
    return ;  
}  
void sort2(Score score[],int ){  
    struct Score a[1];  
    int i,j;  
    for(i=0;i<=10;i++)  
    {  
        for(j=0;j<10;j++)  
            if(strcmp(score[j].num,score[j+1].num)>0)  
            {  
                a[0]=score[j];  
                score[j]=score[j+1];  
                score[j+1]=a[0];  
            }  
    }  
    return ;  
}  
void output(Score score[],int )  
{  
    int i;  
    for(i=0;i<=10;i++){  
        cout<<score[i].num<<" "<<score[i].cpp<<" "<<score[i].math<<" "<<score[i].english<<endl;  
    }  
    return ;  
}  


心得体会:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值