C++教务管理系统
Demo龙 人气:0gradeInfo.cpp
#include <iostream> #include <string> #include <sstream>//stringstream字符串流需要引用的库 #include <fstream> #include "gradeInfo.h" using namespace std; //构造函数初始化数据 gradeInfo::gradeInfo() { studentNumber = new string[200]; grade = new double[200]; courseNumber = ""; studentNum = 0; } //录入学生信息 void gradeInfo::setGradeInfo(string courseNumber,int studentNum) { for (int i = 0; i < studentNum; i++) grade[i] = 0; this->courseNumber = courseNumber; this->studentNum = studentNum; } //录入学生成绩 void gradeInfo::setGrade() { cout << "请开始输入学生成绩:" << endl << endl; for (int i = 0; i < studentNum; i++) { cout << studentNumber[i] << " : "; cin >> grade[i]; } } //根据学号查询某同学的成绩及分数 void gradeInfo::searchSingleGrade(string new_studentNumber) const { for (int i = 0; i < studentNum; i++) { if (new_studentNumber == studentNumber[i]) cout << " 学号:" << studentNumber[i] << " 课程成绩:" << grade[i] << endl << endl; } } //查询所有成绩分数 void gradeInfo::searchAllGrade(student * s, int totalSNum) const { for (int i = 0; i < studentNum; i++) { for (int k = 0; k < totalSNum; k++) { if (studentNumber[i] == s[k].getStudentNumber()) cout << "学号 : " << studentNumber[i] << " 姓名 : " << s[k].getName() << " 成绩: " << grade[i] << " "<< endl; } } cout << endl; } //返回课程数目 string gradeInfo::getCourseNumber() const { return courseNumber; } //返回学生数目 int gradeInfo::getStudentNum() { return studentNum; } //将成绩及数据写入文件 void gradeInfo::writeToTxtFileG(int num) const { string fileName ( "grade"); stringstream ss;//stringstream文件流的输入输出操作 ss << num; fileName.append(ss.str());//ss.str()转换成末尾为/0的字符串数组 fileName.append(".txt"); ofstream txtOut(fileName.c_str());//c_str():生成一个const char*指针,指向以空字符终止的数组。 txtOut << courseNumber << " " << studentNum << endl; for (int i = 0; i < studentNum; i++) { txtOut << studentNumber[i] << " " << grade[i] << endl; } txtOut.close(); } //从文件中读取学号及成绩 void gradeInfo::readFromTxtFileG(int num) { string fileName ( "grade"); stringstream ss; ss << num; fileName.append(ss.str());//.str()返回一个以‘/0'结尾的字符数组 fileName.append(".txt"); fstream txtIn(fileName.c_str(), ios::in); txtIn >> courseNumber >> studentNum; for (int i = 0; i < studentNum; i++) txtIn >> studentNumber[i] >> grade[i]; txtIn.close(); } //根据学生数据判断是否存在学生 bool gradeInfo::isStudentHere(string new_studentNumber) { bool temp = false; for (int i = 0; i < studentNum; i++) { if (new_studentNumber == studentNumber[i]) temp = true; } return temp; } //析构函数 gradeInfo::~gradeInfo() { delete [] studentNumber; delete [] grade; }
gradeInfo.h
#include <string> #include "student.h" using namespace std; class gradeInfo { public: string * studentNumber;//学号 string courseNumber;//课程编号 double * grade;//成绩 int studentNum;//课程学生数 friend class teacher; gradeInfo();//默认构造函数 void setGradeInfo(string courseNumber, int studentNum);//设置初始化成绩信息对象 void setGrade();//录入成绩 void searchSingleGrade(string studentNumber) const;//利用学号查询成绩 void searchAllGrade(student * s, int totalSNum) const;//输出全体学生成绩 string getCourseNumber() const;//获取课程编号 int getStudentNum();//获取学生数 void writeToTxtFileG(int) const; void readFromTxtFileG(int); bool isStudentHere(string new_studentNumber);//判断学生是否有相应课程编码的课 ~gradeInfo(); //删除学号和成绩指针 };
classInfo.cpp
#include <iostream> #include <fstream> #include <string> #include "classInfo.h" using namespace std; //构造函数初始化课程数据 classInfo::classInfo() { courseNumber = ""; courseName = ""; credit = 0 ; jobNumberOfTeacher = ""; } //录入课程数据 void classInfo::setClassInfo(string courseNumber, string courseName, double credit, string jobNumberOfTeacher) { this->courseNumber = courseNumber; this->courseName = courseName; this->credit= credit; this->jobNumberOfTeacher = jobNumberOfTeacher; } //展示课程数据 void classInfo::searchBasicInfo() const { cout <<"课程编号:" << courseNumber << " " << "课程名称:" << courseName << " 学分: " << credit << endl; } //返回教师工号 string classInfo::getJobNumberOfTeacher() const { return jobNumberOfTeacher; } //返回课程代码 string classInfo::getCourseNumber() const { return courseNumber; } //返回课程学分 double classInfo::getCredit() const { return credit; } //返回课程名 string classInfo::getCourseName() const { return courseName; } //将课程信息录入文件 void classInfo::writeToTxtFileC() const { ofstream txtOut("classBasicInfo.txt", ios::app); txtOut << courseNumber << " " << courseName << " " << credit << " " << jobNumberOfTeacher << endl; txtOut.close(); } //从文件中读取课程信息 void classInfo::readFromTxtFileC(int num) { fstream txtIn("classBasicInfo.txt", ios::in); string temp; int line = 1; if(num == 1) txtIn >> courseNumber >> courseName >> credit >> jobNumberOfTeacher ; else { while(getline(txtIn, temp, '\n')) { line++; if(line == num) txtIn >> courseNumber >> courseName >> credit >> jobNumberOfTeacher ; } } txtIn.close(); }
classInfo.h
#ifndef CLASSINFO_H #define CLASSINFO_H #include <string> using namespace std; class classInfo { protected: string courseNumber;//课程编号 string courseName;//课程名称 double credit;//学分 string jobNumberOfTeacher;//任课老师工号 public: friend class systemAdmin; classInfo();//默认构造函数 void setClassInfo(string courseNumber, string courseName, double credit, string jobNumberOfTeacher);//设置课程信息 void searchBasicInfo() const;//输出课程信息 string getJobNumberOfTeacher() const;//获取任课教师工号 string getCourseNumber() const;//获取课程编号 string getCourseName() const;//获取课程名称 double getCredit() const;//获取学分 void writeToTxtFileC() const;//向文件中写入数据 void readFromTxtFileC(int);//从文件中读取数据 }; #endif // !CLASSINFO_H
user.cpp
#include "user.h" #include <string> #include <iostream> using namespace std; //构造函数初始化数据 user::user() { password = "zal222";//初始密码为zal222 name = ""; sex = ""; birth = ""; politicStatus = ""; address = ""; } //修改初始密码 void user::changePassword() { string new_password, original_password, new_password1; cout << endl << "请输入原密码 : "; cin >> original_password; while (password != original_password) { cout << "原密码输入错误,请重新输入: "; cin >> original_password; } while (password == original_password) { cout << "请输入新密码 : "; cin >> new_password; cout << "请再次输入新密码: "; cin >> new_password1; if (new_password == new_password1) { password = new_password; break; } else cout << "两次次新密码不一致,请重新输入!" << endl; } cout << "\t\t\t\t\t 你的密码修改成功,请重新登录!" << endl; } //返回密码 string user::getPassword() const//函数不可以修改class的成员 { return password; } //返回用户名(管理员) string user::getUserName() const//函数不可以修改class的成员 { return userName; }
user.h
#ifndef USER_H #define USER_H #include <string> using namespace std; class user { public: string password;//密码最长为15位 string userName;//用于管理员的用户名 string name;//姓名 string sex;//性别 string birth;//生日 string politicStatus;//政治面貌 string address;//地址 user(); void changePassword();//修改初始密码 string getPassword() const;//返回密码 string getUserName() const;//返回用户名(管理员) //由于教务系统的特殊性,不用自己注册账号 }; #endif
student.cpp
#include <string> #include <fstream> #include <iostream> #include "student.h" using namespace std; //构造函数 student::student() { studentNumber = ""; majorAndClass = ""; } //设置学生基础信息 void student::setStudentBasicInfo(string new_studentNumber, string new_name, string new_sex, string new_majorAndClass, string new_birth, string new_politicStatus, string new_address) { studentNumber = new_studentNumber; name = new_name; sex = new_sex; majorAndClass = new_majorAndClass; birth = new_birth; politicStatus = new_politicStatus; address = new_address; } //查询基础信息 void student::searchBasicInfo() const { cout << endl << "\t学号:" << studentNumber << " " << "姓名:" << name << " " << "性别:" << sex << " " << "专业班级:" << majorAndClass << " " << "生日:" << birth << " " << "政治面貌:" << politicStatus << " " << "家庭地址:" << address << endl; } //返回学号 string student::getStudentNumber() const { return studentNumber; } //返回姓名 string student::getName() { return name; } //向文件中写入数据 void student:: writeToTxtFileS() const { ofstream txtOut("studentBasicInfo.txt", ios::app); txtOut << studentNumber << " " << password << " " << name << " " << sex << " " << majorAndClass << " " << birth << " " << politicStatus << " " << address << endl; txtOut.close(); } //从文件中读取数据 void student::readFromTxtFileS(int num) { fstream txtIn("studentBasicInfo.txt", ios::in); string temp; int line = 1; if(num == 1) txtIn >> studentNumber >> password >> name >> sex >> majorAndClass >> birth >> politicStatus >> address; else { while(getline(txtIn, temp, '\n')) { line++; if(line == num) txtIn >> studentNumber >> password >> name >> sex >> majorAndClass >> birth >> politicStatus >> address; } } txtIn.close(); }
student.h
#ifndef STUDENT_H #define STUDENT_H #include "user.h" #include <string> using namespace std; class student : public user { public: string studentNumber;//学号,学生用户名 string majorAndClass;//专业班级 student();//默认构造函数 void setStudentBasicInfo(string studentNumber, string name, string sex, string majorAndClass, string birth, string politicStatus, string address);//设置学生基础信息 void searchBasicInfo() const;//查询基础信息 string getStudentNumber() const;//返回学号 string getName(); void writeToTxtFileS() const;//向文件中写入数据 void readFromTxtFileS(int);//从文件中读取数据 }; #endif
teacher.cpp
#include "teacher.h" #include <fstream> #include <iostream> using namespace std; //构造函数 teacher::teacher() { user(); //调用构造函数 jobNumber = ""; college = ""; } //录入学生基本信息 void teacher::setTeacherBasicInfo(string jobNumber, string name, string sex, string college, string birth, string politicStatus, string scale) { this->name = name; this->sex = sex; this->birth = birth; this->politicStatus = politicStatus; this->scale = scale; this->jobNumber = jobNumber; this->college = college; } //返回教师工号 string teacher::getJobNumber() const { return jobNumber; } //查找教师基本信息 void teacher::searchBasicInfo() { cout << endl; cout << "\t工号:" << jobNumber << " 姓名:" << name << " 性别:" << sex << " 学院:" << college << " 生日:" << birth << " 政治面貌:" << politicStatus << " 职称:" << scale << endl; cout << endl; } //向文件中写入数据 void teacher::writeToTxtFileT() const { ofstream txtOut("teacherBasicInfo.txt", ios::app); txtOut << jobNumber << " " << password << " " << name << " " << sex << " " << college << " " << birth << " " << politicStatus << " " << scale << endl; txtOut.close(); } //从文件中读取数据 void teacher::readFromTxtFileT(int num) { fstream txtIn("teacherBasicInfo.txt", ios::in); string temp; int line = 1; if(num == 1) txtIn >> jobNumber >> password >> name >> sex >> college >> birth >> politicStatus >> scale; else { while(getline(txtIn, temp, '\n')) { line++; if(line == num) txtIn >> jobNumber >> password >> name >> sex >> college >> birth >> politicStatus >> scale; } } txtIn.close(); }
teacher.h
#include"user.h" #include <string> using namespace std; class teacher :public user//C++继承 { protected: string jobNumber;//工号 string college;//学院 string scale;//职称 public: teacher(); string getJobNumber() const; void writeToTxtFileT() const;//向文件中写入数据 void readFromTxtFileT(int);//从文件中读取数据 void setTeacherBasicInfo(string jobNumber, string name, string sex, string college, string birth, string politicStatus, string scale);//设置教师基础信息 void searchBasicInfo();//查询基本信息 };
main.cpp
#include <iostream> #include <fstream>//C++文件流 #include <string> #include "user.h" #include "student.h" #include "teacher.h" #include "gradeInfo.h" #include "classInfo.h" #include "systemAdmin.h" using namespace std; string userName,password, tempCourseNumber,//用于输入课程编号的地方 tempStudentNumber,//用于输入学号的地方 tempJobNumber;//用于输入工号的地方 //读写删学生文件数据 void writeDataS(student * s, int studentNum); void readDataS(student * s, int studentNum); void deleteStudentTxtInfo(); // 读写删老师文件数据 void writeDataT(teacher * t, int teachertNum); void readDataT(teacher * t, int teacherNum); void deleteTeacherTxtInfo(); //写入文件 void writeDataG(gradeInfo * g, int courseNum); void readDataG(gradeInfo * g, int courserNum); void writeDataA(systemAdmin * a, int systemAdminNum); void readDataA(systemAdmin * a, int systemAdminNum); void deleteSystemAdminTxtInfo(); void writeDataC(classInfo * c, int courseNum); void readDataC(classInfo * c, int courseNum); void deleteCourseTxtInfo(); //文件写入汇总信息 //在文件中写入学生数目,课程数目,老师数目,系统管理原数目 void writeAllNumToFile(int studentNum, int courseNum, int teacherNum, int systemAdminNum); //从文件读取学生数目,课程数目,老师数目,系统管理原数目 void readAllNumFromFile(int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum); //展示各登录 界面 void displayLoginForm();//登录界面展示 void studentLoginForm();//学生功能界面展示 void teacherLoginForm();//教师功能界面展示 void systemAdminLoginForm();//管理员功能界面展示 void studentBasicInfoManageForm();//学生信息管理界面展示 void teacherBasicInfoManageForm();//老师信息管理界面展示 void classBasicInfoManageForm(); //信息管理界面展示 void studentGradeSearchForm();//学生成绩界面 void studentBasicInfoSearchForm();//学生成绩查询界面 void teacherBasicInfoSearchForm();//教师信息查询界面 void classBasicInfoSearchForm();//课程信息查询界面 //返回界面 void enter0ToBack(int& num); //按照课程信息查找成绩 void studentSearchGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3); //按照课程编号和学生学号查询学生信息 void teacherSearchSingleGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3, int& flag5); //查询所有课程 void teacherSearchAllGrade(classInfo * c, gradeInfo * g, student * s, int courseNum, int studentNum, int& flag3); void teacherIuputGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3); void systemAdminInputSBasicInfo(student * s, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i); void systemAdminSearchSingleSBasicInfo(student * s, int studentNum, int& flag7); void systemAdminSearchAllSBasicInfo(student * s, int studentNum); void systemAdminDeleteSBasicInfo(systemAdmin * a, student * s, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i); void systemAdminInputTBasicInfo(teacher * t, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i); void systemAdminSearchSingleTBasicInfo(teacher * t, int teacherNum, int& flag7); void systemAdminSearchAllTBasicInfo(teacher * t, int teacherNum); void systemAdminDeleteTBasicInfo(systemAdmin * a, teacher * t, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i); //录入学生信息 void systemAdminInputCBasicInfo(classInfo * c, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i); //查询学生信息 void systemAdminSearchSingleCBasicInfo(classInfo * c, int courseNum, int& flag7); //展示录入的学生信息 void systemAdminSearchAllCBasicInfo(classInfo * c, int courseNum); //删除管理基本信息 void systemAdminDeleteCBasicInfo(systemAdmin * a, classInfo * c, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i); //学生选课信息 void generateSSelectionInfo(classInfo * c, gradeInfo * f, student * s, int courseNum, int studentNum); //判断老师是否带这门课 bool isTeacherClass(classInfo * c, string courseNumber, string userName, int courseNum); //判断学生是否在这门课中 bool isInThisCourse(gradeInfo * g, string courseNumber, string studentNumber, int courseNum); int main() { int flag[10]= {0}, studentNum = 5, courseNum = 3, teacherNum = 2, systemAdminNum = 1; //writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); readAllNumFromFile(studentNum, courseNum, teacherNum, systemAdminNum); student * s = new student[studentNum + 200]; teacher * t = new teacher[teacherNum + 200]; gradeInfo * g = new gradeInfo[courseNum + 200]; systemAdmin * a = new systemAdmin[systemAdminNum + 200]; classInfo * c = new classInfo[courseNum + 200]; while (flag[0] == 0)//flag[0]用于返回登陆界面 { readDataG(g, courseNum); readDataT(t, teacherNum); readDataS(s, studentNum); readDataA(a, systemAdminNum); readDataC(c, courseNum); displayLoginForm(); for (int i = 0; i < 10; i++) flag[i] = 0; //重新开始登陆,标记值需要返0,否则会产生错误 for (int i = 0; i < studentNum; i++) { if (userName == s[i].getStudentNumber() && password == s[i].getPassword()) { while(flag[1] == 0)//flag[1]用于返回功能管理界面 { flag[3] = 0;//判定学生输入的课程编码是否是他的上课编码 studentLoginForm(); cin >> flag[0]; switch (flag[0]) { case 1: s[i].searchBasicInfo(); enter0ToBack(flag[1]); break; case 2: studentSearchGrade(c, g, courseNum, flag[3]); enter0ToBack(flag[1]); break; case 3: s[i].changePassword(); deleteStudentTxtInfo(); writeDataS(s, studentNum); flag[0] = 0;flag[1] = 1;break; case 4: flag[0] = 0;flag[1] = 1;break; case 5: flag[0] = 1;flag[1] = 1;break; default: cout << "数据错误,请重新输入数字!!!" << endl; } } } else continue; flag[2]++;//flag[2]用于检测密码正误 ,若一直为0,则说明未进入 功能界面,也就是无任何匹配的账号 } for (int i = 0; i < teacherNum; i++) { if (userName == t[i].getJobNumber() && password == t[i].getPassword()) { while(flag[1] == 0)//flag[1]用于返回功能管理界面 { flag[3] = 0;//判定教师输入的课程编码是否是他的教学课程 flag[5] = 0;//判定学生输入的课程编码是否是他的上课编码 flag[4] = 0; teacherLoginForm(); cin >> flag[0]; switch (flag[0]) { case 1: t[i].searchBasicInfo(); enter0ToBack(flag[1]); break; case 2: while(flag[4] == 0)//用于第三层小循环 { studentGradeSearchForm(); cin >> flag[4]; switch(flag[4]) { case 1: teacherSearchSingleGrade(c, g, courseNum, flag[3], flag[5]); enter0ToBack(flag[4]); break; case 2: //输出全体学生成绩 teacherSearchAllGrade(c, g, s, courseNum, studentNum, flag[3]); enter0ToBack(flag[4]); break; case 3://返回教师功能界面 flag[4] = 1; flag[1] = 0; break; case 4: flag[4] = 1; flag[1] = 1; flag[0] = 0; break; case 5://退出程序 flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入数字!!!" << endl; } } break; case 3: teacherIuputGrade(c, g, courseNum, flag[3]); enter0ToBack(flag[1]); break; case 4: t[i].changePassword(); deleteTeacherTxtInfo(); writeDataT(t, teacherNum); flag[0] = 0;flag[1] = 1;break; case 5: flag[0] = 0;flag[1] = 1;break; case 6: flag[0] = 1; flag[1] = 1;break; default: cout << "数据错误,请重新输入数字!!" << endl; } } } else continue; flag[2]++;//flag[2]用于检测密码正误 ,若一直为0,则说明未进入 功能界面,也就是无任何匹配的账号 } for (int i = 0; i < systemAdminNum; i++) { if (userName == a[i].getUserName() && password == a[i].getPassword()) { while(flag[1] == 0)//flag[1]用于返回功能管理界面 { flag[4] = 0; flag[7] = 0; systemAdminLoginForm(); cin >> flag[0]; switch (flag[0]) { case 1: while(flag[4] == 0)//用于第三层小循环 { flag[7] = 0; flag[6] = 0; studentBasicInfoManageForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminInputSBasicInfo(s, a, studentNum, courseNum, teacherNum, systemAdminNum, i); enter0ToBack(flag[4]); break; case 2: while(flag[6] == 0) { flag[7] = 0; studentBasicInfoSearchForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminSearchSingleSBasicInfo(s, studentNum, flag[7]); enter0ToBack(flag[6]); break; case 2: systemAdminSearchAllSBasicInfo(s, studentNum); enter0ToBack(flag[6]); break; case 3: flag[6] = 1; flag[4] = 0; break; case 4: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 0; break; case 5: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入数字!!!" << endl; } } break; case 3: systemAdminDeleteSBasicInfo(a, s, studentNum, courseNum, teacherNum, systemAdminNum, flag[7], i); enter0ToBack(flag[4]); break; case 4: flag[4] = 1; flag[1] = 0; break; case 5: flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入!!!" << endl; } } break; case 2: while(flag[4] == 0)//用于第三层小循环 { flag[7] = 0; flag[6] = 0; teacherBasicInfoManageForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminInputTBasicInfo(t, a, studentNum, courseNum, teacherNum, systemAdminNum, i); enter0ToBack(flag[4]); break; case 2: while(flag[6] == 0) { flag[7] = 0; teacherBasicInfoSearchForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminSearchSingleTBasicInfo(t, teacherNum, flag[7]); enter0ToBack(flag[6]); break; case 2: systemAdminSearchAllTBasicInfo(t, teacherNum); enter0ToBack(flag[6]); break; case 3: flag[6] = 1; flag[4] = 0; break; case 4: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 0; break; case 5: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入数字!!!" << endl; } } break; case 3: systemAdminDeleteTBasicInfo(a, t, studentNum, courseNum, teacherNum, systemAdminNum, flag[7], i); enter0ToBack(flag[4]); break; case 4: flag[4] = 1; flag[1] = 0; break; case 5: flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入!!!" << endl; } } break; case 3: while(flag[4] == 0)//用于第三层小循环 { flag[7] = 0; flag[6] = 0; classBasicInfoManageForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminInputCBasicInfo(c, a, studentNum, courseNum, teacherNum, systemAdminNum, i); enter0ToBack(flag[4]); break; case 2: while(flag[6] == 0) { flag[7] = 0; classBasicInfoSearchForm(); cin >> flag[0]; switch(flag[0]) { case 1: systemAdminSearchSingleCBasicInfo(c, courseNum, flag[7]); enter0ToBack(flag[6]); break; case 2: systemAdminSearchAllCBasicInfo(c, courseNum); enter0ToBack(flag[6]); break; case 3: flag[6] = 1; flag[4] = 0; break; case 4: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 0; break; case 5: flag[6] = 1; flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入数字!!!" << endl; } } break; case 3: systemAdminDeleteCBasicInfo(a, c, studentNum, courseNum, teacherNum, systemAdminNum, flag[7], i); enter0ToBack(flag[4]); break; case 4: flag[4] = 1; flag[1] = 0; break; case 5: flag[4] = 1; flag[1] = 1; flag[0] = 1; break; default: cout << "数据错误,请重新输入!!!" << endl; } } break; case 4: generateSSelectionInfo(c, g, s, courseNum, studentNum); enter0ToBack(flag[1]); break; case 5: a[i].changePassword(); deleteSystemAdminTxtInfo(); writeDataA(a, systemAdminNum); flag[0] = 0;flag[1] = 1;break; case 6: flag[0] = 0;flag[1] = 1;break; case 7: flag[0] = 1; flag[1] = 1;break; default: cout << "数据错误,请重新输入!!!" << endl; } } } else continue; flag[2]++;//flag[2]用于检测密码正误 ,若一直为0,则说明未进入 功能界面,也就是无任何匹配的账号 } if (flag[2] == 0)//flag[2]用于检测密码正误 cout << "用户名和密码输入错误,请重新登录!" << endl; } system("pause"); return 0; } //登录界面展示 void displayLoginForm() { cout << endl; system("color 2f"); cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 教务管理系统登陆界面\t\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t用户名:"; cin >> userName; cout << "\t\t\t\t\t\t密码 :"; cin >> password; } //教师功能界面展示 void teacherLoginForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到教师功能界面\t\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询基本信息" << endl; cout << "\t\t\t\t\t\t2.查询成绩信息" << endl; cout << "\t\t\t\t\t\t3.录入学生成绩" << endl; cout << "\t\t\t\t\t\t4.修改密码" << endl; cout << "\t\t\t\t\t\t5.返回登陆界面" << endl; cout << "\t\t\t\t\t\t6.退出" << endl; cout << "输入对应的数字进行相关操作: " ; } //管理员功能界面展示 void systemAdminLoginForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到管理员功能界面\t\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.管理学生基本信息" << endl; cout << "\t\t\t\t\t\t2.管理教师基本信息" << endl; cout << "\t\t\t\t\t\t3.管理课程信息" << endl; cout << "\t\t\t\t\t\t4.生成学生选课信息" << endl; cout << "\t\t\t\t\t\t5.修改密码" << endl; cout << "\t\t\t\t\t\t6.返回登陆界面" << endl; cout << "\t\t\t\t\t\t7.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //学生功能界面展示 void studentLoginForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到学生功能界面\t\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询基本信息" << endl; cout << "\t\t\t\t\t\t2.查询成绩信息" << endl; cout << "\t\t\t\t\t\t3.修改密码" << endl; cout << "\t\t\t\t\t\t4.返回登陆界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: " ; } //学生信息管理界面展示 void studentBasicInfoManageForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到学生信息管理界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.录入学生信息" << endl; cout << "\t\t\t\t\t\t2.查询学生信息" << endl; cout << "\t\t\t\t\t\t3.删除学生信息" << endl; cout << "\t\t\t\t\t\t4.返回管理员功能界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: " ; } // 教师信息管理界面 void teacherBasicInfoManageForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到教师信息管理界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.录入教师信息" << endl; cout << "\t\t\t\t\t\t2.查询师信息查询" << endl; cout << "\t\t\t\t\t\t3.教师信息删除" << endl; cout << "\t\t\t\t\t\t4.返回管理员功能界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: " ; } //程信息管理界面 void classBasicInfoManageForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到课程信息管理界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.录入课程信息" << endl; cout << "\t\t\t\t\t\t2.查询课程信息" << endl; cout << "\t\t\t\t\t\t3.删除课程信息" << endl; cout << "\t\t\t\t\t\t4.返回管理员功能界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //学生成绩查询界面 void studentGradeSearchForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 学生成绩查询界面\t\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询单个学生成绩" << endl; cout << "\t\t\t\t\t\t2.查询全体学生成绩" << endl; cout << "\t\t\t\t\t\t3.返回教师功能界面" << endl; cout << "\t\t\t\t\t\t4.返回登陆界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //学生成绩查询界面 void studentBasicInfoSearchForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到学生信息查询界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询单个学生信息" << endl; cout << "\t\t\t\t\t\t2.生成全体学生信息" << endl; cout << "\t\t\t\t\t\t3.返回学生信息管理界面" << endl; cout << "\t\t\t\t\t\t4.返回登陆界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //教师信息查询界面 void teacherBasicInfoSearchForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到教师信息查询界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询单个教师信息" << endl; cout << "\t\t\t\t\t\t2.生成全体教师信息" << endl; cout << "\t\t\t\t\t\t3.返回教师信息管理界面" << endl; cout << "\t\t\t\t\t\t4.返回登陆界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //课程信息查询界面 void classBasicInfoSearchForm() { cout << endl; cout << "************************************************************************************************************************" << endl; cout << "*\t\t\t\t\t 欢迎来到课程信息查询界面\t\t\t\t\t *" << endl; cout << "************************************************************************************************************************" << endl; cout << "\t\t\t\t\t\t1.查询单个课程信息" << endl; cout << "\t\t\t\t\t\t2.生成全体课程信息" << endl; cout << "\t\t\t\t\t\t3.返回课程信息管理界面" << endl; cout << "\t\t\t\t\t\t4.返回登陆界面" << endl; cout << "\t\t\t\t\t\t5.退出" << endl; cout << "输入对应的数字进行相关操作: "; } //学生信息保存到文件中 void writeDataS(student * s, int studentNum) { for (int i = 0; i < studentNum; i++) { s[i].writeToTxtFileS(); } } //读取学生信息 void readDataS(student * s, int studentNum) { for (int i = 0; i < studentNum; i++) { s[i].readFromTxtFileS(i + 1); } } //删除学生信息 void deleteStudentTxtInfo() { ofstream output("studentBasicInfo.txt"); output.close(); } //输入老师信息 void writeDataT(teacher * t, int teacherNum) { for (int i = 0; i < teacherNum; i++) { t[i].writeToTxtFileT(); } } //读取老师信息 void readDataT(teacher * t, int teacherNum) { for (int i = 0; i < teacherNum; i++) { t[i].readFromTxtFileT(i + 1); } } //删除老师信息 void deleteTeacherTxtInfo() { ofstream output("teacherBasicInfo.txt"); output.close(); } //写入管理信息 void writeDataG(gradeInfo * g, int courseNum) { for (int i = 0; i < courseNum; i++) { g[i].writeToTxtFileG(i); } } //读取管理信息 void readDataG(gradeInfo * g, int courseNum) { for (int i = 0; i < courseNum; i++) { g[i].readFromTxtFileG(i); } } //文件写入管理密码 void writeDataA(systemAdmin * a, int systemAdminNum) { for (int i = 0; i < systemAdminNum; i++) { a[i].writeToTxtFileA(); } } //读取管理密码信息 void readDataA(systemAdmin * a, int systemAdminNum) { for (int i = 0; i < systemAdminNum; i++) { a[i].readFromTxtFileA(i + 1); } } //管理员密码文件 void deleteSystemAdminTxtInfo() { ofstream output("systemAdminBasicInfo.txt"); output.close(); } //写入课程信息 void writeDataC(classInfo * c, int courseNum) { for (int i = 0; i < courseNum; i++) { c[i].writeToTxtFileC(); } } //读取课程信息 void readDataC(classInfo * c, int courseNum) { for (int i = 0; i < courseNum; i++) { c[i].readFromTxtFileC(i + 1); } } //删除课程信息 void deleteCourseTxtInfo() { ofstream output("classBasicInfo.txt"); output.close(); } //在文件中写入学生数目,课程数目,老师数目,系统管理原数目 void writeAllNumToFile(int studentNum, int courseNum, int teacherNum, int systemAdminNum) { ofstream output("allNum.txt"); output << studentNum << " " << courseNum << " " << teacherNum << " " << systemAdminNum << endl; output.close(); } //从文件读取学生数目,课程数目,老师数目,系统管理原数目 void readAllNumFromFile(int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum) { ifstream input("allNum.txt"); input >> studentNum >> courseNum >> teacherNum >> systemAdminNum; input.close(); } //返回上虞界面; void enter0ToBack(int& num) { cout << "按0键返回上一层: "; cin >> num; while(num != 0) { cout << "指令无效,请输入0返回上一层: "; cin >> num; } } //按照课程信息查找成绩 void studentSearchGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3) { cout << endl << "请输入课程编号来查询相应课程成绩: "; cin >> tempCourseNumber ; for (int j = 0; j < courseNum; j++)//多层循环不可通用一个变量 { if (tempCourseNumber == g[j].getCourseNumber() && isInThisCourse(g, tempCourseNumber, userName, courseNum)) { cout << endl << "\t\t课程编号:" << tempCourseNumber << " 课程名称:" << c[j].getCourseName() << " 课程学分:" << c[j].getCredit(); g[j].searchSingleGrade(userName); flag3++; } } if (flag3 == 0) cout << "课程编号输入错误,您无此课程!!!" << endl; } //按照课程编号和学生学号查询学生信息 void teacherSearchSingleGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3, int& flag5) { cout << endl; cout << "请输入您要查询的课程的课程编号: "; cin >> tempCourseNumber; for (int j = 0; j < courseNum; j++) { if (tempCourseNumber == c[j].getCourseNumber() && userName == c[j].getJobNumberOfTeacher()) { cout << "请输入您要查询学生的学号 : "; cin >> tempStudentNumber; if (isInThisCourse(g, tempCourseNumber, tempStudentNumber, courseNum)) { cout << endl; cout << "\t\t课程编号:" << tempCourseNumber << " 课程名称:" << c[j].getCourseName() << " 课程学分:" << c[j].getCredit(); g[j].searchSingleGrade(tempStudentNumber); flag5++; } flag3++; } } if (flag3 == 0) cout << "输入课程编码错误,您没有这堂课,请重新进行操作!" << endl; if (flag3 != 0 && flag5 == 0) cout << "您没有学生是这个学号,请重新操作!!!" << endl; } //查询所有课程 void teacherSearchAllGrade(classInfo * c, gradeInfo * g, student * s, int courseNum, int studentNum, int& flag3) { cout << endl; cout << "请输入您要查询的课程的课程编码: "; cin >> tempCourseNumber; cout << endl; for (int j = 0; j < courseNum; j++) { if (tempCourseNumber == c[j].getCourseNumber() && userName == c[j].getJobNumberOfTeacher()) { cout << "课程编号: " << tempCourseNumber << " 课程名称: " << c[j].getCourseName() << " 课程学分: " << c[j].getCredit() << endl; g[j].searchAllGrade(s, studentNum); flag3++; } } if (flag3 == 0) cout << "输入课程编码错误,您没有这堂课,请重新进行操作!" << endl; } //输入课程 void teacherIuputGrade(classInfo * c, gradeInfo * g, int courseNum, int& flag3) { cout << endl; cout << "请输入课程编号 : "; cin >> tempCourseNumber; cout << endl; for (int j = 0; j < courseNum; j++) { if (tempCourseNumber == c[j].getCourseNumber() && userName == c[j].getJobNumberOfTeacher()) { g[j].setGrade(); writeDataG(g, courseNum); flag3++; } } if (flag3 == 0) cout << "输入课程编码错误,您没有这堂课,请重新进行操作!" << endl; } //录入学生信息 void systemAdminInputSBasicInfo(student * s, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i) { cout << "请开始录入学生信息: " << endl; a[i].inputStudentBasicInfo(s, studentNum); deleteStudentTxtInfo(); writeDataS(s, studentNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); } //查询学生信息 void systemAdminSearchSingleSBasicInfo(student * s, int studentNum, int& flag7) { cout << "请输入您要查询基本信息的学生的学号: "; cin >> tempStudentNumber; for (int j = 0; j < studentNum; j++) if (tempStudentNumber == s[j].getStudentNumber()) { s[j].searchBasicInfo(); flag7 ++; } if (flag7 == 0) cout << "抱歉,您输入的学号不存在,请仔细校对后再重新查询!" << endl; } void systemAdminSearchAllSBasicInfo(student * s, int studentNum) { cout << "如下是所有学生的基本信息: " << endl; for (int i = 0; i < studentNum; i++) { s[i].searchBasicInfo(); } cout << endl; } //删除学生的信息 void systemAdminDeleteSBasicInfo(systemAdmin * a, student * s, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i) { cout << "请输入要删除信息的学生的学号: "; cin >> tempStudentNumber; for (int j = 0; j < studentNum; j++) { if (tempStudentNumber == s[j].getStudentNumber()) { a[i].deleteStudentBasicInfo(s, tempStudentNumber, studentNum); deleteStudentTxtInfo(); writeDataS(s, studentNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); cout << "学生信息删除成功!!!" << endl; flag7++; } } if (flag7 == 0) cout << "您输入的学号不存在,请重新操作!!!" << endl; } //录入教师信息 void systemAdminInputTBasicInfo(teacher * t, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i) { cout << "请开始录入教师信息: " << endl; a[i].inputTeacherBasicInfo(t, teacherNum); deleteTeacherTxtInfo(); writeDataT(t, teacherNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); } // 查询教师基本信息 void systemAdminSearchSingleTBasicInfo(teacher * t, int teacherNum, int& flag7) { cout << "请输入您要查询基本信息的教师工号: "; cin >> tempJobNumber; for (int j = 0; j < teacherNum; j++) if (tempJobNumber == t[j].getJobNumber()) { t[j].searchBasicInfo(); flag7 ++; } if (flag7 == 0) cout << "抱歉,您输入的工号不存在,请仔细校对后再重新查询!" << endl; } //展示所有教师的基本信息 void systemAdminSearchAllTBasicInfo(teacher * t, int teacherNum) { cout << "如下是所有教师的基本信息: " << endl; for (int i = 0; i < teacherNum; i++) { t[i].searchBasicInfo(); } } //删除某教师的基本信息 void systemAdminDeleteTBasicInfo(systemAdmin * a, teacher * t, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i) { cout << "请输入要删除信息的教师的工号: "; cin >> tempJobNumber; for (int j = 0; j < teacherNum; j++) { if (tempJobNumber == t[j].getJobNumber()) { a[i].deleteTeacherBasicInfo(t, tempJobNumber, teacherNum); deleteTeacherTxtInfo(); writeDataT(t, teacherNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); cout << "删除成功!!!" << endl; flag7++; } } if (flag7 == 0) cout << "您输入的教师工号不存在,请重新操作!!!" << endl; } //录入课程信息 void systemAdminInputCBasicInfo(classInfo * c, systemAdmin * a, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int i) { cout << "请开始录入课程信息: " << endl; a[i].inputClassBasicInfo(c, courseNum); deleteCourseTxtInfo(); writeDataC(c, courseNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); } //查询课程基本信息 void systemAdminSearchSingleCBasicInfo(classInfo * c, int courseNum, int& flag7) { cout << "请输入您要查询基本信息的课程的课程编号: "; cin >> tempCourseNumber; for (int j = 0; j < courseNum; j++) if (tempCourseNumber == c[j].getCourseNumber()) { c[j].searchBasicInfo(); flag7 ++; } if (flag7 == 0) cout << "抱歉,您输入的课程编号不存在,请仔细校对后再重新查询!" << endl; } //展示所有课程的基本信息 void systemAdminSearchAllCBasicInfo(classInfo * c, int courseNum) { cout << "如下是所有课程的基本信息: " << endl; for (int i = 0; i < courseNum; i++) { c[i].searchBasicInfo(); } cout << endl; } //删除某课程信息 void systemAdminDeleteCBasicInfo(systemAdmin * a, classInfo * c, int& studentNum, int& courseNum, int& teacherNum, int& systemAdminNum, int& flag7, int i) { cout << "请输入要删除信息的课程的课程编号: "; cin >> tempCourseNumber; for (int j = 0; j < courseNum; j++) { if (tempCourseNumber == c[j].getCourseNumber()) { a[i].deleteClassBasicInfo(c, tempCourseNumber, courseNum); deleteCourseTxtInfo(); writeDataC(c, courseNum); writeAllNumToFile(studentNum, courseNum, teacherNum, systemAdminNum); cout << "课程信息删除成功!!!" << endl; flag7++; } } if (flag7 == 0) cout << "您输入的课程编号不存在,请重新操作!!!" << endl; } //展示学生选课信息 void generateSSelectionInfo(classInfo * c, gradeInfo * g, student * s, int courseNum, int studentNum) { cout << "学生选课信息如下: " << endl << endl; for (int j = 0; j < studentNum; j++) { cout << "学号 :" << s[j].getStudentNumber() << " 姓名 :" << s[j].getName() << endl; for (int k = 0; k < courseNum; k++) { if (isInThisCourse(g, c[k].getCourseNumber(), s[j].getStudentNumber(), courseNum)) c[k].searchBasicInfo(); } cout << endl; } } //判断老师是否带这门课 bool isTeacherClass(classInfo * c, string courseNumber, string userName, int courseNum) { for (int i = 0; i < courseNum; i++) if(c[i].getJobNumberOfTeacher() == userName && courseNumber == c[i].getCourseNumber()) { return true; break; } } //判断学生是否有这门课 bool isInThisCourse(gradeInfo * g, string courseNumber, string studentNumber, int courseNum) { bool temp = false; for (int i = 0; i < courseNum; i++) { if(g[i].isStudentHere(studentNumber) && courseNumber== g[i].getCourseNumber()) temp = true; } return temp; }
加载全部内容