基于C++实现的学生管理系统

基于C++实现的学生管理系统

要求

该软件用于管理某高校的本科生、研究生2类人员信息,人员信息包括:编号、姓名、性别、专业、年级、班级、类别、高数、英语、C语言、课程综合、论文、总分等,具体功能包括:
① 添加功能:按人员类别,添加各类人员信息。
② 查询功能:按人员类别,提供多种组合查询方式,查询各类人员信息。
③ 删除功能:按人员类别,删除各类人员信息。
④ 显示功能:显示输出所有人员信息。
⑤ 修改功能:按学号进行学生信息的修改。

功能设计

在这里插入图片描述
在这里插入图片描述

结构体

class ungraduate //在读学生
{
public:
	string number;//学号
	string name;//名字
	char sex;//性别
	string speciality;//专业
	string grade;//年级
	string classes;//班级
	int type;
	int math;
	int english;
	int clanguage;
	int score;
	ungraduate(){}
	ungraduate(string num, string na, char s, string sp, string gr, string cl, int ty, int a, int b, int c, int d)
	{
		number = num;
		name = na;
		sex = s;
		speciality = sp;
		grade = gr;
		classes = cl;
		type = ty;
		math = a;
		english = b;
		clanguage = c;
		score = d;
	}
	bool operator<(ungraduate ob1)const
	{
		if (number < ob1.number)
			return true;
		else
			return false;
	}
	string getnumber() { return number; }
	string getname() { return name; }
	char getsex() { return sex; }
	string getspeciality() { return speciality; }
	string getgrade() { return grade; }
	string getclasses() { return classes; }
	int gettype() { return type; }
	int getmath() { return math; }
	int getenglish() { return english; }
	int getclanguage() { return clanguage; }
};
class graduated //研究生
{
public:
	string number;//学号
	string name;//名字
	char sex;//性别
	string speciality;//专业
	string grade;//年级
	string classes;//班级
	int type;
	int comprehensive;
	int thesis;
	int score;
	graduated(string num, string na, char s, string sp, string gr, string cl, int ty, int a, int b, int c)
	{
		number = num;
		name = na;
		sex = s;
		speciality = sp;
		grade = gr;
		classes = cl;
		type = ty;
		comprehensive = a;
		thesis = b;
		score = c;
	}
	bool operator<(graduated ob2)const
	{
		if (number < ob2.number)
			return true;
		else
			return false;
	}
	string getnumber() { return number; }
	string getname() { return name; }
	char getsex() { return sex; }
	string getspeciality() { return speciality; }
	string getgrade() { return grade; }
	string getclasses() { return classes; }
	int gettype() { return type; }
	int getmath() { return comprehensive; }
	int getenglish() { return thesis; }
};
class face //输出
{
protected:
	set<ungraduate> pe1;
	set<graduated> pe2;
public:
	face() { readfile(); }
	void display();
	void run();
	void output();
	void printone1(set<ungraduate>::iterator p);
	void printone2(set<graduated>::iterator p);
	void insert();
	void delet();
	void readfile();
	void open1();
	void open2();
	void search();
	void change();
	void save();
};

源代码

