有序的结构体数组
来源:互联网 发布:windows radius 搭建 编辑:程序博客网 时间:2024/05/20 20:43
/** 程序的版权和版本声明部分:* Copyright (c) 2013.烟台大学计算机学院。* All rights reserved.* 文件名称:输入年月日,返回这一年的第几天* 作 者:冯冬影* 完成日期:2014 年 3月 8 日* 版 本 号:v1.0* 对任务及求解方法的描述部分:* 输入描述: 输入同学们的成绩:英语,高数,C++* 问题描述: 按照要求对这些数据排序* 程序输出: 按要求输出结果* 问题分析:*/#include <iostream>#include <string.h>using namespace std;struct Student{ char num[13]; char name[10]; int cpp; int math; int english; int grade; double score; double average;};void calculate(Student s[],int n); //计算总分和均分,数据在s数组中,共有n个元素void sort1(Student s[],int n); //按总分降序排序void sort2(Student s[],int n); //按学号升序排序void output(Student s[],int n); //输出成绩单void outputExcellent(Student [],int); //输出优秀者:总分超285,单科不低于90int main(){ Student stu[]= {{"201152501104","Tom",65,69 ,68 }, {"201152501114","Jeery",94 ,89 ,63 }, {"201152501138","Speike",67 ,62 ,84 }, {"201152501204","Tyke",100 ,95 ,91 }, {"201152501202","Tuffy",59 ,80 ,55 }, {"201152501115","Butch",100 ,99 ,89 }, {"201152501201","Lightning",95 ,92 ,99 }, {"201152501145","Topsy",88 ,56 ,67 }, {"201152501203","Droopy",62 ,62 ,95 }, {"201152501140","Drupa",80 ,60 ,86 }, {"201152501205","Buzz",73 ,90 ,94} }; int stuNum=sizeof(stu)/sizeof(stu[0]); //用sizeof运算确定数组中元素个数 //计算总分和均分后输出 calculate(stu,stuNum); cout<<"下面是成绩单:"<<endl; output(stu,stuNum); cout<<endl; cout<<"优秀者名单:"<<endl; outputExcellent(stu,stuNum); cout<<endl; //按总分降序排序后输出 sort1(stu,stuNum); cout<<"按总分降序排序后:"<<endl; output(stu,stuNum); cout<<endl; //按学号升序排序后输出 sort2(stu,stuNum); cout<<"按学号升序排序后:"<<endl; output(stu,stuNum); return 0;}void calculate(Student s[],int n) //计算总分和均分,数据在s数组中,共有n个元素{ for(int i=0; i<n; i++) { s[i].score=s[i].cpp+s[i].math+s[i].english; s[i].average=s[i].score/n; cout<<"学号"<<" "<<"总分"<<" "<<"均分"<<endl; cout<<s[i].num<<'\t'<<s[i].score<<'\t'<<s[i].average<<endl; }}void sort1(Student s[],int n) //按总分降序排序{ Student t; for(int i=0; i<n-1; i++) { for(int j=0; j<n-i-1; j++) if(s[j].score<s[j+1].score) { t=s[j]; s[j]=s[j+1]; s[j+1]=t; } }}void sort2(Student s[],int n) //按学号升序排序{ Student k; for(int i=0; i<n-1; i++) { for(int j=0; j<n-i-1; j++) if(strcmp(s[j].num,s[j+1].num)>0) { k=s[j]; s[j]=s[j+1]; s[j+1]=k; } }}void output(Student s[],int n) //输出成绩单{ for(int i=0; i<n; i++) { cout<<"姓名"<<'\t'<<"学号"<<'\t'<<"c++"<<'\t'<<"高数"<<'\t'<<"英语"<<'\t'<<"总分"<<'\t'<<"均分"<<endl; cout<<s[i].name<<'\t'<<s[i].num<<'\t'<<s[i].cpp<<'\t'<<s[i].math<<'\t'<<s[i].english<<'\t'<<s[i].score<<'\t'<<s[i].average<<endl; }}void outputExcellent(Student s[],int n) //输出优秀者:总分超285,单科不低于90{ for(int i=0; i<n; i++) { if(s[i].score>285&&(s[i].cpp>=90&&s[i].math>=90&&s[i].english>=90)) cout<<s[i].name<<'\t'; }}
0 0
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组、
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- MFC中使菜单栏按钮变灰
- 教师节
- 李彦宏:互联网金融无法阻挡 应加快审批相关牌照
- Eclipse for PHP安装和配置过程
- 用有限自动机实现正则表达式的匹配
- 有序的结构体数组
- 李彦宏:互联网金融无法阻挡 应加快审批相关牌照
- 算法杂货铺——分类算法之决策树(Decision tree)
- 教师节
- iOS项目内存优化
- Android
- 文本格式效率
- Pow(x, n)
- [LeetCode] 刷题笔记(一)