c++ 学生管理系统(包含登录--管理员-教师-学生三种登录)

//包含五个.h文件

fream_name.h//包含文件宏定义

#pragma once
#define FILENAME1 "student.txt"
#define FILENAME2 "account.txt"

all.h//包含全部头文件

#pragma once
#include<iostream>
#include<fstream>
#include<conio.h>
#include<string>
using namespace std;

account.h//账号类定义

#pragma once
#include"all.h"
#include"fream_name.h"
class Account
{
public:
	Account(int ,string,int );
	void display();
	int account;//账号
	string password;//密码
	int id;//身份
};

student.h//学生类定义

#pragma once
#include"all.h"
#include"fream_name.h"
class Student
{
public:
	Student(int ,string ,string,string, int ,int );
	void display();
	int num;//学号
	string name;//姓名
	string grade;//年级
	string sex;//性别
	int age;//年龄
	int number;//电话号码
};

people.h//总的部分定义(包含各种操作)

#pragma once
#include"student.h"
#include"account.h"
class People_Manager
{
public:
	People_Manager();

	int Stu_Num;//学生人数
	Student **M_Student;//学生数组指针

	void stu_init();//初始化
	int stu_num();//初始化数量

	int Acc_Num;//账户人数
	Account **M_Account;//账户数组指针

	void acc_init();//初始化
	int acc_num();//初始化数量


	void account_save();//账户保存
	void stu_add();//添加学生
	void stu_sort();//排序学生
	void stu_del();//删除学生
	void stu_mod();//修改学生
	void stu_find();//查找学生
	void stu_save();//保存学生
	void stu_show();//显示学生
	void stu_oper();//学生操作
	void tea_oper();//教师操作
	void man_oper();//管理员操作
	int pass_au(string&);//密码验证  
};

//四个.cpp文件

account.cpp//对账户的部分操作

#include"account.h"
Account::Account(int m_account, string m_password,int m_id)
{
	account = m_account;
	password = m_password;
	id = m_id;
}
void Account::display()
{
	if (id == 1)
	{
		cout << "\t学生学号:" << account << endl;
		cout << "\t密码:" << password << endl;
	}
	else
		if (id == 2)
		{
			cout << "\t教师职工号:" << account << endl;
			cout << "\t密码:" << password << endl;
		}
		else
			if (id == 3)
			{
				cout << "\t管理员账号:" << account << endl;
				cout << "\t密码:" << password << endl;
			}
}

//student.cpp 部分学生类的操作

#include"student.h"

Student::Student(int m_num, string m_name, string m_grade, string m_sex, int m_age, int m_number)
{
	this->num = m_num;
	this->name = m_name;
	this->grade = m_grade;
	this->sex = m_sex;
	this->age = m_age;
	this->number = m_number;
}

void Student::display()
{
	cout << "学号:" << this->num << endl;
	cout << "姓名:" << this->name << endl;
	cout << "年级:" << this->grade << endl;
	cout << "性别:" << this->sex << endl;
	cout << "年龄:" << this->age << endl;
	cout << "电话号码:" << this->number << endl;
}

people.cpp//所有操作集中

#include"people.h"

People_Manager::People_Manager()
{
	fstream f;
	f.open(FILENAME1, ios::in);
	if (!f.is_open())
	{
		cout << "文件不存在" << endl;
		Stu_Num=0;//学生人数
		M_Student=NULL;//数组指针
		f.close();
		return;
	}
	char ch;
	f >> ch; 
	if (f.eof() && f.is_open())
	{
		cout << "文件存在但是为空" << endl;
		Stu_Num = 0;//学生人数
		M_Student = NULL;//数组指针
		f.close();
		return;
	}
	Stu_Num = stu_num();
	M_Student = new Student*[Stu_Num];//开辟空间
	stu_init();
	f.close();
	ifstream ifo;
	ifo.open(FILENAME2, ios::in);
	if (!ifo.is_open())
	{
		cout << "文件不存在" << endl;
		Acc_Num = 0;//学生人数
		M_Account = NULL;//数组指针
		f.close();
		return;
	}
	f >> ch;
	if (f.eof() && f.is_open())
	{
		cout << "文件存在但是为空" << endl;
		Acc_Num = 0;//学生人数
		M_Account = NULL;//数组指针
		f.close();
		return;
	}
	Acc_Num = acc_num();
	M_Account = new Account*[Acc_Num];//开辟空间
	acc_init();
	ifo.close();
}

