大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE稳定放心使用
目录
6.源代码
1.系统分析
本系统的用户分为普通用户和管理员两类,其中普通用户包括教师和学生。普通用户只能对自己的信息进行查询与修改,管理员则拥有所有功能权限。
1.1模块划分
学生选课系统,在登录模块之后,根据系统用户的身份不同划分为三个模块,即:学生模块、教师模块和管理员模块。
1.2功能模块描述
(1)登录模块
登录模块用于用户身份选择与用户登录,完成基本的验证。根据所填信息进行判断,提示“登录成功”、“用户名不存在”或者“密码错误”的信息。
(2)学生模块
学生登录之后,可以查看课程、选课以及修改密码等功能。
(3)教师模块
教师登录之后,可以查看自己所教课程的信息,以及选择该课程的学生信息,可以修改个人密码。
(4)管理员模块
管理员登录之后,可以对该系统进行管理,原则上拥有所有用户的全部权限。主要功能有添加、修改及删除课程信息,设置选课、退课时间,查看课程信息和修改密码等。
2.系统设计
【系统流程图】
【类图】
3.文件说明
4.测试数据
(1)课程信息测试数据,见文件“Subject.txt”;
建议下列数据使用“添加课程”功能录入,每添加一门课程,会自动创建一个文件名为“课程编号”的txt文件。
说明:课程编号,课程名称,课程学分,已选此课的人数,课程最大人数容量,教师姓名,教师工号,课程类型
B06010900 数学建模 3 0 180 邢老师 t1003 理学与工学类
B12015700 交响乐鉴赏 2 5 160 刘老师 t1001 艺术与体育类
B13020820 社会心理学B 2 2 140 汪老师 t1002 教育与文学类
B15064100 普通话读说艺术 2 2 180 杨老师 t1005 哲学与社科类
B12082400 影视文化欣赏 2 2 180 刘老师 t1001 哲学与社科类
B27011700 教育心理学 2 2 180 王老师 t1007 教育与文学类
(2)学生信息测试数据,见文件“Student.txt”;
说明:学号,姓名,学院,专业,班级
1908010301 姓名01 信息学院 计算机 153
1908010302 姓名02 信息学院 计算机 153
1908010303 姓名03 信息学院 计算机 153
1908010304 姓名04 信息学院 计算机 153
1908010305 姓名05 信息学院 计算机 153
1908010306 姓名06 信息学院 计算机 153
1908010307 姓名07 信息学院 计算机 153
1908010308 姓名08 信息学院 计算机 153
(3)学生账号密码测试数据,见文件“studentIP.txt”;
说明:学生账号,密码
1908010301 123
1908010302 1234
1908010303 12345
1908010304 123456
1908010305 12345
1908010306 1234
1908010307 123
1908010308 12
(4)教师账号密码测试数据,见文件“TeacherIP.txt”;
说明:教师账号,密码
t1001 123
t1002 123
t1003 123
t1004 123
t1005 123
t1006 123
t1007 123
(5)管理员账号密码测试数据,见文件“ManagerIP.txt”;
说明:管理员账号,密码
m1 1236
m2 1236
(6)学生选课情况测试数据,保存于文件“StSubject.txt”;
说明:所有学生的学号,0
【注】:最开始需要把该文件初始化为“学号 0”的形式。意思为,改学生选课科目数为0。如下:
1908010301 0
1908010302 0
1908010303 0
1908010304 0
1908010305 0
1908010306 0
1908010307 0
1908010308 0
(7)选课时间测试数据,见文件“TimeSelect.txt”;
说明:选课开始的时间,选课结束的时间
2019 4 8
2019 4 11
(8)退课时间测试数据,见文件“TimeQuit.txt”。
说明:退课开始的时间,退课结束的时间
2019 4 8
2019 4 12
5.系统效果图【部分】
【登录】
【学生】
【教师】
【管理员】
6.源代码
【运行前需要自行新建所需文件,必要时自己加上测试数据】
【如果本博文对你有帮助,动动手指,点个赞呗,诚谢~】
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cstring>
#include <conio.h>
#include <ctime>
#include <iomanip>
using namespace std;
class Student;
//账号密码
class IdPw
{
public:
IdPw(){}
~IdPw(){}
string id; //账号
string password; //密码
IdPw *next;
};
//课程
class Subject
{
public:
Subject(){}
~Subject(){}
string subID; //课程号
string subName; //课程名
string subTearcherID; //任课教师工号
string subTeacher; //任课老师
string subCate; //课程类型
float mark; //学分
int maxNum; //课程最大容量
int okNum; //选此课的人数
Subject *next;
Student *head_SubSt; //选此课的学生信息
};
//基类
class Base
{
public:
Base(){}
~Base(){}
void readShowSub(); //显示可选课程
IdPw ip;
};
//学生
class Student : virtual public Base
{
public:
Student(){}
~Student(){}
void querySub(); //查询已选课程
void selecSub(); //选课
void quitSub(); //退课
void modifyPw(); //修改密码
int n; //已选课程数
string stNo; //学号
string name; //姓名
string college; //学院
string major; //专业
string clas; //班级
Student *next;
Subject *head_stSub; //所选课程
};
//教师
class Teacher : virtual public Base
{
public:
Teacher(){}
~Teacher(){}
void querySubInfo(); //查询所教课程信息
void modifyPw(); //修改密码
};
//管理员
class Manager : public Student, public Teacher
{
public:
Manager(){}
~Manager(){}
void addSub(); //添加课程
void deleteSub(); //删除课程
void modifySub(); //修改课程信息
void setSelSubTime(); //设置选课时间
void setQuitSubTime(); //设置退课时间
void modifyPwM(); //修改密码
void ShowSub();
void writeSub(Subject *head_sub);
void writeAddSub(Subject *p);
};
class Time
{
public:
int year;
int month;
int day;
};
/**声明对象**/
Student st;
Teacher tea;
Manager ma;
Time start, endt;
/** Base **/
//读取课程文件
Subject* readSub()
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
Subject *p, *q;
q = head_sub;
ifstream in("Subject.txt");
if (!in)
{
cout << "\n\n\t\t\t\tCan't open \"Subject.txt\"!";
exit(0);
}
p = new Subject;
while (in >> p ->subID >> p ->subName >> p ->mark >> p ->okNum >> p ->maxNum >> p ->subTeacher >> p ->subTearcherID >> p ->subCate)
{
p ->next = NULL;
q ->next = p;
q = p;
p = new Subject;
}
in.close();
return head_sub;
}//Base::readSub
//显示可选课程
void Base::readShowSub()
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
head_sub = readSub();
Subject *p = head_sub ->next;
cout << setiosflags(ios_base::left) << setw(4) << "序号" << setw(13) << " 课程编号" << setw(16) << " 课程名" << setw(6) << "学分" << setw(7) << "剩余" << setw(10) << "最大容量" << setw(10) <<"任课老师" << "课程属性\n";
cout << "===========================================";
cout << "====================================" << endl;
int i = 1;
while (p)
{
if (p ->maxNum - p ->okNum > 0)
cout << setiosflags(ios_base::left) << " " << setw(4) << i++ << setw(14) << p ->subID << setw(14) << p ->subName << setw(6) << p ->mark << setw(8) << p ->maxNum - p ->okNum << setw(10) << p ->maxNum << setw(10) << p ->subTeacher << setw(10) <<p ->subCate << endl << endl;
p = p ->next;
}
}//Base::readShowSub
//读取账号密码文件
IdPw * read(string fname)
{
IdPw *head_IP = new IdPw;
IdPw *q = head_IP;
ifstream in(fname);
if (!in)
{
cout << "Can't open the file!" << endl;
exit(0);
}
IdPw *p = new IdPw;
while (in >> p ->id >> p ->password)
{
p ->next = NULL;
q ->next = p;
q = p;
p = new IdPw;
}
in.close();
return head_IP;
}//read()
//写入账号密码文件
void write(IdPw *head_ip, string fname)
{
IdPw *p = head_ip ->next;
head_ip ->next = NULL;
ofstream ou(fname);
if (!ou)
{
cout << "Can't open the file!" << endl;
exit(0);
}
while(p)
{
ou << p ->id << " " << p ->password << endl;
p = p ->next;
}
ou.close();
}//write
/** Student **/
//修改密码
void Student::modifyPw()
{
IdPw *head_ip = new IdPw;
head_ip ->next = NULL;
string pw1, pw2, pw3;
int flag = 1;
head_ip = read("studentIP.txt");
if (head_ip == NULL)
{
cout << "\n\n\t\t\t\t文件打开错误,密码修改失败!";
return ;
}
IdPw *p = head_ip ->next;
cout << "\n\t\t\t\t请输入原密码:";
cin >> pw1;
cout << "\n\n\t\t\t\t请输入新密码:";
cin >> pw2;
cout << "\n\n\t\t\t\t再次输入新密码:";
cin >> pw3;
p = head_ip ->next;
while (p)
{
if (p ->id == st.ip.id)
{
if (p ->password == pw1)
{
if (pw2 == pw3)
{
p ->password = pw2;
cout << "\n\n\t\t\t\t密码修改成功!";
cout << " *按Enter键返回!*" << endl;
write(head_ip, "studentIP.txt");
}
else
{
cout << "\n\n\t\t\t\t两次新密码不一致!";
}
flag = 0;
}
}
if (flag == 0)
break;
p = p ->next;
}
if (flag == 1)
cout << "\n\n\t\t\t\t原密码输入错误!";
}//Student::modifyPw()
//读取选课时间
void readTime1()
{
ifstream in("TimeSelect.txt");
if (!in)
{
cout << "Can't open \"TimeSelect.txt\"!";
exit(0);
}
in >> start.year >> start.month >> start.day;
in >> endt.year >> endt.month >> endt.day;
}//readTime1()
//读取退课时间
void readTime2()
{
ifstream in("TimeQuit.txt");
if (!in)
{
cout << "Can't open \"TimeQuit.txt\"!";
exit(0);
}
in >> start.year >> start.month >> start.day;
in >> endt.year >> endt.month >> endt.day;
}//readTime2()
/** 计算两个日期的“时间差” **/
int diffDay(Time t1, Time t2)
{
if (t1.month == t2.month)
return t2.day-t1.day;
return 31-t1.day+t2.day;
}//diffDay(Time t1, Time t2)
/** 读取学生-课程信息文件 **/
Student* readStSub()
{
Student *head_st = new Student;
head_st ->next = NULL;
Student *p, *q;
p = new Student;
q = head_st;
q ->next = NULL;
p ->head_stSub = new Subject;
p ->head_stSub ->next = NULL;
Subject *s, *t;
t = p ->head_stSub;
t ->next = NULL;
// 读取学生选课文件
ifstream in("StSubject.txt");
if (!in)
{
cout << "Can't open \"StSubject.txt\"!";
exit(0);
}
while (in >> p ->stNo >> p ->n)
{
for (int i = 0; i < p ->n; i++)
{
s = new Subject;
in >> s ->subID;
s ->next = NULL;
t ->next = s;
t = s;
}
p ->next = NULL;
q ->next = p;
q = p;
p = new Student;
p ->head_stSub = new Subject;
t = p ->head_stSub;
t ->next = NULL;
}//while
in.close();
return head_st;
}//readStSub()
/** 更新学生-课程信息文件 **/
void writeStSub(Student *head_st)
{
Student *p;
Subject *s;
ofstream ou2("StSubject.txt");
if (!ou2)
{
cout << "Can't open \"StSubject.txt\"!";
exit(0);
}
p = head_st ->next;
while (p)
{
//该学生所选的课程数加一
if (p ->stNo == st.ip.id)
p ->n++;
ou2 << p ->stNo << " " << p ->n;
s = p ->head_stSub ->next;
while (s)
{
ou2 << " " << s ->subID;
s = s ->next;
}
ou2 << endl;
p = p ->next;
}
ou2.close();
}//writeStSub()
/** 学生选课 **/
void Student::selecSub()
{
//判断是否是选课时间
Time nowTime;
time_t t = time(NULL);
tm *tt = localtime(&t);
nowTime.year = tt ->tm_year+1900;
nowTime.month = tt ->tm_mon+1;
nowTime.day = tt ->tm_mday;
readTime1();
int x = diffDay(start, endt);
int y = diffDay(start, nowTime);
if (x >= y)
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
head_sub = readSub();
Subject *a = head_sub ->next;
//显示可选课程
readShowSub();
int c;
cout << "\n 请输入要选择的课程(序号):";
cin >> c;
//根据输入的序号定位课程
int i = 1;
int flag = 0;
while (a)
{
if (c == i)
{
flag = 1;
break;
}
if (a ->maxNum - a ->okNum > 0)
i++;
a = a ->next;
}
if (flag == 1)
{
/** 判断是否已选此课,并更新信息 **/
Student *head_st = new Student;
head_st ->next = NULL;
head_st = readStSub();
Student *p;
p = new Student;
p ->head_stSub = new Subject;
p ->next = NULL;
Subject *s, *t;
//判断该学生本学期是否已选本课程
int flag1 = 0, flag2 = 1;
p = head_st ->next;
while (p)
{
if (p ->stNo == st.ip.id)
{
flag1 = 1;
s = p ->head_stSub ->next;
t = p ->head_stSub;
while (s)
{
if (s ->subID == a ->subID)
{
flag2 = 0;
break;
}
t = s;
s = s ->next;
}
break;
}//if
p = p ->next;
}//while
//更新学生-课程文件
if (flag1 == 1 && flag2 == 1)
{
//将新选课程加入链表
s = new Subject;
s ->subID = a ->subID;
s ->next = NULL;
t ->next = s;
writeStSub(head_st);
//修改课程信息
a ->okNum++;
ma.writeSub(head_sub);
//更新课程_学生信息
Student *head_st2 = new Student;
Student *e = new Student, *r;
r = head_st2;
r ->next = NULL;
//读取学生基本信息
ifstream in2("Student.txt");
if (!in2)
{
cout << "Can't open \"Student.txt\"!";
exit(0);
}
while (in2 >> e ->stNo >> e ->name >> e ->college >> e ->major >> e ->clas)
{
e ->next = NULL;
r ->next = e;
r = e;
e = new Student;
}
in2.close();
//将学生信息加入到课程-学生文件
r = head_st2 ->next;
while (r)
{
if (r ->stNo == st.ip.id)
break;
r = r ->next;
}
string ssss = a ->subID + ".txt";
ofstream ou(ssss, ios::app);
if (!ou)
{
cout << "Can't open \"" << ssss << "\"!";
exit(0);
}
ou << r ->stNo << " " << r ->name << " " << r ->college << " " << r ->major << " " << r ->clas << endl;
ou.close();
cout << "选课成功!";
cout << " *按Enter键返回!*" << endl;
}//if
else
{
cout << " 你本学期已选本课程!" << endl;
}
}//if
else
{
cout << " 输入错误!" << endl;
}
}//if (x >= y)
else
cout << "现在不是选课时间!";
}//Student::selecSub()
/** 查看已选课程 **/
void Student::querySub()
{
Subject *head_Sub = new Subject;
head_Sub ->next = NULL;
Subject *p, *s;
Student *head_st =new Student;
head_st ->next = NULL;
Student *sp;
head_Sub = readSub();
head_st = readStSub();
sp = head_st ->next;
int i = 1;
cout << "序号 课程号 " << " 课程名 " << " 学分 " << " 任课教师 " << " 课程属性" << endl;
cout << "===========================================";
cout << "===================================" << endl;
while (sp)
{
if (sp ->stNo == st.ip.id)
{
s = sp ->head_stSub ->next;
while (s)
{
p = head_Sub;
while (p)
{
if (p ->subID == s ->subID)
{
cout << " " << setiosflags(ios_base::left) << setw(6) << i++ << setw(13) << p ->subID << setw(18) << p ->subName << setw(6) << p ->mark << setw(10) << p ->subTeacher << p ->subCate << endl << endl;
break;
}
p = p ->next;
}//while
s = s ->next;
}//while
break;
}//if
sp = sp ->next;
}//while
}//Student::querySub()
/** 读取课程-学生文件 **/
Student * readSubSt(string s)
{
Student *head = new Student;
Student *r = new Student, *q;
q = head;
q ->next = NULL;
ifstream in(s);
if (!in)
{
cout << "Can't open \"" << s << "\"!";
exit(0);
}
while (in >> r ->stNo >> r ->name >> r ->college >> r ->major >> r ->clas)
{
r ->next = NULL;
q ->next = r;
q = r;
r = new Student;
}
in.close();
return head;
}//readSubSt
/** 退课 **/
void Student::quitSub()
{
//判断是否是选课时间
Time nowTime;
time_t t = time(NULL);
tm *tt = localtime(&t);
nowTime.year = tt ->tm_year+1900;
nowTime.month = tt ->tm_mon+1;
nowTime.day = tt ->tm_mday;
readTime2();
int x = diffDay(start, endt);
int y = diffDay(start, nowTime);
if (x >= y)
{
//显示已选课程
querySub();
int c;
cout << "请选择退选课的序号:";
cin >> c;
//定位课程
Student *head_st = new Student;
head_st ->next = NULL;
Student *p;
head_st = readStSub();
int i = 1;
Subject *s;
string subId;
p = head_st ->next;
while (p)
{
if (p ->stNo == st.ip.id)
{
s = p ->head_stSub ->next;
while (s)
{
i++;
s = s ->next;
}
break;
}
}//while
if (c <= i && c > 0)
{
i = 1;
//更新学生-课程文件
ofstream ou("StSubject.txt");
if (!ou)
{
cout << "Can't open \"StSubject.txt\"!";
exit(0);
}
p = head_st ->next;
while (p)
{
if (p ->stNo == st.ip.id)
{
p ->n--;
ou << p ->stNo << " " << p ->n;
s = p ->head_stSub ->next;
while (s)
{
if (i != c)
ou << " " << s ->subID;
else
subId = s ->subID;
i++;
s = s ->next;
}
}//if
else
{
ou << p ->stNo << " " << p ->n;
s = p ->head_stSub ->next;
while (s)
{
ou << " " << s ->subID;
s = s ->next;
}
}
ou << endl;
p = p ->next;
}//while
ou.close();
//更新课程文件
Subject *head_sub = new Subject;
head_sub ->next = NULL;
head_sub = readSub();
s = head_sub ->next;
while (s)
{
if (s ->subID == subId)
{
s ->okNum--;
break;
}
s = s ->next;
}
ofstream ou2("Subject.txt");
if (!ou2)
{
cout << "Can't open the file!";
exit(0);
}
s = head_sub ->next;
while (s)
{
ou2 << s ->subID << " " << s ->subName << " " << s ->mark << " " << s ->okNum << " " << s ->maxNum << " " << s ->subTeacher << " " << s ->subTearcherID << " " << s ->subCate << endl;
s = s ->next;
}
ou2.close();
//更新课程-学生文件
Student *head_st2 = new Student;
head_st2 ->next = NULL;
string sss = subId + ".txt";
head_st2 = readSubSt(sss);
ofstream ou3(sss);
if (!ou3)
{
cout << "Can't open the file!";
exit(0);
}
p = head_st2 ->next;
while (p)
{
if (p ->stNo != st.ip.id)
ou << p ->stNo << " " << p ->name << " " << p ->college << " " << p ->major << " " << p ->clas << endl;
p = p ->next;
}
ou3.close();
cout << "退课成功!";
cout << " *按Enter键返回!*" << endl;
}//if
else
{
cout << "输入错误!";
}
}//if
else
{
cout << "现在不是退课时间!";
}
}//Student::quitSub()
/** Teacher **/
//修改密码
void Teacher::modifyPw()
{
IdPw *head_ip = new IdPw;
head_ip ->next = NULL;
string pw1, pw2, pw3;
int flag = 1;
head_ip = read("TeacherIP.txt");
if (head_ip == NULL)
{
cout << "\n\n\t\t\t\t文件打开错误,密码修改失败!";
return ;
}
IdPw *p = head_ip ->next;
cout << "\n\t\t\t\t请输入原密码:";
cin >> pw1;
cout << "\n\n\t\t\t\t请输入新密码:";
cin >> pw2;
cout << "\n\n\t\t\t\t再次输入新密码:";
cin >> pw3;
p = head_ip ->next;
while (p)
{
if (p ->id == tea.ip.id)
{
if (p ->password == pw1)
{
if (pw2 == pw3)
{
p ->password = pw2;
cout << "\n\n\t\t\t\t密码修改成功!";
write(head_ip, "TeacherIP.txt");
}
else
{
cout << "\n\n\t\t\t\t两次新密码不一致!";
}
flag = 0;
}//if
}
if (flag == 0)
break;
p = p ->next;
}
if (flag == 1)
cout << "\n\n\t\t\t\t原密码输入错误!";
}//Teacher::modifyPw
/** 查询所教课程信息 **/
void Teacher::querySubInfo()
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
Student *head_SubSt = new Student;
head_SubSt ->next = NULL;
head_sub = readSub();
Subject *p = head_sub ->next;
cout << " 序号" << " 课程编号\t" << "课程名\t" << " 学分 " << "选课人数" << " 最大容量 " << "任课老师" << " 课程属性\n";
cout << "===========================================";
cout << "===================================" << endl;
int i = 1;
while (p)
{
if (p ->subTearcherID == tea.ip.id)
cout << setw(3) << i++ << "."<< setw(13) << p ->subID << setw(15) << p ->subName << setw(4) << p ->mark << setw(8) << p ->okNum << setw(12) << p ->maxNum << setw(12) << p ->subTeacher << p ->subCate << endl << endl;
p = p ->next;
}
string c;
cout << "\n *1-查看详细信息 0-返回*" << endl << endl;
cout << " 请选择:";
cin >> c;
cout << endl;
if (c == "1")
{
cout << " *请选择科目序号: ";
int c2, t = 1;
cin >> c2;
int flag = 0;
p = head_sub ->next;
while (p)
{
if (tea.ip.id == p ->subTearcherID)
{
if (t == c2)
{
flag = 1;
break;
}
t++;
}
p = p ->next;
}
if (flag == 1)
{
string subId = p ->subID + ".txt";
head_SubSt = readSubSt(subId);
Student *head_new = new Student, *p1, *t, *r, *s;
p1 = head_new ->next = head_SubSt ->next;
p1 = p1 ->next;
head_new ->next ->next = NULL;
while (p1)
{
t = p1 ->next;
r = head_new ->next;
s = head_new;
while (r!=NULL && p1 ->stNo > r ->stNo)
{
s = r;
r = r ->next;
}
s ->next = p1;
p1 ->next = r;
p1 = t;
}
cout << "序号 " << " 学号 " << " 姓名 " << " 学院 " << " 专业班级" << endl;
cout << "===========================================";
cout << "===================================" << endl;
int t2 = 1;
Student *sp = head_new ->next;
while (sp)
{
cout << " " << setiosflags(ios_base::left) << setw(6) << t2++ << setw(12) << sp ->stNo << setw(10) << sp ->name << setw(12) << sp ->college << sp ->major << sp ->clas << endl << endl;
sp = sp ->next;
}
}//if
else
{
cout << "*输入错误! ";
}
}//if
else if (c != "0")
{
cout << "*输入错误! ";
}
cout << " 按Enter返回!";
}//Teacher::querySubInfo()
/** Manager **/
/** 写入课程文件 **/
void Manager::writeSub(Subject *head_sub)
{
Subject *p;
ofstream ou("Subject.txt");
if (!ou)
{
cout << "\n\n\t\t\t\tCan't open the file!";
exit(0);
}
p = head_sub ->next;
while (p)
{
ou << p ->subID << " " << p ->subName << " " << p ->mark << " " << p ->okNum << " " << p ->maxNum << " " << p ->subTeacher << " " << p ->subTearcherID << " " << p ->subCate << endl;
p = p ->next;
}
ou.close();
}//Manager::writeSub
/** 写入添加课程文件 **/
void Manager::writeAddSub(Subject *p)
{
ofstream ou("Subject.txt", ios::app);
if (!ou)
{
cout << "\n\n\t\t\t\tCan't open the file!";
exit(0);
}
ou << p ->subID << " " << p ->subName << " " << p ->mark << " " << p ->okNum << " " << p ->maxNum << " " << p ->subTeacher << " " << p ->subTearcherID << " " << p ->subCate << endl;
ou.close();
}//Manager::writeAddSub
/** 添加课程 **/
void Manager::addSub()
{
ifstream in("Subject.txt");
if (!in)
{
cout << "Can't open the file!\n";
exit(0);
}
Subject *head_sub = new Subject;
head_sub ->next = NULL;
head_sub = readSub();
Subject *q;
Subject *p = new Subject;
int y;
do
{
y = 0;
cout << "请输入课程号:";
cin >> p ->subID;
q = head_sub ->next;
while (q)
{
if (q ->subID == p ->subID)
{
y = 1;
cout << "该课程号已存在,请重新输入!" << endl;
break;
}
q = q ->next;
}
}while (y == 1);
cout << "请输入课程名:";
cin >> p ->subName;
cout << "请输入课程学分:";
cin >> p ->mark;
cout << "请输入最大学生容量:";
cin >> p ->maxNum;
cout << "请输入课程类型归属:";
cin >> p ->subCate;
cout << "请输入任课教师工号:";
cin >> p ->subTearcherID;
cout << "请输入任课教师姓名:";
cin >> p ->subTeacher;
p ->okNum = 0;
cout << "确定要添加此课程?\n";
cout << " 1-确定 0-取消\n";
cout << "请选择:";
int c;
cin >> c;
if (c == 1)
{
writeAddSub(p);
cout << "添加课程成功!";
}
string s = p ->subID + ".txt";
ofstream ou(s);
ou.close();
cout << " *按Enter键返回!*" << endl;
}//Manager::addSub()
/** 修改课程信息 **/
void Manager::modifySub()
{
ifstream in("Subject.txt");
if (!in)
{
cout << "Can't open the file!\n";
exit(0);
}
Subject *head_sub = new Subject;
head_sub ->next = NULL;
string s;
head_sub = readSub();
Subject *p = head_sub ->next;
int y = 1;
int choice;
while (y)
{
system("cls");
cout << " ------------------\n";
cout << " *选 课 系 统*\n";
cout << " *修改课程*\n";
cout << " ------------------\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " || 1-修改课程名 2-修改课程学分 ||\n\n";
cout << " || 3-修改课程容量 4-修改任课教师 ||\n\n";
cout << " || 5-修改课程归属 6-全部修改 ||\n\n";
cout << " || 0-退出修改 ||\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " 请输入所选择的序号:";
cin >> choice;
if(choice >= 0 && choice <= 6)
y = 0;
else
{
cout << " 输入错误,请重新输入!\n";
getchar();
getchar();
system("cls");
}//switch(choice)
}//while(y)
if (choice != 0)
{
cout << "请输入要修改课程的课程号:";
cin >> s;
}
p = head_sub ->next;
int flag = 1;
while (p)
{
if (p ->subID == s)
{
flag = 0;
break;
}
p = p ->next;
}
if (flag == 0)
{
int flag = 1;
switch(choice)
{
case 0: break;
case 1:
cout << "请输入修改后的课程名:";
cin >> p ->subName;
break;
case 2:
cout << "请输入修改后的课程学分:";
cin >> p ->mark;
break;
case 3:
cout << "请输入修改后的课程容量:";
cin >> p ->maxNum;
break;
case 4:
cout << "请输入修改后的任课教师工号:";
cin >> p ->subTearcherID;
cout << "请输入修改后的任课教师:";
cin >> p ->subTeacher;
break;
case 5:
cout << "请输入修改后的课程归属:";
cin >> p ->subCate;
break;
case 6:
cout << "请输入修改后的课程名:";
cin >> p ->subName;
cout << "请输入修改后的课程学分:";
cin >> p ->mark;
cout << "请输入修改后的课程容量:";
cin >> p ->maxNum;
cout << "请输入修改后的任课教师工号:";
cin >> p ->subTearcherID;
cout << "请输入修改后的任课教师:";
cin >> p ->subTeacher;
break;
default :
flag = 0;
break;
}//switch
if (flag == 1)
{
cout << "\n确定要修改课程信息?";
cout << "\n 1-确定 0-取消\n";
cout << "请选择:";
int c;
cin >> c;
if (c == 1)
{
writeSub(head_sub);
cout << "修改课程成功!";
}
}
else
cout << "输入错误,修改失败!";
}//if
else if (choice == 0)
{
;
}
else
{
cout << "未找到此课程号对应的信息!";
getchar();
}
cout << " *按Enter键返回!*" << endl;
}//Manager::modifySub
/** 删除课程信息 **/
void Manager::deleteSub()
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
Subject *p, *q;
head_sub = readSub();
string s;
cout << "请输入要删除课程的课程号:";
cin >> s;
p = head_sub ->next;
q = head_sub;
int flag = 1;
while (p)
{
if (p ->subID == s)
{
flag = 0;
break;
}
q = p;
p = p ->next;
}
if (flag == 0)
{
cout << "要删除的课程信息为:\n";
cout << "课程号:" << p ->subID << endl;
cout << "课程名:" << p ->subName << endl;
cout << "任课教师:" << p ->subTeacher << endl << endl;
cout << "\n确定要修改课程信息?";
cout << "\n 1-确定 0-取消\n";
cout << "请选择:";
int c;
cin >> c;
if (c == 1)
{
q ->next = p ->next;
free(p);
writeSub(head_sub);
char sn[20];
int len = s.size();
for (int i = 0; i <= len; i++)
{
sn[i] = s[i];
}
strcat(sn, ".txt");
remove(sn);
cout << "\n删除成功!\n";
}//if
}//if
else
{
cout << "未找到该课程!";
getchar();
}
cout << " *按Enter键返回!*" << endl;
}//Manager::deleteSub
/**设置选课时间**/
void Manager::setSelSubTime()
{
cout << "选课开始时间\n";
cout << "年:"; cin >> start.year;
cout << "月:"; cin >> start.month;
cout << "日:"; cin >> start.day;
cout << "选课结束时间\n";
cout << "年:"; cin >> endt.year;
cout << "月:"; cin >> endt.month;
cout << "日:"; cin >> endt.day;
ofstream ou("TimeSelect.txt");
if (!ou)
{
cout << "Can't open \"TimeSelect.txt\"!";
exit(0);
}
ou << start.year << " " << start.month << " " << start.day << endl;
ou << endt.year << " " << endt.month << " " << endt.day << endl;
ou.close();
cout << "设置成功! *按Enter键返回!*" << endl;
}//Manager::setSelSubTime
/**设置选课时间**/
void Manager::setQuitSubTime()
{
cout << "退课开始时间\n";
cout << "年:"; cin >> start.year;
cout << "月:"; cin >> start.month;
cout << "日:"; cin >> start.day;
cout << "退课结束时间\n";
cout << "年:"; cin >> endt.year;
cout << "月:"; cin >> endt.month;
cout << "日:"; cin >> endt.day;
ofstream ou("TimeQuit.txt");
if (!ou)
{
cout << "Can't open \"TimeQuit.txt\"!";
exit(0);
}
ou << start.year << " " << start.month << " " << start.day << endl;
ou << endt.year << " " << endt.month << " " << endt.day << endl;
ou.close();
cout << "设置成功! *按Enter键返回!*" << endl;
}//Manager::setQuitSubTime
//修改密码
void Manager::modifyPwM()
{
IdPw *head_ip = new IdPw;
string pw1, pw2, pw3;
int flag = 1;
head_ip = read("ManagerIP.txt");
if (head_ip == NULL)
{
cout << "\n\n\t\t\t\t文件打开错误,密码修改失败!";
return ;
}
IdPw *p = head_ip ->next;
cout << "\n\t\t\t\t请输入原密码:";
cin >> pw1;
cout << "\n\n\t\t\t\t请输入新密码:";
cin >> pw2;
cout << "\n\n\t\t\t\t再次输入新密码:";
cin >> pw3;
p = head_ip ->next;
while (p)
{
if (p ->id == ma.ip.id)
{
if (p ->password == pw1)
{
if (pw2 == pw3)
{
p ->password = pw2;
cout << "\n\n\t\t\t\t密码修改成功!";
cout << " *按Enter键返回!*" << endl;
write(head_ip, "ManagerIP.txt");
}
else
{
cout << "\n\n\t\t\t\t两次新密码不一致!";
}
flag = 0;
}
}
if (flag == 0)
break;
p = p ->next;
}
if (flag == 1)
cout << "\n\n\t\t\t\t原密码输入错误!";
}//Manager::modifyPwM
void Manager::ShowSub()
{
Subject *head_sub = new Subject;
head_sub ->next = NULL;
head_sub = readSub();
Subject *p = head_sub ->next;
cout << setiosflags(ios_base::left) << setw(4) << "序号" << setw(13) << " 课程编号" << setw(16) << " 课程名" << setw(6) << "学分" << setw(7) << "剩余" << setw(10) << "最大容量" << setw(10) <<"任课老师" << "课程属性\n";
cout << "===========================================";
cout << "====================================" << endl;
int i = 1;
while (p)
{
cout << setiosflags(ios_base::left) << " " << setw(4) << i++ << setw(14) << p ->subID << setw(14) << p ->subName << setw(6) << p ->mark << setw(8) << p ->maxNum - p ->okNum << setw(10) << p ->maxNum << setw(10) << p ->subTeacher << setw(10) <<p ->subCate << endl << endl;
p = p ->next;
}
}//Manager::ShowSub()
/** load() **/
int key;
//登录界面
void loadMenu(int t)
{
char pw[20];
system("cls");
cout << "\n\n\n\n\n\n\n";
cout << " ╔*☆***◎***◇***☆*** 欢迎光临 ***☆***◇***◎***☆*╗\n";
cout << " ************************* 教 务 系 统 ************************\n\n";
cout << endl << endl;
cout << "\t\t\t\t请输入用户名:";
switch(t)
{
case 1: cin >> st.ip.id; break;
case 2: cin >> tea.ip.id; break;
case 3: cin >> ma.ip.id; break;
}
cout << "\n\t\t\t\t请输入密码: ";
int i = 0;
char c;
do
{
c = getch();
if (c == '\b')
{
cout << "\b";
cout << '\0';
i--;
cout << "\b";
}
else if (c != '\r')
{
cout << "*";
pw[i] = c;
i++;
}
}while (c != '\r');
pw[i] = '\0';
string pw1 = (string) pw;
switch(t)
{
case 1: st.ip.password = pw1; break;
case 2: tea.ip.password = pw1; break;
case 3: ma.ip.password = pw1; break;
}
}//loadMenu()
//学生登录
int load_student()
{
int flag = 0;
loadMenu(1);
ifstream in("studentIP.txt");
if (!in)
{
cout << "Can't open \"studentIP.txt\"!" << endl;
exit(0);
}
string ids, pws;
while (in >> ids >> pws)
{
if (ids == st.ip.id)
{
flag = 1;
break;
}
}
in.close();
if (flag == 0)
{
key = 0;
cout << "\n\n\t\t\t\t账号不存在!";
getchar();
getchar();
return 0;
}
if (pws == st.ip.password)
{
return 1;
}
return 0;
}//load_student()
//教师登录
int load_teacher()
{
int flag = 0;
loadMenu(2);
ifstream in("TeacherIP.txt");
if (!in)
{
cout << "Can't open \"TeacherIP.txt\"!" << endl;
exit(0);
}
string ids, pws;
while (in >> ids >> pws)
{
if (ids == tea.ip.id)
{
flag = 1;
break;
}
}
in.close();
if (flag == 0)
{
key = 0;
cout << "\n\n\t\t\t\t账号不存在!";
getchar();
getchar();
return 0;
}
if (pws == tea.ip.password)
{
return 1;
}
return 0;
}//load_teacher()
//管理员登录
int load_manager()
{
int flag = 0;
loadMenu(3);
ifstream in("ManagerIP.txt");
if (!in)
{
cout << "Can't open \"ManagerIP.txt\"!" << endl;
exit(0);
}
string ids, pws;
while (in >> ids >> pws)
{
if (ids == ma.ip.id)
{
flag = 1;
break;
}
}
in.close();
if (flag == 0)
{
key = 0;
cout << "\n\n\t\t\t\t账号不存在!";
getchar();
getchar();
return 0;
}
if (pws == ma.ip.password)
{
return 1;
}
return 0;
}//load_manager()
void Menu_Student()
{
int y = 1;
int choice;
while (y)
{
system("cls");
cout << " ------------------\n";
cout << " *选 课 系 统*\n";
cout << " ------------------\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " || 1-选课 2-查看可选课程 ||\n\n";
cout << " || 3-退课 4-查看已选课程 ||\n\n";
cout << " || 5-修改密码 0-退出系统 ||\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " 请输入所选择的序号:";
cin >> choice;
system("cls");
switch (choice)
{
case 0: y = 0; break;
case 1: st.selecSub(); getchar(); break;
case 2: st.readShowSub(); cout << "按Enter键返回!"; getchar(); break;
case 3: st.quitSub(); getchar(); break;
case 4: st.querySub(); cout << "按Enter键返回!"; getchar(); break;
case 5: st.modifyPw(); getchar(); break;
default:
cout << " 输入错误,请重新输入!\n";
getchar();
break;
}//switch(choice)
getchar();
}//while(y)
}//Menu_Student()
void Menu_Teacher()
{
int y = 1;
int choice;
while (y)
{
system("cls");
cout << " ------------------\n";
cout << " *选 课 系 统*\n";
cout << " ------------------\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " || 1-查看所教课程信息 2-修改密码 ||\n\n";
cout << " || 0-退出系统 ||\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " 请输入所选择的序号:";
cin >> choice;
system("cls");
switch (choice)
{
case 0: y = 0; break;
case 1: tea.querySubInfo(); getchar(); break;
case 2: tea.modifyPw(); getchar(); break;
default:
cout << " 输入错误,请重新输入!\n";
getchar();
break;
}//switch(choice)
getchar();
}//while(y)
}//Menu_Teacher()
void Menu_Manager()
{
int y = 1;
int choice;
while (y)
{
system("cls");
cout << " ------------------\n";
cout << " *选 课 系 统*\n";
cout << " ------------------\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " || 1-添加课程 2-修改课程信息 ||\n\n";
cout << " || 3-删除课程 4-修改密码 ||\n\n";
cout << " || 5-设置选课时间 6-设置退课时间 ||\n\n";
cout << " || 7-查看可选课程 0-退出系统 ||\n\n";
cout << " *******************************************\n\n";
cout << " *******************************************\n\n";
cout << " 请输入所选择的序号:";
cin >> choice;
system("cls");
switch (choice)
{
case 0: y = 0; break;
case 1: ma.addSub(); getchar(); break;
case 2: ma.modifySub(); getchar(); break;
case 3: ma.deleteSub(); getchar(); break;
case 4: ma.modifyPwM(); getchar(); break;
case 5: ma.setSelSubTime(); getchar(); break;
case 6: ma.setQuitSubTime(); getchar(); break;
case 7: ma.ShowSub(); cout << "*按Enter键返回!"; getchar(); break;
default:
cout << " 输入错误,请重新输入!\n";
getchar();
break;
}//switch(choice)
getchar();
}//while(y)
}//Menu_Manager()
//登录
void load()
{
int n;
int y = 1;
while (y)
{
key = 1;
system("cls");
cout << "\n\n\n\n\n\n\n";
cout << " ╔*☆***◎***◇***☆*** 欢迎光临 ***☆***◇***◎***☆*╗\n";
cout << " ************************* 教 务 系 统 ************************\n\n";
cout << endl << endl;
cout << " ============1-学生登录===========\n";
cout << " ============2-教师登录===========\n";
cout << " ============3-管理员登录=========\n";
cout << " ============0-退出系统===========\n";
cout << " 请输入您的选择:";
cin >> n;
cout << endl;
switch(n)
{
case 0: y = 0; break;
case 1: if (load_student() == 0 && key == 1)
{
cout << "\n\n\n\t\t\t\t密码输入错误!";
getchar();
getchar();
}
else if (key == 1)
{
cout << "\n\n\n\t\t\t\t登录成功,按Enter进入!";
getchar();
getchar();
Menu_Student();
}
break;
case 2: if(load_teacher() == 0 && key == 1)
{
cout << "\n\n\n\t\t\t\t密码输入错误!";
getchar();
getchar();
}
else if (key == 1)
{
cout << "\n\n\n\t\t\t\t登录成功,按Enter进入!";
getchar();
getchar();
Menu_Teacher();
}
break;
case 3: if(load_manager() == 0 && key == 1)
{
cout << "\n\n\n\t\t\t\t密码输入错误!";
getchar();
getchar();
}
else if (key == 1)
{
cout << "\n\n\n\t\t\t\t登录成功,按Enter进入!";
getchar();
getchar();
Menu_Manager();
}
break;
default : y = 1; cout << "\n\n\t\t\t\t输入错误!";
}//switch
}//while(y)
}//load()
int main()
{
load();
return 0;
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/181642.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...