#include<string.h>
#include<fstream>
#include<set>
#include<iterator>
#include<algorithm>
#include<iostream>
using namespace std;
int choice;
class ungraduate
{
public:
	string number;//学号
	string name;//名字
	char sex;//性别
	string speciality;//专业
	string grade;//年级
	string classes;//班级
	int type;
	int math;
	int english;
	int clanguage;
	int score;
	ungraduate(){}
	ungraduate(string num, string na, char s, string sp, string gr, string cl, int ty, int a, int b, int c, int d)
	{
		number = num;
		name = na;
		sex = s;
		speciality = sp;
		grade = gr;
		classes = cl;
		type = ty;
		math = a;
		english = b;
		clanguage = c;
		score = d;
	}
	bool operator<(ungraduate ob1)const
	{
		if (number < ob1.number)
			return true;
		else
			return false;
	}
	string getnumber() { return number; }
	string getname() { return name; }
	char getsex() { return sex; }
	string getspeciality() { return speciality; }
	string getgrade() { return grade; }
	string getclasses() { return classes; }
	int gettype() { return type; }
	int getmath() { return math; }
	int getenglish() { return english; }
	int getclanguage() { return clanguage; }
};
class graduated
{
public:
	string number;//学号
	string name;//名字
	char sex;//性别
	string speciality;//专业
	string grade;//年级
	string classes;//班级
	int type;
	int comprehensive;
	int thesis;
	int score;
	graduated(string num, string na, char s, string sp, string gr, string cl, int ty, int a, int b, int c)
	{
		number = num;
		name = na;
		sex = s;
		speciality = sp;
		grade = gr;
		classes = cl;
		type = ty;
		comprehensive = a;
		thesis = b;
		score = c;
	}
	bool operator<(graduated ob2)const
	{
		if (number < ob2.number)
			return true;
		else
			return false;
	}
	string getnumber() { return number; }
	string getname() { return name; }
	char getsex() { return sex; }
	string getspeciality() { return speciality; }
	string getgrade() { return grade; }
	string getclasses() { return classes; }
	int gettype() { return type; }
	int getmath() { return comprehensive; }
	int getenglish() { return thesis; }
};
class face
{
protected:
	set<ungraduate> pe1;
	set<graduated> pe2;
public:
	face() { readfile(); }
	void display();
	void run();
	void output();
	void printone1(set<ungraduate>::iterator p);
	void printone2(set<graduated>::iterator p);
	void insert();
	void delet();
	void readfile();
	void open1();
	void open2();
	void search();
	void change();
	void save();
};
void face::display()
{
	system("cls");
	cout << "┏━━━━━━学生信息管理菜单━━━━━┓" << endl;
	cout << "┃               1-添加信息             ┃" << endl;
	cout << "┃               2-查询信息             ┃" << endl;
	cout << "┃               3-删除信息             ┃" << endl;
	cout << "┃               4-显示信息             ┃" << endl;
	cout << "┃               5-修改信息             ┃" << endl;
	cout << "┃               0-退    出             ┃" << endl;
	cout << "┗━━━━━━━━━━━━━━━━━━━┛" << endl;
}
void face::run()
{
	int choice1;
	do
	{
		display();
		cout << "Please input your choice:";
		cin >> choice1;
		switch (choice1)
		{
		case 0:break;
		case 1:insert(); system("pause"); break;
		case 2:search(); system("pause"); break;
		case 3: delet(); system("pause"); break;
		case 4:output(); system("pause"); break;
		case 5:change(); system("pause"); break;
		}
	} while (choice1);
	save();
}
void face::change()
{
	string number="";
	string what="";
	int math, english, clanguage, comprehensive, thesis, score;
	char sex;
	char content[20]="";
	cout << "Please enter the student number to be modified:";
	cin >> number;
	if (choice == 1)
	{
		ungraduate ob;
		set<ungraduate>::iterator p1 = pe1.begin();
		while (p1 != pe1.end())
		{
			if (p1->number == number)break;
			p1++;
		}
		if (p1 == pe1.end())cout << "No information about this person!" << endl;
		else
		{
			cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t高数\t英语\tC语言\t总分\n";
			cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
			printone1(p1);
			cout << "Please enter what you want to modify";
			cout << "(number,name,sex,speciality,grade,type,math,english,clanguage):" << endl;
			cin >> content;
			if (strcmp(content, "number") == 0)
			{
				cout << "Please input the number:";
				cin >> what;
				ungraduate ob(what, p1->name, p1->sex, p1->speciality, p1->grade, p1->classes, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "name") == 0)
			{
				cout << "Please input the name:";
				cin >> what;
				ungraduate ob(p1->number, what, p1->sex, p1->speciality, p1->grade, p1->classes, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "sex") == 0)
			{
				cout << "Please input the sex(m-女/f-男):";
				cin >> sex;
				ungraduate ob(p1->number, p1->name, sex, p1->speciality, p1->grade, p1->classes, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "speciality") == 0)
			{
				cout << "Please input the speciality:";
				cin >> what;
				ungraduate ob(p1->number, p1->name, p1->sex, what, p1->grade, p1->classes, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "grade") == 0)
			{
				cout << "Please input the grade:";
				cin >> what;
				ungraduate ob(p1->number, p1->name, p1->sex, p1->speciality, what, p1->classes, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "class") == 0)
			{
				cout << "Please input the class:";
				cin >> what;
				ungraduate ob(p1->number, p1->name, p1->sex, p1->speciality, p1->speciality , what, p1->type, p1->math, p1->english, p1->clanguage, p1->score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "math") == 0)
			{
				cout << "Please input the math mark:";
				cin >> math;
				score = math + p1->english + p1->clanguage;
				ungraduate ob(p1->number, p1->name, p1->sex, p1->speciality, p1->grade, p1->classes, p1->type, math, p1->english, p1->clanguage, score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;

			}
			if (strcmp(content, "english") == 0)
			{
				cout << "Please input the english mark:";
				cin >> english;
				score = p1->math + english + p1->clanguage;
				ungraduate ob(p1->number, p1->name, p1->sex, p1->speciality, p1->grade, p1->classes, p1->type, p1->math, english, p1->clanguage, score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "clanguage") == 0)
			{
				cout << "Please input the clanguage mark:";
				cin >> clanguage;
				score = p1->math + p1->english + clanguage;
				ungraduate ob(p1->number, p1->name, p1->sex, p1->speciality, p1->grade, p1->classes, p1->type, p1->math, p1->english, clanguage, score);
				pe1.erase(p1);
				pe1.insert(ob);
				cout << "Modified success !" << endl;
			}
			
		}
	}
	if (choice == 2)
	{
		set<graduated>::iterator p2 = pe2.begin();
		while (p2 != pe2.end())
		{
			if (p2->number == number)break;
			p2++;
		}
		if (p2 == pe2.end())cout << "No information about this person!" << endl;
		else
		{
			cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t课综\t论文\t总分\n";
			cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
			printone2(p2);
			cout << "Please enter what you want to modify";
			cout << "(number,name,sex,speciality,grade,class,type,comprehensive,thesis):" << endl;
			cin >> content;
			if (strcmp(content, "number") == 0)
			{
				cout << "Please input the number:";
				cin >> what;
				graduated ob(what, p2->name, p2->sex, p2->speciality, p2->grade, p2->classes, p2->type, p2->comprehensive, p2->thesis, p2->score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "name") == 0)
			{
				cout << "Please input the name:";
				cin >> what;
				graduated ob(p2->number, what, p2->sex, p2->speciality, p2->grade, p2->classes, p2->type, p2->comprehensive, p2->thesis, p2->score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "sex") == 0)
			{
				cout << "Please input the sex(m-女/f-男):";
				cin >> sex;
				graduated ob(p2->number, p2->name, sex, p2->speciality, p2->grade, p2->classes, p2->type, p2->comprehensive, p2->thesis, p2->score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "speciality") == 0)
			{
				cout << "Please input the speciality:";
				cin >> what;
				graduated ob(p2->number, p2->name, p2->sex, what, p2->grade, p2->classes, p2->type, p2->comprehensive, p2->thesis, p2->score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "grade") == 0)
			{
				cout << "Please input the grade:";
				cin >> what;
				graduated ob(p2->number, p2->name, p2->sex, p2->speciality, what, p2->classes, p2->type, p2->comprehensive, p2->thesis, p2->score);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "comprehensive") == 0)
			{
				cout << "Please input the comprehensive mark:";
				cin >> comprehensive;
				score = comprehensive + p2->thesis;
				graduated ob(p2->number, p2->name, p2->sex, p2->speciality, p2->grade, p2->classes, p2->type, comprehensive, p2->thesis, score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
			if (strcmp(content, "thesis") == 0)
			{
				cout << "Please input the thesis mark:";
				cin >> thesis;
				score = p2->comprehensive + thesis;
				graduated ob(p2->number, p2->name, p2->sex, p2->speciality, p2->grade, p2->classes, p2->type, p2->comprehensive, thesis, score);
				pe2.erase(p2);
				pe2.insert(ob);
				cout << "Modified success !" << endl;
			}
		}
	}
}
void face::search()
{
	string number;
	cout << "Please enter the number you want to query:" << endl;
	cin >> number;
	if (choice == 1)
	{
		set<ungraduate>::iterator p1 = pe1.begin();
		while (p1 != pe1.end())
		{
			if (p1->number == number)break;
			p1++;
		}
		if (p1 == pe1.end())cout << "No information about this person!" << endl;
		else
		{
			cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t高数\t英语\tC语言\t总分\n";
			cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
			printone1(p1);
		}
	}
	if (choice == 2)
	{
		set<graduated>::iterator p2 = pe2.begin();
		while (p2 != pe2.end())
		{
			if (p2->number == number)break;
			p2++;
		}
		if (p2 == pe2.end())cout << "No information about this person!" << endl;
		else
		{
			cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t课综\t论文\t总分\n";
			cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
			printone2(p2);
		}
	}
}
void face::insert()
{
	string number;
	string name;
	char sex;
	string speciality;
	string grade;
	string classes;
	int math, english, clanguage, thesis, comprehensive;
	int score, type;
	char ch = 'n';
	do
	{
		cout << "学号:";
		cin >> number;
		cout << "姓名:";
		cin >> name;
		cout << "性别(m-女/f-男):";
		cin >> sex;
		cout << "专业:";
		cin >> speciality;
		cout << "年级:";
		cin >> grade;
		cout << "班级:";
		cin >> classes;
		type = 1;
		if (choice == 1)
		{
			cout << "高数:";
			cin >> math;
			cout << "英语:";
			cin >> english;
			cout << "C语言:";
			cin >> clanguage;
			score = math + english + clanguage;
			ungraduate ob(number, name, sex, speciality, grade, classes, type, math, english, clanguage, score);
			pe1.insert(ob);
		}
		if (choice == 2)
		{
			cout << "课综:";
			cin >> comprehensive;
			cout << "论文:";
			cin >> thesis;
			score = comprehensive + thesis;
			graduated ob(number, name, sex, speciality, grade, classes, type, comprehensive, thesis, score);
			pe2.insert(ob);
		}
		cout << "Continue typing?(Y/N):";
		cin >> ch;
	} while (ch == 'Y' || ch == 'y');
}
void face::printone1(set <ungraduate>::iterator p)
{
	cout << p->number << "\t" << p->name << "\t";
	if (p->sex == 'm')
		cout << "女   ";
	else cout << "男   ";
	cout << p->speciality << "\t" << p->grade << "\t" << p->classes << "\t";
	cout << "本科生\t";
	cout << p->math << "\t" << p->english << "\t" << p->clanguage << "\t" << p->score << endl;
}
void face::printone2(set <graduated>::iterator p)
{
	cout << p->number << "\t" << p->name << "\t";
	if (p->sex == 'm')
		cout << "女   ";
	else cout << "男   ";
	cout << p->speciality << "\t" << p->grade << "\t" << p->classes << "\t";
	cout << "研究生\t";
	cout << p->comprehensive << "\t" << p->thesis << "\t" << p->score << endl;
}
void face::output()
{
	if (choice == 1)
	{
		cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t数学\t英语\tC语言\t总分\n";
		cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
		set<ungraduate>::iterator p1 = pe1.begin();
		while (p1 != pe1.end())
		{
			printone1(p1);
			p1++;
		}
	}
	if (choice == 2)
	{
		cout << "学号\t姓名\t性别\t专业\t年级\t班级\t类别\t课综\t论文\t总分\n";
		cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
		set<graduated>::iterator p2 = pe2.begin();
		while (p2 != pe2.end())
		{
			printone2(p2);
			p2++;
		}
	}
}
void face::delet()
{
	string number;
	cout << "Please enter the number you want to delete:";
	cin >> number;
	if (choice == 1)
	{
		set<ungraduate>::iterator p1 = pe1.begin();
		while (p1 != pe1.end())
		{
			if (p1->number == number)
			{
				pe1.erase(p1++);
				cout << "Successful deletion!" << endl;
			}
			else p1++;
		}
	}
	if (choice == 2)
	{
		set<graduated>::iterator p2 = pe2.begin();
		while (p2 != pe2.end())
		{
			if (p2->number == number)
			{
				pe2.erase(p2++);
				cout << "Successful deletion!" << endl;
			}
			else p2++;
		}
	}
	return;
}
void face::readfile()
{
	do
	{
		system("cls");
		cout << "┏━━━━━━学生信息管理系统━━━━━┓" << endl;
		cout << "┃              1-本科生管理            ┃" << endl;
		cout << "┃              2-研究生管理            ┃" << endl;
		cout << "┃              0-退      出            ┃" << endl;
		cout << "┗━━━━━━━━━━━━━━━━━━━┛" << endl;
		cout << "Please input your choice:";
		cin >> choice;
		while (choice != 1 && choice != 2 && choice != 0)
		{
			cout << "Input error, please re-enter:";
			cin >> choice;
		}
		switch (choice)
		{
		case 0:break;
		case 1:open1(); run(); system("pause"); break;
		case 2:open2(); run(); system("pause"); break;
		}
	} while (choice);
}
void face::open1()
{
	ifstream in("ungraduate.txt");
	if (!in)
	{
		cout << "Cannot open file!" << endl;
		return;
	}
	string number;
	string name;
	char sex;
	string speciality;
	string grade;
	string classes;
	int type, math, english, clanguage, score;
	set<ungraduate>::iterator p1 = pe1.begin();
	in >> number >> name >> sex >> speciality >> grade >> classes >> type >> math >> english >> clanguage >> score;
	do
	{
		ungraduate ob(number, name, sex, speciality, grade, classes, type, math, english, clanguage, score);
		pe1.insert(ob);
		in >> number >> name >> sex >> speciality >> grade >> classes >> type >> math >> english >> clanguage >> score;
	} while (!in.eof());
	in.close();
	return;
}
void face::open2()
{
	ifstream in("graduated.txt");
	if (!in)
	{
		cout << "Cannot open file!" << endl;
		return;
	}
	string number;
	string name;
	char sex;
	string speciality;
	string grade;
	string classes;
	int type, comprehensive, thesis, score;
	set<graduated>::iterator p = pe2.begin();
	in >> number >> name >> sex >> speciality >> grade >> classes >> type >> comprehensive >> thesis >> score;
	do
	{
		graduated ob(number, name, sex, speciality, grade, classes, type, comprehensive, thesis, score);
		pe2.insert(ob);
		in >> number >> name >> sex >> speciality >> grade >> classes >> type >> comprehensive >> thesis >> score;
	} while (!in.eof());
	in.close();
	return;
}
void face::save()
{
	if (choice == 1)
	{
		ofstream out1("ungraduate.txt");
		if (!out1)
		{
			cout << "Cannot open file!" << endl;
			return;
		}
		set<ungraduate>::iterator p1 = pe1.begin();
		while (p1 != pe1.end())
		{
			out1 << p1->number << " " << p1->name << " " << p1->sex << " " << p1->speciality << " "
				<< p1->grade << " " << p1->classes << " " << p1->type << " "
				<< p1->math << " " << p1->english << " " << p1->clanguage << " " << p1->score << endl;
			p1++;
		}
		out1.close();
	}
	if (choice == 2)
	{
		ofstream out2("graduated.txt");
		if (!out2)
		{
			cout << "Cannot open file!" << endl;
			return;
		}
		set<graduated>::iterator p2 = pe2.begin();
		while (p2 != pe2.end())
		{
			out2 << p2->number << " " << p2->name << " " << p2->sex << " " << p2->speciality << " "
				<< p2->grade << " " << p2->classes << " " << p2->type << " "
				<< p2->comprehensive << " " << p2->thesis << " " << p2->score << endl;
			p2++;
		}
		out2.close();
	}
	return;
}
int main()
{
	face inter;
	system("pause");
	return 0;
}

实现截图

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值