void People_Manager::stu_init()//初始化
{
	fstream f;
	f.open(FILENAME1, ios::in);
	int m_num;
	string m_name;
	string m_grade;
	string m_sex;
	int m_age;
	int m_number;

	int  i = 0;
	//读取
	while (f >> m_num&&f >> m_name&&f >> m_grade&&f >> m_sex&&f >> m_age&&f >> m_number)
	{
		Student *stu = NULL;
		stu = new Student(m_num, m_name, m_grade, m_sex, m_age, m_number);
		M_Student[i] = stu;
		i++;
	}
	f.close();
}

int People_Manager::stu_num()//初始化数量
{
	fstream f;
	f.open(FILENAME1, ios::in);
	int i = 0;
	int m_num;
	string m_name;
	string m_grade;
	string m_sex;
	int m_age;
	int m_number;
	while (f >> m_num&&f >> m_name&&f >> m_grade&&f >> m_sex&&f >> m_age&&f >> m_number)
	{
		i++;
	}
	f.close();
	return i;
}

void People_Manager::acc_init()//账户初始化
{
	fstream f;
	f.open(FILENAME2 ,ios::in);
	int account;
	string password;
	int id;
	int  i = 0;
	while (f >> account&&f >> password&&f>>id)
	{
		Account *Acc = NULL;
		Acc = new Account(account, password, id);
		M_Account[i] = Acc;
		i++;
	}
	f.close();
}

void People_Manager::stu_show()//显示学生
{
	for (int i = 0; i < Stu_Num; i++)
	{
		M_Student[i]->display();
	}
	system("pause");
	system("cls");
}

void People_Manager::stu_add()//添加学生
{
	fstream f;
	f.open(FILENAME2, ios::out);
	if (!f.is_open())
	{
		cout << "文件不存在" << endl;
		return;
	}
	int j;
	int num;
	cout << "请输入要添加学生的数量:" << endl;
	cin >> num;
	Account **Acc_Manager = new Account*[Acc_Num+num];
	int i;
	for ( i = 0; i < Acc_Num; i++)
	{
		Acc_Manager[i] = M_Account[i];
	}
	j = i;
	int account;
	string password;
	//新建一个更大空间的数组
	Student **E_Student;
	E_Student = new Student *[Stu_Num + num];
	//复制数组
	for ( i = 0; i < Stu_Num; i++)
	{
		E_Student[i] = M_Student[i];
	}
	int id;
	int m_num;
	string m_name;
	string m_grade;
	string m_sex;
	int m_age;
	int m_number;
	
	for (i=0; i < num; i++)
	{
		int flag = 0;
		Account *acc = NULL;
		Student *stu = NULL;
		cout << "请输入第" << i+ 1 << "个学生的学号:" << endl;
		cin >> m_num;
		//判断是否存在重复
		for (int jjj = 0; jjj < Stu_Num; jjj++)
		{
			if (M_Student[jjj]->num == m_num)
			{
				cout << "已有该同学,请重新输入..." << endl;
				system("pause");
				system("cls");
				flag = 1;
				i--;
				break;
			}
		}
		if (flag == 1)
		{
			continue;
		}
		cout << "请输入第" << i  + 1 << "个学生的姓名:" << endl;
		cin >> m_name;
		cout << "请输入第" << i  + 1 << "个学生的年纪:" << endl;
		cin >> m_grade;
		cout << "请输入第" << i  + 1 << "个学生的性别:" << endl;
		cin >> m_sex;
		cout << "请输入第" << i  + 1 << "个学生的年龄:" << endl;
		cin >> m_age;
		cout << "请输入第" << i + 1 << "个学生的电话号码:" << endl;
		cin >> m_number;
		//默认密码为666666
		acc = new Account(m_num, "666666",1);
		Acc_Manager[j] = acc;
		stu=new Student(m_num, m_name, m_grade, m_sex, m_age, m_number);
		E_Student[i+ Stu_Num] = stu;
		j++;
	}
	//释放之前所开辟的空间
	delete[] M_Student;
	delete[] M_Account;

	M_Account = Acc_Manager;
	M_Student = E_Student;
	//数量加
	Stu_Num += num; 
	Acc_Num += num;

	cout << "成功添加" << num << "位学生" << endl;

	f.close();

	stu_save();	
	account_save();

	system("pause");
	system("cls");
}

