C++学生成绩管理系统
小白疼疼目前是大二狗,虽然是学软件工程的,但确实是正经的C++小白……最近应一妹子请求帮忙写了下她C++选修课作业,看到网上巨多此类代码,在此也就湊表脸的把我写的代码贴上来,写得不好不怕喷请大家多多指教~
需求描述
1.添加学生信息:增加学生,并将学生信息和成绩添加到文件student.txt。
2.修改学生信息;按学号调出学生信息和成绩,并做修改,修改后保存到student.txt。
3.删除学生信息; 按学号调出学生信息和成绩,并从student.txt删除该学生信息。
4.查询:1)按学号某个学生的成绩信息和学分信息;2)按课程查询某门课程的所有学生成绩。
5.统计:1)按课程统计不及格学生;2)排序,按课程将某门课的成绩排序;3)按所有课程的总分排序。
代码块
Student.h:
#pragma once
# include <iostream>
# include <fstream>
# include <string.h>
#include <conio.h>
using namespace std;
class Student
{
public:
Student();
~Student();
char name[20]; //名字
char id; //学号
int MathScore; //数学成绩
int EnglishScore; //英语成绩
int ComputerScore; //计算机成绩
int PEScore; //体育成绩
int PoliticScore; //政治成绩
int sum; //总分
Student *Next;
void Input(); //输入各种信息
void ReadFile(istream &in); //写入各种信息
void Show(); //显示各种信息
void Show_Math();
void Show_Eng();
void Show_Com();
void Show_PE();
void Show_Pol();
};
Student.cpp
#include "Student.h"
Student::Student()
{
}
Student::~Student()
{
}
void Student::Input()
{
cout << "请输入学生的姓名:"; cin >> name;
cout << "请输入学生的学号:"; cin >> id;
cout << "请输入数学课的成绩:"; cin >> MathScore;
cout << "请输入英语课的成绩:"; cin >> EnglishScore;
cout << "请输入计算机课的成绩:"; cin >> ComputerScore;
cout << "请输入体育课的成绩:"; cin >> PEScore;
cout << "请输入政治课的成绩:"; cin >> PoliticScore;
sum = MathScore + EnglishScore + ComputerScore + PEScore + PoliticScore;
}
void Student::ReadFile(istream & in)
{
in >> name >> id >> MathScore >> EnglishScore >> ComputerScore >> PEScore >> PoliticScore >> sum;
}
void Student::Show()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "数学:" << MathScore << endl
<< "英语:" << EnglishScore << endl
<< "计算机:" << ComputerScore << endl
<< "体育:" << PEScore << endl
<< "政治:" << PoliticScore << endl
<< "总分:" << sum << endl
<< endl;
}
void Student::Show_Math()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "数学:" << MathScore << endl
<< endl;
}
void Student::Show_Eng()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "英语:" << EnglishScore << endl
<< endl;
}
void Student::Show_Com()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "计算机:" << ComputerScore << endl
<< endl;
}
void Student::Show_PE()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "体育:" << PEScore << endl
<< endl;
}
void Student::Show_Pol()
{
cout << "姓名:" << name << endl
<< "学号:" << id << endl
<< "政治:" << PoliticScore << endl
<< endl;
}
Studentmassage.h
#pragma once
# include <iostream>
# include <fstream>
# include <string.h>
#include <conio.h>
#include<sstream>
#include"Student.h"
#include"Course.h"
using namespace std;
class Studentmassage
{
public:
Studentmassage();
~Studentmassage();
void Display(); //显示信息
void Display_Math(); //显示数学成绩信息
void Display_Eng(); //显示英语成绩信息
void Display_Com(); //显示计算机成绩信息
void Display_PE(); //显示体育成绩信息
void Display_Pol(); //显示政治成绩信息
void AddItem(); //添加信息
void Save(); //保存当前数据
void ModifyItem(); //修改学生信息
void RemoveItem(); //删除学生信息
void Swap(Student *p1, Student *p2);//交换信息位置函数
int ListCount(); //统计当前链表记录数目并返回
void Sort(); //按总成绩排序
void Sort_Math();
void Sort_Eng();
void Sort_Com();
void Sort_PE();
void Sort_Pol();
void Main_Menu(); //主菜单
void Stu_Info_Menu(); //学生信息菜单
void Search_Menu(); //查询菜单
void Grade_Menu(); //课程选择菜单
void Sort_Menu(); //统计菜单
void SortbyGrade(); //按课程成绩排序选择菜单
void Find(); //按学号查找学生信息
void Find_fail(); //查找不及格学生
//void read(); //脑残出品…别管它…
private:
Student *Head, *End;
ifstream in;
ofstream out;
Student *FindId(char *id) {
for (Student * p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空
if (!p->Next->id, id)return p;
return NULL;
};
Student *FindItem(char *name) {
for (Student * p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空
if (!strcmp(p->Next->name, name))return p;
return NULL;
};
Student *FindFail() {
for (Student * p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空
if (p->sum < 300)return p;
return NULL;
}
};
Studentmassage.cpp
#include "Studentmassage.h"
Studentmassage::Studentmassage()
{
Head = new Student;
Head->Next = new Student;
End = Head->Next;
in.open("student.txt");
if (!in)
cout << "这是一个新系统,无学生信息。请先输入。" << endl;
else
{
while (!in.eof())
{
End->ReadFile(in);
if (End->name[0] == '\0')break;
End->Next = new Student;
End = End->Next;
}
in.close();
cout << "读取学生信息成功!" << endl;
}
}
Studentmassage::~Studentmassage()
{
Save();
for (Student * temp; Head->Next != End;)
{
temp = Head->Next;