有序的结构体数组四
来源:互联网 发布:免费手机小号软件 编辑:程序博客网 时间:2024/06/04 18:20
/* 烟台大学计算机学院 作者:任子仪 日期:2014年3月5日 问题描述: 样例输入: 样例输出: 问题分析:*/#include <iostream>#include <iomanip>#include <string.h>using namespace std;struct Student{ char num[13]; char name[10]; int cpp; int math; int english; int grade; double average;};void calculate(Student s[],int n);//按总分降序排序void output(Student [],int); //输出成绩单//输出优秀者:总分超 285,单科不低于 90void outputExcellent(Student [],int);int 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} };//用 sizeof 运算确定数组中元素个数 int stuNum=sizeof(stu)/sizeof(stu[0]);//计算总分和均分后输出 cout<<"下面是总分和均分:"<<endl; calculate(stu,stuNum); cout<<"优秀者名单:"<<endl; outputExcellent(stu,stuNum); return 0;}void calculate(Student s[],int n){ for(int i=0; i<n; i++) { s[i].grade=s[i].english+s[i].math+s[i].cpp; s[i].average=s[i].grade/3; } for(int i=0; i<n; i++) { cout.setf(ios::left); cout<<setw(15)<<s[i].num<<setw(15)<<s[i].name<<setw(8)<<s[i].grade<<setw(8)<<s[i].average<<endl; }}void outputExcellent(Student s[],int n){ for(int i=0;i<n;i++) { if(s[i].grade>285&&s[i].english>90&&s[i].cpp>90&&s[i].math>90) { cout.setf(ios::left); cout<<setw(15)<<s[i].num<<setw(15)<<s[i].name; cout<<setw(8)<<setw(8)<<s[i].cpp<<setw(8)<<s[i].math; cout<<setw(8)<<s[i].english<<setw(8)<<s[i].grade<<setw(8)<<s[i].average<<endl; } }}
示例图片:
0 0
- 有序的结构体数组四
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组、
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 有序的结构体数组
- 题目1214:丑数
- 从Linux内核代码中学习获得结构体成员偏移量的方法
- int main(int argc,char* argv[])详解
- 【struts】Unable to load configuration 相关仔细查看报错信息
- 函数strtol和strtok详解
- 有序的结构体数组四
- hdu2196 Computers 树形DP
- UIResponder类的介绍
- Unity3 游戏优化 - 缓存(重复利用)物体
- AOJ - 0005 GCD and LCM (O(logn)求最大公约数,最小公倍数)
- Path Sum
- 解决nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
- Github for windows 安装教程(历尽千辛终于可以安装了)
- 通过web安装iOS app