void People_Manager::stu_save()//保存学生
{
	fstream f;
	f.open(FILENAME1, ios::out);
	for (int i = 0; i < Stu_Num; i++)
	{
		f << M_Student[i]->num << " "
			<< M_Student[i]->name << " "
			<< M_Student[i]->grade << " "
			<< M_Student[i]->sex << " "
			<< M_Student[i]->age << " "
			<< M_Student[i]->number << endl;
	}
	f.close();
}

void People_Manager::stu_del()//删除学生
{
	int num;
	string name;
	int id;
	cout << "输入删除的学生学号和姓名" << endl;
	cin >> num;
	cin >> name;
	for (int i = 0; i < Stu_Num; i++)
	{
		if (M_Student[i]->num == num && M_Student[i]->name==name)
		{
			for (int j = i; j < Stu_Num; j++)
			{
				M_Student[j] = M_Student[j+1];
			}
			cout << "删除成功" << endl;

			Stu_Num--;

			break;
		}
	}
	for (int k = 0; k < Acc_Num; k++)
	{
		if (M_Account[k]->account == num)
		{
			for (int j = k; j < Acc_Num; j++)
			{
				M_Account[k] = M_Account[k + 1];
			}
		}
	}
	//数量减一
	Acc_Num--;
	stu_save();
	account_save();
	system("pause");
	system("cls");
}

void People_Manager::stu_mod()//修改学生
{
	int num;
	string name;
	int id;
	int j;
	int i = 0;
	cout << "输入修改的学生学号和姓名" << endl;
	cin >> num;
	cin >> name;
	for (; i < Stu_Num; i++)
	{
		if (M_Student[i]->num == num && M_Student[i]->name== name)
		{
			j = i;
			break;
		}
	}
	if (i == Stu_Num)
	{
		cout << "查无此人" << endl;
		return;
	}
	int k;	
	int m_num;
	string m_name;
	string m_grade;
	string m_sex;
	int m_age;
	int m_number;	
	while (true)
	{
		int ch;
		cout << "1、学号" << endl;
		cout << "2、姓名" << endl;
		cout << "3、年级" << endl;
		cout << "4、性别" << endl;
		cout << "5、年龄" << endl;
		cout << "6、电话号码" << endl;
		cout << "7、所有" << endl;
		cout << "0、返回" << endl;
		cout << "请输入要修改的部分:" << endl;

		cin >> ch;

		switch (ch)
		{
		case 1:
			cout << "输入新学号:" << endl;
			for (int i = 0; i < Acc_Num; i++)
			{
				if (M_Account[i]->account == m_num)
				{
					k = i;
					break;
				}
			}
			cin >> m_num;
			M_Student[j]->num = m_num;
			M_Account[k]->account = m_num;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 2:
			cout << "输入新姓名:" << endl;
			cin >> m_name;
			M_Student[j]->name = m_name;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 3:
			cout << "输入新年级:" << endl;
			cin >> m_grade;
			M_Student[j]->grade = m_grade;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 4:
			cout << "输入新性别:" << endl;
			cin >> m_sex;
			M_Student[j]->sex = m_sex;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 5:
			cout << "输入新年龄:" << endl;
			cin >> m_age;
			M_Student[j]->age = m_age;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 6:
			cout << "输入新电话号码:" << endl;
			cin >> m_number;
			M_Student[j]->number = m_number;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 7:
			for (int i = 0; i < Acc_Num; i++)
			{
				if (M_Account[i]->account == m_num)
				{
					k = i;
					break;
				}
			}
			cout << "输入新学号:" << endl;
			cin >> m_num;
			M_Student[j]->num = m_num;
			M_Account[k]->account = m_num;
			cout << "输入新姓名:" << endl;
			cin >> m_name;
			M_Student[j]->name = m_name;
			cout << "输入新年级:" << endl;
			cin >> m_grade;
			M_Student[j]->grade = m_grade;
			cout << "输入新性别:" << endl;
			cin >> m_sex;
			M_Student[j]->sex = m_sex;
			cout << "输入新年龄:" << endl;
			cin >> m_age;
			M_Student[j]->age = m_age;
			cout << "输入新电话号码:" << endl;
			cin >> m_number;
			M_Student[j]->number = m_number;
			cout << "修改成功" << endl;
			system("pause");
			system("cls");
			break;
		case 0:
			system("cls");
			stu_save();
			return;
			break;
		}
	}
		
}

