C++ 编写一个选课系统

//source.cpp文件


#include
#include
#include
#include
#include"c.h"
/*************************主函数****************************/
int main()
{
	int x, x1, x2, x3, x4,x5;
	bool quit1 = false;
	bool quit2 = false;
	cout << "\t\t◎★★★★【欢迎进入学生选课系统】★★★★◎\n";
	cout << "\t\t*                                          *\n";
	cout << "\t\t*            0  退出系统                   *\n";
	cout << "\t\t*            1  管理员端                   *\n";
	cout << "\t\t*            2  学生端                     *\n";
	cout << "\t\t*            3  教师端                     *\n";
	cout << "\t\t*                                          *\n";
	cout << "\t\t********************************************\n\n";

	studentmanage students;
	coursemanage courses;
	teachermanage teachers;
	selectcourse slcourse;
	teacher teacher;
	cout << "选择登入方式: "; cin >> x;
	switch (x) {
	case 0:exit(0); break;		 //****退出系统
	case 1:		                        //*********进入管理员端
		system("cls");
		char password[8];
		cout << "请输入管理员密码: "; cin >> password;
		if (strcmp(password, "123456") == 0) {
		loop:   system("cls");
			cout << "\t\t* *************************************** *\n";
			cout << "\t\t*       ★★★★ 管理员端★★★★         *\n";
			cout << "\t\t*                                         *\n";
			cout << "\t\t*              0  退出系统                *\n";
			cout << "\t\t*              1  学生信息管理            *\n";
			cout << "\t\t*              2  教师信息管理            *\n";
			cout << "\t\t*              3  课程信息管理            *\n";
			cout << "\t\t*              4  查看选课情况            *\n";
			cout << "\t\t*                                         *\n";
			cout << "\t\t* *************************************** *\n";
			while (1) {
				cout << "请选择: "; cin >> x1;
				switch (x1) {
				case 0:exit(0); break;
				case 1:
					system("cls");
					students.ShowMenu();
					while (1) {
						cout << "\n请选择: ";
						cin >> x2;
						switch (x2) {
						case 0:goto loop; break;
						case 1:students.additem();  break;
						case 2:students.display(); break;
						case 3:students.find(); break;
						case 4:students.removeitem(); break;
						case 5:students.modifyitem(); break;
						case 6:students.save(); break;
						}
					}break;
				case 2:
					system("cls");
					teachers.ShowMenu();
					while (1) {
						cout << "\n请选择: ";
						cin >> x3;
						switch (x3) {
						case 0:goto loop; break;
						case 1:teachers.additem();  break;
						case 2:teachers.display(); break;
						case 3:teachers.find(); break;
						case 4:teachers.removeitem(); break;
						case 5:teachers.modifyitem(); break;
						case 6:teachers.save(); break;
						}
					}break;
				case 3:
					system("cls");
					courses.ShowMenu();
					while (1) {
						cout << "\n请选择: ";
						cin >> x4;
						switch (x4) {
						case 0:goto loop; break;
						case 1:courses.additem();  break;
						case 2:courses.display(); break;
						case 3:courses.find(); break;
						case 4:courses.removeitem(); break;
						case 5:courses.modifyitem(); break;
						case 6:courses.save(); break;
						}
					}break;
				case 4:
					slcourse.disslcourse(); break;
				default:
					break;
				}
			}
		}
		else {
			cout << "密码错误! "; exit(0); break;
		}break;
	case 2:                               //*********进入学生端
		system("cls");
		slcourse.ShowMenu();
		while (1) {
			cout << "\n请选择: ";
			cin >> x4;
			switch (x4) {
			case 0:exit(0); break;
			case 1:slcourse.select(students, courses);  break;
			case 2:courses.display(); break;
			case 3:students.display2(); break;
			case 4:slcourse.dismessage(students); break;
			}
		} break;
	case 3:
		system("cls");
		teacher.ShowMenu();
		while (1) {
			cout << "\n请选择: ";
			cin >> x5;
			switch (x5) {
			case 0:exit(0); break;
			case 1:teachers.display2();  break;
			case 2:slcourse.disslcourse2(teachers); break;
			case 3:courses.fabucourse(teachers); break;
			}
		} break;
	}
	system("pause");
}


//c.h文件

