学生成绩管理系统: 统计成绩排序并打印(c++)(内含读取文件.txt及将文件输出excel的方法)
实验要求:输入30个学生的学号、姓名和5门课程的成绩,计算总分并按照总分排出名次,最后按照学号顺序打印成绩单, 并把成绩单输出为excel文件。
txt数据:
2015020981 甲 90 89 99 88 79
2015020986 戌 97 87 97 60 79
2015020970 鹏 97 88 77 80 79
2015020983 丙 92 89 70 88 79
2015020984 丁 93 84 96 36 77
2015020982 乙 61 88 99 84 70
2015020985 戊 94 81 94 82 75
2015020989 三 93 89 99 88 50
2015020994 八 91 88 49 84 70
2015020987 一 99 89 99 88 60
2015020988 二 91 58 69 84 70
2015020969 将 94 51 94 82 75
2015020960 孙 91 88 99 84 99
2015020990 四 93 84 96 86 77
2015020995 九 92 50 99 88 79
2015020992 六 97 87 97 80 79
2015020993 七 90 69 99 88 79
2015020997 张 74 81 54 82 75
2015020996 十 63 84 96 86 77
2015020965 郑 90 88 99 88 79
2015020998 王 97 87 100 80 79
2015020999 李 40 89 99 88 79
2015020963 刘 94 89 94 82 75
2015020961 赵 92 89 99 88 79
2015020962 岳 93 84 96 86 100
2015020966 林 51 88 99 84 70
2015020964 宋 97 87 47 80 79
2015020968 宗 93 84 96 86 57
2015020967 任 92 89 99 70 79
2015020991 五 94 81 44 82 75
源代码:
#include<iostream>
#include<cstdio>
#include<fstream>
#include<string>
#include<algorithm>
using namespace std;
struct Student
{
int id;
string name;
int score[5];
int total;
int rank;
public:
friend ostream & operator<<(ostream & out, const Student &stu);
friend istream & operator>>(istream & in, Student &stu);
};
ostream & operator <<(ostream & out, const Student &stu)
{
out << stu.id<<"\t"<<stu.name << "\t" << stu.score[0]<<"\t"<< stu.score[1]
<<"\t" << stu.score[2]<<"\t"<< stu.score[3]<<"\t" << stu.score[4] <<"\t"
<<stu.total<<"\t"<<stu.rank<<endl ;
return out;
}
istream & operator >>(istream & in, Student &stu)
{
in>>stu.id>>stu.name >> stu.score[0]>> stu.score[1]>> stu.score[2]
>> stu.score[3] >>stu.score[4];
return in;
}
int main()
{
string filename1;
int num = 0;
Student stu[100];
int ReadTextFile(string fname, Student stu[]);//从文件中读取TXT数据
void PrintScreen(Student stu[], int n);//打印数据在屏幕中
void Total(Student stu[],int n);//计算总分
void Rank(Student stu[], int n);//计算排名
void Sort(Student stu[], int n);//按学号排序
void WExcel(Student stu[], int n);//在Excel中输出
filename1 = "c:\\score.txt";
num=ReadTextFile(filename1, stu);
Total(stu,num);
Rank(stu, num);
Sort(stu, num);
WExcel(stu, num);
PrintScreen(stu, num);
}
//从文件中读取TXT数据
int ReadTextFile(string fname, Student stu[])
{
int i = 0;
ifstream fin(fname);
if (!fin)
{
cout << "source text file error\n";
return 0;
}
fin >> stu[i];
while (!fin.eof())
{
i++;
fin >> stu[i];
}
fin.close();
return i;
}
//打印数据在屏幕中
void PrintScreen(Student stu[], int n)
{
for (int i = 0; i <n; i++)
cout << stu[i];
}
void Total(Student stu[],int n)
{
for (int i=0; i < n; i++)
{
stu[i].total= stu[i].score[0] + stu[i].score[1] + stu[i].score[2]
+ stu[i].score[3] + stu[i].score[4];
}
}
//计算总分
void Rank(Student stu[], int n)
{
int temp,i,j;
for ( i = 0; i < n; i++)
{
temp = 0;
{for (j = 0; j < n; j++)
if (stu[i].total<=stu[j].total)
temp++;
stu[i].rank = temp;
}
}
}
//按学号排序
void Sort(Student stu[],int n)
{
int i, j;
Student temp;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if (stu[i].id>stu[j].id)
{
temp = stu[i];
stu[i] = stu[j];
stu[j] = temp;
}
}
//在Excel中输出
void WExcel(Student stu[], int n)
{
ofstream oFile;
oFile.open("1.csv", ios::out | ios::trunc);
oFile << "学号"<<"," << "姓名" << "," << "成绩1" << "," << "成绩2"
<< ","<<"成绩3"<<"," << "成绩4"<<" ,"<< "成绩5"<<","
<<"总分"<<","<<"排名"<<endl;
for (int i = 0; i < n; i++)
{
oFile << stu[i].id << "," << stu[i].name << "," << stu[i].score[0]
<< "," << stu[i].score[1]<< "," << stu[i].score[2] << ","
<< stu[i].score[3] << "," << stu[i].score[4]<<","<<stu[i].total
<<","<<stu[i].rank<<endl;
}
oFile.close();
}