void People_Manager::stu_find()//查找学生
{
	
	int num;
	string name;
	int j,i;
	cout << "输入查找的学生学号和姓名" << endl;
	cin >> num;
	cin >> name;
	for ( i = 0; i < Stu_Num; i++)
	{
		if (M_Student[i]->num == num && M_Student[i]->name==name)
		{
			j = i;
		cout << M_Student[j]->num << " "<<
		M_Student[j]->name << " " <<
		M_Student[j]->grade << " " <<
		M_Student[j]->sex << " " <<
		M_Student[j]->age << " " <<
		M_Student[j]->number << endl;
			break;
		}
	}
	if (i == Stu_Num)
	{
		cout << "查无此人" << endl;
	}
	system("pause");
	system("cls");

}

void  People_Manager::stu_oper()//操作
{
	int account;
	string password;
	while (true)
	{
		cout << "输入学号:" << endl;
		cin >> account;
		cout << "输入密码:" << endl;
		pass_au(password);
		int flag = 0;
		int j;
		char b;
		for (int k = 0; k < Acc_Num; k++)
		{
			if (M_Account[k]->account == account&&M_Account[k]->password == password&&M_Account[k]->id==1)
			{
				flag = 1;	
				j = k;
				cout << "登录成功" << endl;
				system("pause");
				system("cls");
				break;
			}
		}
		if (flag)
		{
			int c;
			while (true)
			{
				cout << "\t\t-----------------" << endl;
				cout << "\t\t|1、查看自身信息|" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t|2、 修改密码   |" << endl;
				cout << "\t\t-----------------" << endl;
				cout << "\t\t|0、    返回    |" << endl;
				cout << "\t\t-----------------" << endl;
				cin >> c;
				switch (c)
				{
				case 1:
					for (int k = 0; k < Stu_Num; k++)
					{
						if (M_Student[k]->num == account)
						{
							M_Student[k]->display();
							system("pause");
							system("cls");
							break;
						}
					}
					break;
				case 2:
					cout << "输入新密码:" << endl;
					cin >> password;
					M_Account[j]->password = password;
					account_save();
					cout << "修改成功" << endl;
					system("pause");
					system("cls");
					break;
				case 0:
					system("cls");
					return;
					break;
				}
			}
		}
		else
		{
			cout << "密码错误" << endl;
			cout << "是否重新输入....(y/n)" << endl;
			cin >> b;
			if (b == 'n')
			{
				system("cls");
				return;
			}
			system("cls");
		}
	}
}