using namespace std;
class student {							   //*******************学生类
public:
	char name[20];
	char xuehao[20];
	char major[20];
	student	 * next;
	void readfile(istream & in) { in >> name >> xuehao >> major; }
	void Input1() {
		cout << "请输入学生的姓名: ";  cin >> name;
		cout << "请输入学生的专业: ";  cin >> major;
	}
	void show1() {
		cout << "姓名:  " << name << " ,  " << "学号:  " << xuehao << " ,  " << "专业: " << major << endl;
	}
};
class studentmanage {			//**************学生管理类
public:
	studentmanage();
	~studentmanage();
	int comparexh(char xuehao[20]);
	int comparexh2(char xuehao[20]);
	int comparename(char xuehao[20], char name[20]);
	void ShowMenu();
	void additem();
	void display();
	void display2();
	void find();
	void removeitem();
	void modifyitem();
	void save();
private:
	student *Head, *End;
	ifstream in;
	ofstream out;
	student * finditem(char * xuehao) {
		for (student * p = Head; p->next != End; p = p->next)
			if (!strcmp(p->next->xuehao, xuehao)) return p;
		return NULL;
	}
};
studentmanage::studentmanage() {				 //**************构造函数
	Head = new student;
	Head->next = new student;
	End = Head->next;
	in.open("student_sort.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;
	}
}
studentmanage::~studentmanage() {					 //**************析构函数
	for (student * temp; Head->next != End;) {
		temp = Head->next;
		Head->next = Head->next->next;
		delete temp;
	}
	delete Head, End;
}
int studentmanage::comparexh(char xuehao[20]) {		 //********判断学号是否重复
	student * p = NULL;
	if (p = finditem(xuehao)) {
		cout << "该学号的学生信息已存在! " << endl;
		return 0;
	}
	else return 1;
}
int studentmanage::comparexh2(char xuehao[20]) {		 //********在选课时判断是否有该学生
	student * p = NULL;
	if (p = finditem(xuehao)) return 0;
	else {
		cout << "你输入的学号不对! " << endl;
		return 1;
	}
}
int studentmanage::comparename(char xuehao[20], char name[20]) {		 //********在选课时判断姓名是否正确
	student * p = finditem(xuehao);
	if (!strcmp(p->next->name, name)) return  0;
	else {
		cout << "你输入的姓名不对! " << endl;
		return 1;
	}
}
void studentmanage::ShowMenu() {		  //*******学生管理菜单
	cout << "\t\t* *************************************** *\n";
	cout << "\t\t*      ★★★★ 学生信息管理★★★★      *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t*             0  返回上层                 *\n";
	cout << "\t\t*             1  增加学生信息             *\n";
	cout << "\t\t*             2  显示学生信息             *\n";
	cout << "\t\t*             3  查找学生信息             *\n";
	cout << "\t\t*             4  删除学生信息             *\n";
	cout << "\t\t*             5  修改学生信息             *\n";
	cout << "\t\t*             6  保存学生信息             *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t* *************************************** *\n";
}
void studentmanage::display() {				 //*****管理员端显示学生信息
	for (student * p = Head->next; p != End; p = p->next) 
		p->show1();
}
void studentmanage::display2() {				 //*****学生端显示个人信息
	char xuehao[20];
	student * p;
	cout << "请输入你的学号: "; cin >> xuehao;
	if (p = finditem(xuehao)) {
		cout << "学号:  " << p->next->xuehao << " ,  " << "姓名:  " << p->next->name << " ,  " << "专业: " << p->next->major << endl;
	}
	else cout << "你输入的学号不对! " << endl;
}
void studentmanage::additem() {			     //*****添加学生信息
	cout << "请输入学生学号: "; cin >> End->xuehao;
	if (comparexh(End->xuehao) == 1) {
		End->Input1();
		End->next = new student;
		End = End->next;
		cout << "添加成功! " << endl;
	}
}
void studentmanage::find() {				   //*****查找学生
	char xuehao[20];
	student * p = NULL;
	cout << "请输入要查找学生的学号: ";
	cin >> xuehao;
	if (p = finditem(xuehao)) {
		p->next->show1();
	}
	else {
		cout << "没有找到该学号的学生!" << endl;
	}
}
void studentmanage::removeitem() {			//****删除学生
	char xuehao[20];
	student * p = NULL, *temp = NULL;
	cout << "请输入要删除学生的学号: "; cin >> xuehao;
	if (p = finditem(xuehao)) {
		temp = p->next;
		p->next = p->next->next;
		delete temp;
		cout << "删除成功! " << endl;
		cout << p->name;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void studentmanage::modifyitem() {		   //*****修改学生信息
	char xuehao[20];
	student * p = NULL;
	cout << "请输入要修改学生的学号: "; cin >> xuehao;
	if (p = finditem(xuehao)) {
		cout << "已找到学生的信息,请输入新的信息!" << endl;
		p->next->Input1();
		cout << "修改成功! " << endl;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void studentmanage::save() {			   //*******保存学生信息
	out.open("student_sort.txt");
	for (student * p = Head->next; p != End; p = p->next)
		out << p->name << "\t" << p->xuehao << "\t" << p->major << endl;
	out.close();
	cout << "信息已保存至指定文件! " << endl;
}
class teacher {							   //*******************教师类
public:
	char gh[20];
	char name[20];
	char post[20];
	teacher	 * next;
	void ShowMenu();
	void Input3() {
		cout << "请输入教师的姓名: ";  cin >> name;
		cout << "请输入教师的职称: ";  cin >> post;
	}
	void readfile3(istream & in) { in >> gh >> name >> post; }
	void show3() {
		cout << "工号:  " << gh << " ,  " << "姓名:  " << name << " ,  " << "职称: " << post << endl;
	}
};
void teacher::ShowMenu() {					//********教师端菜单
	cout << "\t\t* *************************************** *\n";
	cout << "\t\t*        ★★★★ 教师端★★★★          *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t*             0  退出系统                 *\n";
	cout << "\t\t*             1  查看个人信息             *\n";
	cout << "\t\t*             2  查看选课信息             *\n";
	cout << "\t\t*             3  发布课程                 *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t* *************************************** *\n";
}
class teachermanage {			//**************教师管理类
public:
	teachermanage();
	~teachermanage();
	int comparegh(char gh[20]);
	int comparegh2(char gh[20]);
	int comparename(char gh[20], char name[20]);
	void ShowMenu();
	void additem();
	void display();
	void display2();
	void find();
	void removeitem();
	void modifyitem();
	void save();
private:
	teacher *Head, *End;
	ifstream in;
	ofstream out;
	teacher * finditem(char * gh) {
		for (teacher * p = Head; p->next != End; p = p->next)
			if (!strcmp(p->next->gh, gh))  return p;
		return NULL;
	}
};
teachermanage::teachermanage() {				 //**************构造函数
	Head = new teacher;
	Head->next = new teacher;
	End = Head->next;
	in.open("teacher_sort.txt");
	if (!in)
		cout << "无教师信息,请先输入。" << endl;
	else {
		while (!in.eof()) {
			End->readfile3(in);
			if (End->gh[0] == '\0') break;
			End->next = new teacher;
			End = End->next;
		}
		in.close();
		cout << "读取教师信息成功! " << endl;
	}
}
teachermanage::~teachermanage() {					 //**************析构函数
	for (teacher * temp; Head->next != End;) {
		temp = Head->next;
		Head->next = Head->next->next;
		delete temp;
	}
	delete Head, End;
}
int teachermanage::comparegh(char gh[20]) {		 //********判断工号是否重复
	teacher * p = NULL;
	if (p = finditem(gh)) {
		cout << "该工号的教师信息已存在! " << endl;
		return 0;
	}
	else return 1;
}
int teachermanage::comparegh2(char gh[20]) {		 //********判断教师是否存在
	teacher * p = NULL;
	if (p = finditem(gh))  	return 0;
	else {
		cout << "你输入的工号不对! " << endl;
		return 1;
	}
}
int teachermanage::comparename(char gh[20], char name[20]) {		 //********教师端判断姓名是否正确
	teacher * p = finditem(gh);
	if (!strcmp(p->next->name, name)) return  0;
	else {
		cout << "你输入的姓名不对! " << endl;
		return 1;
	}
}
void teachermanage::ShowMenu() {		      //*******教师管理菜单
	cout << "\t\t* *************************************** *\n";
	cout << "\t\t*      ★★★★ 教师信息管理★★★★      *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t*             0  返回上层                 *\n";
	cout << "\t\t*             1  增加教师信息             *\n";
	cout << "\t\t*             2  显示教师信息             *\n";
	cout << "\t\t*             3  查找教师信息             *\n";
	cout << "\t\t*             4  删除教师信息             *\n";
	cout << "\t\t*             5  修改教师信息             *\n";
	cout << "\t\t*             6  保存教师信息             *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t* *************************************** *\n";
}
void teachermanage::display() {				 //*****显示教师信息
	for (teacher * p = Head->next; p != End; p = p->next)
		p->show3();
}
void teachermanage::display2() {				 //*****教师端显示个人信息
	char gh[20];
	teacher * p;
	cout << "请输入你的工号: "; cin >> gh;
	if (p = finditem(gh)) {
		cout << "工号:  " << p->next->gh << " ,  " << "姓名:  " << p->next->name << " ,  " << "职称: " << p->next->post << endl;
	}
	else cout << "你输入的工号错误! " << endl;
}
void teachermanage::additem() {			     //*****添加教师信息
	cout << "请输入教师学号: "; cin >> End->gh;
	if (comparegh(End->gh) == 1) {
		End->Input3();
		End->next = new teacher;
		End = End->next;
		cout << "添加成功! " << endl;
	}
}
void teachermanage::find() {				   //*****查找教师
	char gh[20];
	teacher * p = NULL;
	cout << "请输入要查找教师的工号: ";
	cin >> gh;
	if (p = finditem(gh)) {
		p->next->show3();
	}
	else {
		cout << "没有找到该学号的教师!" << endl;
	}
}
void teachermanage::removeitem() {			//****删除教师
	char gh[20];
	teacher * p = NULL, *temp = NULL;
	cout << "请输入要删除教师的工号: "; cin >> gh;
	if (p = finditem(gh)) {
		temp = p->next;
		p->next = p->next->next;
		delete temp;
		cout << "删除成功! " << endl;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void teachermanage::modifyitem() {		   //*****修改教师信息
	char gh[20];
	teacher * p = NULL;
	cout << "请输入要修改教师的学号: "; cin >> gh;
	if (p = finditem(gh)) {
		cout << "已找到教师的信息,请输入新的信息!" << endl;
		p->next->Input3();
		cout << "修改成功! " << endl;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void teachermanage::save() {			   //*******保存教师信息
	out.open("teacher_sort.txt");
	for (teacher * p = Head->next; p != End; p = p->next)
		out << p->gh << "\t" << p->name << "\t" << p->post << '\n';
	out.close();
	cout << "信息已保存至指定文件! " << endl;
}
class course {							//*******************课程类
public:
	char number[20];		        //课程编号
	char name[20];				    //课程名
	char teacher[20];			    //授课老师
	course * next;
	void Input2() {
		//		cout << "请输入课程编号:"; cin >> number;
		cout << "请输入课程名: "; cin >> name;
		cout << "请输入授课老师: "; cin >> teacher;
	}
	void readfile2(istream & in) { in >> number >> name >> teacher; }
	void show2() {
		cout << "课程编号:  " << number << ",    " << "课程名:  " << name << ",   " << "授课老师:  " << teacher << endl;
	}
};
class coursemanage {			  //****************课程管理类
public:
	coursemanage();
	~coursemanage();
	void ShowMenu();
	void additem();
	void fabucourse(teachermanage & t);
	void display();
	void find();
	void save();
	void modifyitem();
	void removeitem();
	int comparekc(char number[20]);
	int comparekc2(char number[20]);
	int checkfabu(char teacher[20]);
public:
	course * Head, *End;
	ifstream in;
	ofstream out;
	course * finditem(char * number) {
		for (course * p = Head; p->next != End; p = p->next)
			if (!strcmp(p->next->number, number)) return p;	    //如果已存在返回p->next
		return NULL;
	}
};
coursemanage::coursemanage() {				 //******构造函数
	Head = new course;
	Head->next = new course;
	End = Head->next;
	in.open("course_sort.txt");
	if (!in) {
		cout << "无课程信息,请先输入。" << endl;
	}
	else {
		while (!in.eof()) {
			End->readfile2(in);
			if (End->number[0] == '\0') break;
			End->next = new course;
			End = End->next;
		}
		in.close();
		cout << "读取课程信息成功! " << endl;
	}
}
coursemanage::~coursemanage() {				 //******析构函数
	for (course * temp; Head->next != End;) {
		temp = Head->next;
		Head->next = Head->next->next;
		delete temp;
	}
	delete Head, End;
}
void coursemanage::ShowMenu() {			  //******课程管理菜单
	cout << "\t\t* *************************************** *\n";
	cout << "\t\t*      ★★★★ 课程信息管理★★★★      *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t*             0  返回上层                 *\n";
	cout << "\t\t*             1  增加课程信息             *\n";
	cout << "\t\t*             2  显示课程信息             *\n";
	cout << "\t\t*             3  查找课程信息             *\n";
	cout << "\t\t*             4  删除课程信息             *\n";
	cout << "\t\t*             5  修改课程信息             *\n";
	cout << "\t\t*             6  保存课程信息             *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t* *************************************** *\n";
}
void coursemanage::additem() {					  //********管理员端添加课程
	cout << "请输入课程编号: "; cin >> End->number;
	if (comparekc(End->number) == 1) {
		End->Input2();
		End->next = new course;
		End = End->next;
		cout << "添加成功! " << endl;
	}
}
void coursemanage::fabucourse(teachermanage & t) {				//**************教师端发布课程信息
	char gh[20];
	cout << "请输入你的工号: "; cin >> gh;
	if (t.comparegh2(gh) == 0) {
		cout << "请输入你的姓名: "; cin >> End->teacher;
		if (t.comparename(gh, End->teacher) == 0) {
			if (checkfabu(End->teacher) == 0) {
				cout << "请输入课程编号: "; cin >> End->number;
				if (comparekc(End->number) == 1) {
					cout << "请输入课程名: "; cin >> End->name;
					out.open("course_sort.txt", ios::app);
					out << End->number << "\t" << End->name << "\t" << End->teacher << '\n';
					End->next = new course;
					End = End->next;
					out.close();
					cout << "发布成功! " << endl;
				}
			}
			else {
				cout << "你已经发布过课程了! " << endl;
			}
		}
	}
}
void coursemanage::display() {					//******显示课程信息
	for (course*p = Head->next; p != End; p = p->next)
		p->show2();
}
void coursemanage::find() {			//*********查找课程
	char number[20];
	course * p = NULL;
	cout << "请输入要查找的课程编号: "; cin >> number;
	if (p = finditem(number)) {
		p->next->show2();
	}
	else {
		cout << "没有找到该课程! " << endl;
	}
}
int coursemanage::comparekc(char number[20]) {			  //**********判断课程是否存在
	course * p = NULL;
	if (p = finditem(number)) {
		cout << "该课程编号已存在 ! " << endl;
		return 0;
	}
	else return 1;
}
int coursemanage::comparekc2(char number[20]) {			  //**********在选课时判断课程存在与否
	course * p = NULL;
	if (p = finditem(number))  return 0;
	else {
		cout << "该课程还未开设! " << endl;
		return 1;
	}
}
int coursemanage::checkfabu(char teacher[20]) {			  //**********在选课时判断课程存在与否
	course * p = NULL;
	for (course * p = Head; p->next != End; p = p->next)
		if (!strcmp(p->next->teacher, teacher)) return 1;	    //如果已存在返回1
	return 0;
}
void coursemanage::modifyitem() {		  //********修改课程
	char number[20];
	course * p = NULL;
	cout << "请输入要修改的课程编号: "; cin >> number;
	if (p = finditem(number)) {
		cout << "已找到该课程的信息,请输入新的信息! " << endl;
		p->next->Input2();
		cout << "修改成功! " << endl;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void coursemanage::removeitem() {		   //********删除课程
	char number[20];
	course * p = NULL, *temp = NULL;
	cout << "请输入要删除课程的编号: "; cin >> number;
	if (p = finditem(number)) {
		temp = p->next;
		p->next = p->next->next;
		delete temp;
		cout << "删除成功! " << endl;
	}
	else {
		cout << "没有找到! " << endl;
	}
}
void coursemanage::save() {
	out.open("course_sort.txt");
	for (course * p = Head->next; p != End; p = p->next)
		out << p->number << "\t" << p->name << "\t" << p->teacher << '\n';
	out.close();
	cout << "课程信息已存至指定文件! " << endl;
}
class sc :public student, public course {			//********选课类
public:
	sc * next;
	void Inputname() { cout << "请输入你的姓名: "; cin >> student::name; }
	void Inputxuehao() { cout << "请输入你的学号: "; cin >> xuehao; }
	void Inputnumber() { cout << "请输入你要选择课程的编号: "; cin >> number; }
	void readfile4(istream & in) { in >> xuehao >> student::name >> number >> course::name >> teacher; }
	void Showslcourse() {
		cout << "学号:  " << xuehao << ",  " << "姓名:  " << student::name << ",   " << "课程编号:  " << number << ",  " << "课程名:  " << course::name << ",  " << "授课老师:  " << teacher << endl;
	}
};
class selectcourse {
public:
	selectcourse();
	~selectcourse();
	void ShowMenu();
	int comparetest(char number[20]);
	void disslcourse();
	void disslcourse2(teachermanage & t);
	void select(studentmanage &s, coursemanage &c);
	void dismessage(studentmanage &s);
private:
	sc *Head, *End;
	ofstream out;
	ifstream in;
	sc *finditem2(char * xuehao) {
		for (sc *p = Head; p->next != End; p = p->next)
			if (!strcmp(p->next->xuehao, xuehao))  return p->next;
		return NULL;
	}
};
selectcourse::selectcourse() {
	Head = new sc;
	Head->next = new sc;
	End = Head->next;
	in.open("selectcourse_sort.txt");
	if (!in)
		cout << "暂无学生选课信息。" << endl;
	else {
		while (!in.eof()) {
			End->readfile4(in);
			if (End->xuehao[0] == '\0')  break;
			End->next = new sc;
			End = End->next;
		}
		in.close();
	}
}
selectcourse::~selectcourse() {			   //***********析构函数
	for (sc * temp; Head->next != End;) {
		temp = Head->next;
		Head->next = Head->next->next;
		delete temp;
	}
	delete Head, End;
}
void selectcourse::disslcourse() {			        //*************管理员端显示选课情况
	in.open("selectcourse_sort.txt");
	if (!in)
		cout << "暂无学生选课信息。" << endl;
	else {
		for (sc* p = Head->next; p != End; p = p->next) {
			p->Showslcourse();
		}
	}
	in.close();
}
void selectcourse::disslcourse2(teachermanage & t) {				 //教师端查看选课情况
	char  gh[20];
	char name[20];
	int sum = 0;
	sc * p, *temp;
	cout << "请输入你的工号: "; cin >> gh;
	if (t.comparegh2(gh) == 0) {
		cout << "请输入你的姓名: "; cin >> name;
		if (t.comparename(gh, name) == 0) {
			for (p = Head->next; p != End; p = p->next) {
				if (!strcmp(p->teacher, name)) {
					sum++;
					temp = p;
				}
			}
			cout << "课程编号:  " << temp->number << ",  " << "课程名:  " << temp->course::name << ",   " << "已选人数:  " << sum << '\0';
		}
	}
}
void selectcourse::ShowMenu() {					//********学生端菜单
	cout << "\t\t* *************************************** *\n";
	cout << "\t\t*        ★★★★ 学生端★★★★          *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t*             0  退出系统                 *\n";
	cout << "\t\t*             1  开始选课                 *\n";
	cout << "\t\t*             2  显示课程信息             *\n";
	cout << "\t\t*             3  查看个人信息             *\n";
	cout << "\t\t*             4  查看选课情况             *\n";
	cout << "\t\t*                                         *\n";
	cout << "\t\t* *************************************** *\n";
}
int selectcourse::comparetest(char xuehao[20]) {		  //******判断该学生是否选过课
	sc * p = NULL;
	if (p = finditem2(xuehao)) {
		cout << "你已经选过课程了! " << endl;
		return 1;
	}
	else return 0;
}
void selectcourse::select(studentmanage &s, coursemanage &c) {		  //******学生选课函数
	End->Inputxuehao();
	if (s.comparexh2(End->xuehao) == 0)
		if (comparetest(End->xuehao) == 0) {
			End->Inputname();
			if (s.comparename(End->xuehao, End->student::name) == 0) {
				End->Inputnumber();
				if (c.comparekc2(End->number) == 0) {
					course * p = c.finditem(End->number);
					out.open("selectcourse_sort.txt", ios::app);
					out << End->xuehao << "\t" << End->student::name << "\t" << p->next->number << "\t" << p->next->name << "\t" << p->next->teacher << '\n';
					End->next = new sc;
					End = End->next;
					out.close();
					cout << "选课成功!  " << endl;
				}
			}
		}
}
void selectcourse::dismessage(studentmanage &s) {				//学生端查看选课情况
	char xuehao[20];
	sc * p;
	cout << "请输入你的学号: "; cin >> xuehao;
	if (s.comparexh2(xuehao) == 0) {
		for (p = Head->next; p != End; p = p->next) {
			if (!strcmp(p->xuehao, xuehao))  break;
		}
		if (!strcmp(p->xuehao, xuehao)) {
			cout << "学号:  " << p->xuehao << ",  " << "姓名:  " << p->student::name << ",   " << "已选课程编号:  " << p->number << '\0';
		}
		else cout << "你还没有选课! " << endl;
	}
}


你可能感兴趣的:(【C/C++】)