学生成绩管理系统: 统计成绩排序并打印(c++)(内含读取文件.txt及将文件输出excel的方法)的更多相关文章
- 【转】 [C/OC的那点事儿]NSMutableArray排序的三种实现(依赖学生成绩管理系统).
原文网址:http://blog.csdn.net/ministarler/article/details/17018839 c语言实现的学生成绩管理系统是面向过程的,而OC实现的学生成绩管理系统则是 ...
- c++链表实现学生成绩管理系统(简易版)
#include<iostream> using namespace std; typedef struct student{ int id;//学号 string sex; string ...
- 学生成绩管理系统C(链表)语言
#include"stdio.h" #include"stdlib.h" #include"string.h" //用于调用一些函数 str ...
- 学生成绩管理系统[C]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...
- 使用C++名单在文档处理和学生成绩管理系统相结合
对于学生成绩管理系统,我并不陌生,几乎学习C人的语言.做项目会想到学生成绩管理系统,我也不例外.在研究中的一段时间C语言之后,还用C语言到学生管理系统,然后做几个链接.计数,这个系统是以前的系统上的改 ...
- 【学生成绩管理系统】 大二c语言作业
几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...
- [项目记录] 用c语言完成的一个学生成绩管理系统
一.要求: 学生成绩管理系统 某班有最多不超过30人(具体人数由键盘输入)参加期末考试,最多不超过6门(具体门数由键盘输入).使用链表编程实现如下菜单驱动的学生成绩管理系统. 从文件读入每个学生个人信 ...
- 学生成绩管理系统C++
今天晚上终于做完了学生成绩管理系统!激动!开心!!!哈哈哈~~~~ 总共298行代码,第一次写这么多. 其中遇到了好多困难,也烦恼了好久,不过最终都解决了! 做了之后果然,满满的成就感!抑制不住的兴奋 ...
- C语言项目:学生成绩管理系统
C语言项目:学生成绩管理系统 1.数据结构:学生信息:学号.姓名.年龄.性别.3课成绩 2.功能: (1)增加学生记录 (2) 删除学生记录 (3) 查找学生信息(学号 ...
随机推荐
- PyQt(Python+Qt)学习随笔:Qt Designer中部件的geometry几何属性
geometry属性保存部件相对于其父级对象的位置和大小,Qt实际上是以一个长方形来表示部件的位置和大小的,包括左上角的坐标位置.长度和宽带. 当部件的geometry调整时,部件如果可见将立即接收m ...
- Springboot集成xxl-Job
一.前言 xxl-job一个轻量级的分布的调度中间件,详情介绍自己到官网看:https://www.xuxueli.com/xxl-job/ 二.客户端(执行器) 引入依赖compile group: ...
- 如何在苹果电脑上创建一个html格式文件,并在浏览器正确打开
之前一直使用windows系统的电脑,创建文件很简单,改格式也非常的简单.但换了苹果电脑,如何创建一个HTML文件?却把我给整蒙了. 首先,为什么mac上不能直接新建文本文件? 因为mac一都是以应用 ...
- 矩阵乘法优化DP复习
前言 最近做毒瘤做多了--联赛难度的东西也该复习复习了. Warning:本文较长,难度分界线在"中场休息"部分,如果只想看普及难度的可以从第五部分直接到注意事项qwq 文中用(比 ...
- 题解-Railgun
题面 Railgun \(T\) 组测试数据,每次给定 \(n,k\),求(\(F(i)\) 为斐波那契数列第 \(i\) 项): \[\sum_{1\le x_i\le n(1\le i\le k) ...
- 安卓11配置谷歌FCM推送报错
2020-12-11 11:57:50.872 15404-15464/com.sp.notify E/FirebaseInstanceId: Failed to get FIS auth token ...
- mysql扩展百分位函数(类似SUM)
mysql扩展百分位函数(类似SUM) 参考:https://my.oschina.net/waterbear/blog/1186744 百度搜索:mysql percentile
- vue2中$emit $on $off实现组件之间的联动,绝对有你想了解的
在vue2开发中,你肯定会遇到组件之间联动的问题,现在我们就来说说哪个神奇的指令可以满足我们的需求. 一.先上实例: 需求:点击A组件或者B组件可以使C组件的名称相应发生改变,同样,点击A组件也会使对 ...
- 【Azure Developer】通过Azure提供的Azue Java JDK 查询虚拟机的CPU使用率和内存使用率
问题描述 在Azure上创建虚拟机(VM)后,在门户上可以查看监控指标(Metrics),如CPU Usage,Memory,Disk I/O等.那如何通过Java 代码获取到这些指标呢? 关于VM ...
- Day5 - 05 函数的参数-关键字参数
可变参数可以传入任意个参数,并在函数调用时自动组为一个tuple,而关键字参数允许传入任意个携带参数名的参数,这些关键字参数在函数内部自动组为一个dict. >>> ...