void People_Manager::tea_oper()//教师操作
{
	int account;
	string password;
	while (true)
	{
		cout << "输入职工号:" << endl;
		cin >> account;
		cout << "输入密码:" << endl;
		//cin >> password;
		int flag = 0;
		pass_au(password);
		int j;
		for (int k = 0; k < Acc_Num; k++)
		{
			if (M_Account[k]->id==2&&M_Account[k]->account == account&&M_Account[k] ->password == password)
			{
				flag = 1;
				j = k;
				cout << "登录成功" << endl;
				system("pause");
				system("cls");
				break;
			}
		}
		if (flag)
		{
			int c;
			while (true)
			{
				cout << "\t\t----------------------" << endl;
				cout << "\t\t|1、查看所有学生信息|" << endl;
				cout << "\t\t----------------------" << endl;
				cout << "\t\t|2、查看单个学生信息|" << endl;
				cout << "\t\t----------------------" << endl;
				cout << "\t\t|3、    修改密码    | " << endl;
				cout << "\t\t----------------------" << endl;
				cout << "\t\t|0、    返回        |" << endl;
				cout << "\t\t----------------------" << endl;
				cin >> c;
				int flag2 = 0;
				switch (c)
				{
				case 1:
					for (int k = 0; k < Stu_Num; k++)
					{
						M_Student[k]->display();						
					}
					system("pause");
					system("cls");
					break;
				case 2:
					
					cout << "输入学生的学号:" << endl;
					cin >> account;
					for (int k = 0; k < Stu_Num; k++)
					{
						if (M_Student[k]->num == account)
						{
							flag2=1;
							M_Student[k]->display();
							system("pause");
							system("cls");
							break;
						}
					}
					if (!flag2)
					{
						cout << "查无此人" << endl;
					}
					break;
				case 3:
					cout << "输入新密码:" << endl;
					cin >> password;
					M_Account[j]->password = password;
					account_save();
					break;
				case 0:
					system("cls");
					return;
					break;
				}
				system("cls");
			}
		}
		else
		{
			char b;
			cout << "密码错误" << endl;
			cout << "是否重新输入....(y/n)" << endl;
			cin >> b;
			if (b == 'n')
			{
				system("cls");
				return;
			}
			system("cls");
		}
	}
}

void  People_Manager::account_save()//账户保存
{
	fstream f;
	f.open(FILENAME2, ios::out);
	if (!f.is_open())
	{
		cout << "文件不存在" << endl;
		return;
	}
	for (int i = 0; i < Acc_Num; i++) {
		f << M_Account[i]->account << " " <<
			M_Account[i]->password <<" " <<
			M_Account[i]->id<<" "<<endl;
	}
	f.close();
}

