学生信息
来源:互联网 发布:部门人员优化方案 编辑:程序博客网 时间:2024/05/01 21:34
建立一个结构体类型的学生信息数据库,学生信息包括姓名和四门课程(数学、计算机、英语、体育)成绩。要求调用函数完成学生信息的录入(输入),调用函数完成学生信息按总分从高到低的排序,调用函数完成排序后的学生信息输出。
提示:const int N=5;结构体类型数组有N个元素。
提示:const int N=5;结构体类型数组有N个元素。
#include <iostream>#include <string>using namespace std;struct student{string name;int score[4];};int main(){const int n=5;student stu[n];void input(student [],int );void sore(student [],int);void print(student [],int );input(stu,n);sore(stu,n);print(stu,n);return 0;}void input(student stu[],int n){ int i,j;for(i=0;i<n;i++){cin>>stu[i].name;for(j=0;j<4;j++)cin>>stu[i].score[j];}}void sore(student stu[],int n){ int sum[4],i,j,t; student temp; for(i=0;i<n;i++) { sum[i]=0; for(j=0;j<4;j++) sum[i]=sum[i]+stu[i].score[j]; } for(i=0;i<n-1;i++) for(j=0;j<n-1-i;j++)if(sum[j]<sum[j+1]){ temp=stu[j];stu[j]=stu[j+1];stu[j+1]=temp; t=sum[j];sum[j]=sum[j+1];sum[j+1]=t;}}void print(student stu[],int n){ int i,j;for(i=0;i<n;i++){cout<<stu[i].name<<" ";for(j=0;j<4;j++)cout<<stu[i].score[j]<<" ";cout<<endl;}}
0 0
- 学生信息
- 学生信息
- 学生信息
- 学生信息
- 学生信息
- 学生信息
- 学生信息
- 学生信息
- 学生信息查询器
- 学生信息追踪分析
- 输入学生信息的!
- 学生的信息_h
- 学生信息统计表
- ios 学生的信息
- 学生信息 类 结构
- 学生的信息
- 更改学生信息表
- 5个学生信息
- Perl + XS 用c/c++方便的编写perl扩展
- 字符串个数统计 为什么统计结果错误
- hadoop连接eclipse,Ubuntu
- 服务器集群与负载均衡
- CC2530串口接收总结
- 学生信息
- 宏定义
- 【android自定义控件】TextView详解及自定义<一>
- 使用NamedParameterJdbcTemplate 通过BeanPropertyRowMapper 返回一个对象或List 集合
- php 二维数组快速排序算法
- 某超市商品销售情况
- C++中的new、operator new与placement new
- 统计单词个数
- Leetcode_interleaving-string