void People_Manager::man_oper()//管理员操作
{

	int number = 3;
	int ACCOUNT;
	string PASSWORD;
	string password;
	int id;
	int account;
	while (true)
	{

		if (number == 3)
		{
			cout << "请输入账号:" << endl;
			cin >> ACCOUNT;
		}
		cout << "请输入密码:" << endl;
		pass_au(PASSWORD);
		int FLAG = 0;
		for (int ii = 0; ii < Acc_Num; ii++)
		{
			if (M_Account[ii]->account == ACCOUNT&&M_Account[ii]->id == 3 && M_Account[ii]->password==PASSWORD)
			{
				FLAG = 1;
				break;
			}
		}
		if (FLAG)
		{
			cout << "登录成功...." << endl;
			system("pause");
			system("cls");
			//
			int ch;
			int f;
			while (true)
			{
				
				int flag = 0;
				cout << "\t\t --------------------" << endl;
				cout << "\t\t|1、学生信息的操作  |" << endl;
				cout << "\t\t --------------------" << endl;
				cout << "\t\t|2、   账号操作     |" << endl;
				cout << "\t\t --------------------" << endl;
				cout << "\t\t|0、   退出登录     |" << endl;
				cout << "\t\t --------------------" << endl;
				cout << "输入你的选择:" << endl;
				cin >> ch;
				system("cls");
				switch (ch)
				{
				case 1:
					//
					while (true)
					{
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|1、 增添学生   |" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|2、 删除学生   |" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|3、修改学生信息|" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|4、  查找学生  |" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|5、显示学生信息|" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|6、排序学生    |" << endl;
						cout << "\t\t  ---------------" << endl;
						cout << "\t\t|0、  返回      |" << endl;
						cout << "\t\t  ---------------" << endl;
						cout << "输入你的选择:" << endl;
						cin >> ch;
						switch (ch)
						{
						case 1:
							stu_add();
							break;
						case 2:
							stu_del();
							break;
						case 3:
							stu_mod();
							break;
						case 4:
							stu_find();
							break;
						case 5:
							stu_show();
							break;
						case 6:
							stu_sort();
							break;
						case 0:
							flag = 1;
							break;

						}
						if (flag)
						{
							break;//退出循环
						}
					}
					system("cls");
					//
					break;
				case 2:
					//
					int as;

					while (true)
					{
						Account **Acc_M = new Account*[Acc_Num + 1];
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|1、添加教师账号|" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|2、删除教师账号|" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|3、查看所有账号|" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|4、修改密码    |" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "\t\t|0、退出        |" << endl;
						cout << "\t\t-----------------" << endl;
						cout << "输入你的选择:" << endl;
						cin >> ch;
						switch (ch)
						{
						case 1:
							while (true)
							{
								f = 0;
								
								cout << "输入教师的职工号:" << endl;
								cin >> account;
								for (int iii = 0; iii < Stu_Num; iii++)
								{
									if (M_Account[iii]->account == account&&M_Account[iii]->id==2)
									{
										cout << "该教师已经存在,请重新输入..." << endl;
										f = 1;
										break;
									}
								}
								if (!f)
								{
									break;
								}
							}
							for (int xi=0; xi < Acc_Num; xi++)
							{
								Acc_M[xi] = M_Account[xi];
							}
							Account *acc_m;
							acc_m = new Account(account, "111111", 2);
							Acc_M[Acc_Num] = acc_m;
							delete[]M_Account;
							M_Account = Acc_M;
							Acc_Num++;
							account_save();
							cout << "添加成功.." << endl;
							system("pause");
							system("cls");
							break;
						case 2:
							cout << "输入教师的职工号:" << endl;
							cin >> account;
							for (int ii = 0; ii < Acc_Num; ii++)
							{
								if (M_Account[ii]->account == account&&M_Account[ii]->id==2)
								{
									for (int jj = ii; jj < Acc_Num; jj++)
									{
										M_Account[jj] = M_Account[jj + 1];
									}
									break;
								}
							}
							Acc_Num--;
							account_save();
							cout << "删除成功.." << endl;
							system("pause");
							system("cls");
							break;
						case 3:
							for (int i = 0; i < Acc_Num; i++)
							{
								M_Account[i]->display();
							}
							system("pause");
							system("cls");
							break;
						case 4:
							for (int ii = 0; ii < Acc_Num; ii++)
							{
								if (M_Account[ii]->account == ACCOUNT&&M_Account[ii]->id == 3)
								{
									cout << "输入修改后的密码:" << endl;
									cin >> password;
									M_Account[ii]->password = password;
									break;
								}
							}
							account_save();
							cout << "修改成功.." << endl;
							system("pause");
							system("cls");
							break;
						case 0:
							flag = 1;
							break;
						}
						if (flag)
						{
							system("cls");
							break;
						}
					}
					system("cls");
					//
					break;
				case 0:
					system("cls");
					return;
					break;
				}
			}
			//
			return;
			
		}
		else
		{
			char  c;
			number--;
			cout << "共有三次,还剩" << number << "次";
			cout << "密码错误,是否重新输入. . .(y/n) " << endl;
			cin >> c;
			if (number == 0) {
				cout << "密码错误,进行锁定。" << endl;
				cout << "无法再次输入密码" << endl;
				_getch();
				system("cls");
				break;
			}
			//cout << "共有三次,还剩" << number << "次";	
			system("pause");
			if (c == 'n')
			{
				system("cls");
				return;
			}
			system("cls");
			
		}
	}
}

void People_Manager::stu_sort()//排序学生
{
	while (true)
	{
		system("cls");
		cout << "\t\t----------------" << endl;
		cout << "\t\t|1、顺序排序|" << endl;
		cout << "\t\t----------------" << endl;
		cout << "\t\t|2、逆序排序|" << endl;
		cout << "\t\t----------------" << endl;
		cout << "\t\t|0、  返回  |" << endl;
		cout << "\t\t----------------" << endl;
		cout << "输入你的选择:" << endl;
		int c;
		cin >> c;

		switch (c)
		{
		case 1:
			for (int i = 0; i < Stu_Num; i++)
			{
				for (int j = 0; j < Stu_Num - i - 1; j++)
				{
					if (M_Student[j]->num > M_Student[j + 1]->num)
					{
						swap(M_Student[j], M_Student[j + 1]);
					}
				}
			}
			cout << "排序成功" << endl;
			system("pause");
			system("cls");
			break;
		case 2:
			for (int i = 0; i < Stu_Num; i++)
			{
				for (int j = 0; j < Stu_Num - i - 1; j++)
				{
					if (M_Student[j]->num < M_Student[j + 1]->num)
					{
						swap(M_Student[j], M_Student[j + 1]);
					}
				}
			}
			cout << "排序成功" << endl;
			system("pause");
			system("cls");
			break;
		case 0:
			system("cls");
			stu_save();
			return;
			break;
		}

	}

}

int People_Manager::acc_num()//初始化数量
{
	fstream f;
	f.open(FILENAME2, ios::in);
	int i = 0;
	int account;
	string password;
	int id;
	while (f >> account && f >> password&&f >> id)
	{
		i++;
	}
	f.close();
	return i;
}

int People_Manager::pass_au(string &pass)//密码验证
{
	char password[1024];
	int index = 0;
	while (1) {
		char ch;
		ch = _getch();
		if (ch == 8) {
			if (index > 0) {
				index--;
				cout << char(8) << " " << char(8);
				
			}
		}
		else
			if (ch == '\r') {
				password[index] = '\0';
				cout << endl;
				break;
			}
			else
			{
				cout << "*";
				password[index++] = ch;
			}
	}
	for (int i = 0; i < index; i++) {
		pass += password[i];
	}

}

main.cpp//汇总操作

#include"all.h"
#include"fream_name.h"
#include"people.h"
#include<iostream>
#include<Windows.h>
using namespace std;
//可局部颜色变化
void color(unsigned short color_index)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_index);
}

void menu()
{
	color(6);
	cout << "\t\t-------------------------" << endl;
	cout << "\t\t|                       |" << endl;;
	cout << "\t\t|   《1、学生登录 》    |" << endl;
	cout << "\t\t|                       |" << endl;;
	cout << "\t\t|   《2、教师登录 》    |" << endl;
	cout << "\t\t|                       |" << endl;;
	cout << "\t\t|   《3、管理员登录 》  |" << endl;
	cout << "\t\t|                       |" << endl;;
	cout << "\t\t|   《0、退出系统  》   |" << endl;
	cout << "\t\t|                       |" << endl;;
	cout << "\t\t-------------------------" << endl;
	cout << "请输入你的选择:" << endl;
}

int main() 
{
	People_Manager peo;	
	int  ch;
	while (true) 
	{
		menu();
		cin >> ch;
		switch (ch)
		{
		case 1:
			peo.stu_oper();//学生
			break;
		case 2:
			peo.tea_oper();//教师
			break;
		case 3:
			peo.man_oper();//管理员
			break;
		case 0:
			system("cls");
			cout << "\n\n\n\t欢迎下次使用" << endl << endl;
			system("pause");
			exit(0);
			break;
		default:
			cout << "无此选项" << ",";
			cout << "请重新输入...." << endl;
			system("pause");
			system("cls");
			break;
		}
	}
	_getch();
	return 0;
}
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

内存不足°

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值