简单版学生管理系统,c++,链表实现,如果你是计算机系的学生真的希望你不要完全复制,做下参考自己编写出来才能有所收获,这是对你的将来负责;
学生管理系统,主要划分为以下三个模块:
1) 学生:包括增加学生信息、删除学生信息、修改学生信息、查找学生信息、学生选课。
2) 课程:包括增加课程信息、删除课程信息、修改课程信息、查找课程信息。
3)拓展功能:文件导入,文件导出。
#include
#include
#include
using namespace std;
const int nubofCourse = 10;//学生最多可以选修的课程
typedef struct StudentMessage *sMessage;//学生结点指针类型
typedef struct Courses *sCourse;//课程结点指针类型
fstream foutint;//文件导入导出
/*课程结构体*/
struct Courses {
int stdCourstcount;
string cNo;
string cName;
string scTeacher;
string stdNo[nubofCourse];
sCourse cNext;
};
/*学生结构体*/
struct StudentMessage {
string sNo;//学号
string sClass;
string sName;
char sSex;
sMessage sNext;
};
typedef sMessage sm;//学生头指针类型
typedef sCourse sc;//课程头指针类型
/*关于我们,关于程序*/
void aboutMe() { //首页打印设置
string input;
cout << "\n\n\t\t\t*****************************\n";
cout << "\t\t\t 学生信息管理系统\n";
cout << "\t\t\t*****************************\n\n\n";
// cout<<"\n\t\t\t 欢迎来到学生信息管理系统\n\n";
cout << "--------------------------------------------------------------------------------\n";
cout << "\n\t\t\t拼搏到无能为力,\n"; cout << "\t\t\t\t 坚持到感动自己!\n";
cout << "\t 开发者:路ren甲\n\n"; cout << "\t 联系方式:QQ:1508287079 or Mail To:[email protected]\n";
cout << " \n--------------------------------------------------------------------------------\n";
//cout<<"\t______________________________________________________________________\n";
cout << "\t\t版权所有@路ren甲\n\n\n";
cout << "\t<输入任意字符进入>\n\t";
cin >> input; //让用户输入一个字符后再进行下一步
system("cls"); //清屏
}
//再见页面
void goodbye() { //首页打印设置
string input;
// cout<<"\n\t\t\t 欢迎来到学生信息管理系统\n\n";
cout << " \n\n\n\n\n\n\n\n--------------------------------------------------------------------------------\n";
cout << "\n\t\t可能程序还有许多不足,\n"; cout << "\t\t\t 希望大家可以提出或者修改!\n";
cout << "\t\t\t\t再见,遇见成功的自己!\n";
cout << " \n--------------------------------------------------------------------------------\n";
cout << "\t<输入任意字符关闭>\n\t";
cin >> input; //让用户输入一个字符后再进行下一步
exit(1); //清屏
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓课程函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
sc initC() {
sCourse chead;
chead = new Courses;
chead->cNext = NULL;
return chead;
}
//打印课程信息
int ptfselect_SCourse(sc head, string sId) {
int flags = 0;
if (head->cNext == NULL) { cout << "\n\t\t\t没有选到课喔……………!_!-_-\n"; return 1; }
cout << "\t\t课程编号" << "\t 课程名称" << "\t 开课老师" << endl;
//课程信息
head = head->cNext;
while (head != NULL) {
for (int l = 0; l < nubofCourse; l++) {
if (head->stdNo[l] == sId) {
flags = 1;
cout << "\t\t" << head->cNo << "\t\t" << head->cName << "\t\t" << head->scTeacher << "\t\n";
}
}
head = head->cNext;
}
if (flags == 0) { cout << "\n\t\t\t没有选到课喔……………!_!-_-\n"; }
cout << "\t\t----------------------------------------------------\n";
return 1;
}
int ptfSCourse(sc cHead) {
if (cHead->cNext == NULL) { cout << "没有课程信息\n"; return 0; }
//全部学生信息
cout << "\n\t\t课程编号" << "\t 课程名称" << "\t 开课老师" << endl;
cHead = cHead->cNext;
while (cHead != NULL) {
cout << "\t\t" << cHead->cNo << "\t\t" << cHead->cName << "\t\t" << cHead->scTeacher<< "\t\n";
cHead = cHead->cNext;
}
return 1;
}
void printfCourse(sc head, int i) {
//一个课程信息
int j;
sCourse find;
j = 0;
find = head->cNext;
cout << "\n\t\t课程编号" << "\t\t课程名称" << "\t\t开课老师" << endl;
while (find != NULL) {
j++; if (j == i) {
cout << "\t\t" << find->cNo << "\t\t" << find->cName << "\t\t" << find->scTeacher << "\t\n";
break;
}
find = find->cNext;
}
}
void pfCourse(sc head) {
cout << "\n\t\t课程编号" << "\t\t课程名称" << "\t\t开课老师" << endl;
cout << "\t\t" << head->cNo << "\t\t" << head->cName << "\t\t" << head->scTeacher << "\t\n";
cout << endl;
}
查找课程
int locateCourse(sc chead, string numb) {
int j = 0;
chead = chead->cNext;
while (chead != NULL) {
j++;//统计
if (numb == chead->cNo) {
return j;
}
chead = chead->cNext;
}
return 0;
}
添加课程
void addCourse(sc scHead) {
sc cnew;//新课程
int g = 0,k=0;
char flag = 'y';
while (flag == 'y') {
cnew = new Courses;
cnew->stdCourstcount = 0;
while (g==0) {
g = 1;
cout << "输入课程编号(六位数字):";
cin >> cnew->cNo;
if (locateCourse(scHead,cnew->cNo) != 0) { cout << "课程编号已经存在,请重新输入" << endl; g = 0; }
}
g = 0;
cout << "输入课程名称:";
cin >> cnew->cName;
cout<<"输入教师姓名:";
cin >> cnew->scTeacher;
cnew->cNext = scHead->cNext;
scHead->cNext = cnew;
cout << "您想继续进行添加吗?输入y继续,输入n退出" << endl;
cout << "输入你的选择(y/n):";
cin >> flag;
}
//system("cls");
cout << "已经添加课程信息成功\n" << endl;
}
//修改课程信息
int updatesCourse(sc chead) {
string fdc;
int k = 0;
if (chead->cNext == NULL) { cout << "没有课程数据,请添加课程" << endl; return 0; }
cout << "输入修改课程编号:";
cin >> fdc;
chead = chead->cNext;
while (chead != NULL) {
k++;//统计
if (fdc == chead->cNo) {
pfCourse(chead);
cout << "课程名称:";
cin >> chead->cName;
cout << "开课老师:";
cin >> chead->scTeacher;
cout << "修改课程" << chead->cNo << "信息成功!";
return k;
}
chead = chead->cNext;
}
return 0;
}
int deletesCourse(sc cHead) {
string del;
char flag;
int f = 0;
sCourse deletestd,preform;
int j = 0;
if (cHead->cNext == NULL) { cout << "没有课程数据,请添加课程" << endl; return 0; }
preform = cHead;
deletestd = cHead->cNext;//从首节点开始扫描
cout << "输入删除课程编号:";
cin >> del;//删除课程
while (deletestd != NULL) {
f = 0;
j++;
if (deletestd->cNo==del) {
pfCourse(deletestd);
cout << "是否删除该课程(y/n),输入你的选择:";
cin >> flag;
if (flag == 'y') {
cout << "删除课程" << deletestd->cName << "成功!";
preform->cNext = deletestd->cNext;
delete deletestd;
return j;
}
else {
cout << "你已经取消删除" << deletestd->cNext->cName << endl;
return 0;
}
}
preform=preform->cNext;
deletestd = deletestd->cNext;
f = 1;
}
if (f == 1) { cout << "不存在该学生找到了"; }
return 0;//不存在该学生找到了
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓学生函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
/*初始化*/
sm init() {
sMessage shead;
shead = new StudentMessage;
shead->sNext = NULL;
return shead;
}
//打印学生信息
void printfSMessge(sm head, sc cHead) {
sm find2;
string fc;
int i = 0;
if (head == NULL) cout << "没有学生信息";
find2 = head->sNext;
//全部学生信息
head = head->sNext;
while (head != NULL) {
cout << "\t\t---------------------第"<<++i<<"位--------------------------\n";
cout << "\t\t\t\t姓名:" << head->sName << "\t\n";
if (head->sSex == '1') {
cout << "\t\t\t\t性别:男" << "\t\n";
}
else if (head->sSex == '0') {
cout << "\t\t\t\t性别:女" << "\t\n";
}
cout << "\t\t\t\t学号:" << head->sNo << "\t\n";
cout << "\t\t\t\t班级:" << head->sClass << "\t\n";
cout << "\n\t\t\t选修课程:\n";
if (find2 != NULL) {
fc =find2->sNo;
ptfselect_SCourse(cHead, fc);//输出学生选课
}
find2 = find2->sNext;
head = head->sNext;
}
}
void printfPerson(sm head, int i,sc cHead) {
//一个学生信息
int j;
string fc;
sMessage find, find2;
//if(i==0) return head;
// if(i<0) return ;//位置非法。无此结节点
j = 0;
find = head->sNext;
find2 = head->sNext;
while (find != NULL){
j++; if (j == i) {
cout << "\t\t----------------------------------------------------\n";
cout << "\t\t\t\t姓名:" << find->sName << "\t\n";
if (find->sSex == '1') {
cout << "\t\t\t\t性别:男" << "\t\n";
}
else if (find->sSex == '0') {
cout << "\t\t\t\t性别:女" << "\t\n";
}
cout << "\t\t\t\t学号:" << find->sNo << "\t\n";
cout << "\t\t\t\t班级:" << find->sClass << "\t\n";
cout << "\n\t\t\t选修课程:\n";
while (find2 != NULL) {
fc = find2->sNo;
if(ptfselect_SCourse(cHead, fc)==1) break;//输出学生选课
}
break;
}
find2 = find2->sNext;
find = find->sNext;
}
}
void pfPerson(sm head) {
cout << "\t\t----------------------------------------------------\n";
cout << "\t\t\t\t姓名:" << head->sName << "\t\n";
if (head->sSex == '1') {
cout << "\t\t\t\t性别:男" << "\t\n";
}
else if (head->sSex == '0') {
cout << "\t\t\t\t性别:女" << "\t\n";
}
cout << "\t\t\t\t学号:" << head->sNo << "\t\n";
cout << "\t\t\t\t班级:" << head->sClass << "\t\n";
cout << "\t\t----------------------------------------------------\n";
}
查找学生
int locateStdfByNo(sm sHead, string numb) {
int j = 0;
if (sHead->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; return NULL; }
sHead = sHead->sNext;
j = 0;
while (sHead != NULL) {
j++;//统计
if (numb==sHead->sNo) {
return j;
}
sHead = sHead->sNext;
}
return 0;
}
int locateByName(sm sHead, string sname,sc cHead) {
int j = 0;
sm head=sHead;
if (sHead->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; return NULL; }
sHead = sHead->sNext;
while (sHead != NULL) {
j++;
if (sHead->sName == sname) { printfPerson(head, j, cHead);
}
sHead = sHead->sNext;
}
return 0;
}
//添加学生
void addStudent(sm sHead) {
sMessage snew;//新学生
int f = 1,g=0;
char flag = 'y';
while (flag == 'y') {
snew = new StudentMessage;
while (f == 1) {//判断学号和输入学号
f = 0;
cout << "输入学号6位数字:";
cin >> snew->sNo;
if (locateStdfByNo(sHead, snew->sNo) != 0) { cout << "学号已经存在,请重新输入"<> snew->sName;
f = 1;
while(f==1){
f = 0;
cout << "输入性别选择<男:1><女:0>:";
cin >> snew->sSex;
if (snew->sSex!='1'&& snew->sSex != '0'&&f==0) { cout << "选择操作不对,请重新输入"<> snew->sClass;
snew->sNext = sHead->sNext;
sHead->sNext = snew;
pfPerson(snew);
cout << "您想继续进行添加吗?输入y继续,输入n退出" << endl;
cout << "输入你的选择(y/n):";
cin >> flag;
}
//system("cls");
cout << "已经添加学生信息成功" << endl;
}
//修改学生信息
int updates(sm sHead) {
char flagc = 'y';
string numb;
int j = 0,f=1;
if (sHead->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; return 0; }
cout << "输入修改学生学号:";
cin >> numb;
sHead = sHead->sNext;
while (sHead != NULL) {
j++;//统计
if ( numb== sHead->sNo) {
pfPerson(sHead);
cout << "\n输入修改信息\n";
while (f == 1) {
f = 0;
cout << "输入性别选择<男:1><女:0>:";
cin >> sHead->sSex;
if (sHead->sSex != '1' && sHead->sSex != '0') { cout << "选择操作不对,请重新输入" << endl; f = 1; }
}
cout << "输入姓名:";
cin >> sHead->sName;
f = 1;
cout << "输入班级:";
cin >> sHead->sClass;
return j;
}
sHead = sHead->sNext;
}
return 0;
}
//删除
int deletesMessage(sm sHead) {
string numb;
char flag;
sMessage deletestd, preform;
int j = 0, i = 0;
if (sHead->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; return 0; }
preform = sHead;
deletestd = sHead->sNext;//从首节点开始扫描
cout << "输入删除学生学号:";
cin >> numb;
while (deletestd != NULL) {
j++;
if (deletestd->sNo==numb) {
pfPerson(deletestd);
cout << "是否删除该学生(y/n),输入你的选择:";
cin >> flag;
if (flag == 'y') {
cout << "你已经删除" << deletestd->sName << "成功!";
preform->sNext = deletestd->sNext;
delete(deletestd->sNext);
return j;
}
else {
cout << "你已经取消删除" << deletestd->sNext->sName;
return j;
}
}
preform = preform->sNext;
deletestd = deletestd->sNext;
i = 1;
}
if (i == 1) cout << "没有找到该学生!-_-!\n";
return 0;//不存在该学生找到了
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓选择排序↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
sMessage getminkey(sm p) {
sm minp, exchange, perfrom;
if (p->sNext == NULL) {
return p;
}
minp = p;
perfrom = p;
p = p->sNext;
while (p) {
if (minp->sNo>p->sNo) {
exchange = minp;
minp = p;
perfrom->sNext = p->sNext;
minp->sNext = exchange;//minp是较小值的指针
}
perfrom = p;
p = p->sNext;
}
return minp;//返回较小值的指针
}
sm selectsort(sm head, sm newHead) {
sm j, i, temp;
if (head->sNext == NULL || newHead == NULL) cout << "没有学生数据,请添加学生\n";
i = head;
j = newHead;
i = i->sNext;
while (i != NULL) {//尾插法
i = getminkey(i);
j->sNext = i;
temp = i->sNext;
i->sNext = NULL;
j = i;
i = temp;
}
head->sNext = newHead->sNext;
return newHead;
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓导出程序↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
void savePersonFile(sm student, sc course) {
ofstream *outfile[50], out;
int j = 0, k = 0;
//写入方式为追加
student = student->sNext;
course = course->cNext;
while (student != NULL) {
string str = "Project16";
//string i;
//ostringstream change;
str.append(student->sName);
//change << j;
//i = change.str();
//str.append(i);
str.append(".txt");
outfile[j] = new ofstream(str, ios::ate);
*outfile[j] << "\t\t\t\t学生信息:" << endl;
*outfile[j] << "\t\t学号:" << student->sNo << endl;
*outfile[j] << "\t\t姓名:" << student->sName << endl;
if (student->sSex = '1'){
*outfile[j] << "\t\t性别:" << "男" << endl;
}
else {
*outfile[j] << "\t\t性别:" << "女" << endl;
}
*outfile[j] << "\t\t班级:" << student->sClass << endl;
*outfile[j] << "\t\t\t\t选修课程:" << endl;
while (course != NULL) {
for (int l = 0; l < nubofCourse; l++) {
if (course->stdNo[l] == student->sNo) {
k = 1;
*outfile[j] << "\t\t课程名称:" << course->cName << endl;
*outfile[j] << "\t\t课程编号:" << course->cNo << endl;
*outfile[j] << "\t\t开课老师:" << course->scTeacher << endl;
}
}
course = course->cNext;
}
if (k == 0) *outfile[j] << "\t\t\t没有选修课程:" << endl;
student = student->sNext;
(*outfile[j]).close();
j++;
}
}
void saveCourseToLocal(sc head) {
ofstream outfile;
outfile.open("course.txt");
sc p;
p = head->cNext;
while (p != NULL) {
outfile << p->stdCourstcount << " ";
outfile << p->cNo << " ";
outfile << p->cName << " ";
outfile << p->scTeacher << "\n";
if(p->stdCourstcount>0){
for (int i = 0; i < p->stdCourstcount; i++) {
outfile << p->stdNo[i] << "\n";
}
}
p = p->cNext;
}
}
void readCourseFromLacal(sc head) {
fstream fin("course.txt");
if (fin)
{
sc p;
p = head;
sc q;
int stdCourstcount;
string scTeacher, cNo, cName,std;
while (fin >>stdCourstcount >> cNo >> cName >> scTeacher)
{
q = new Courses;
if (stdCourstcount > 0) {
for (int i = 0; i < stdCourstcount; i++) {
fin >>std;
q->stdNo[i] = std;
}
}
q->stdCourstcount = stdCourstcount;
q->cNo = cNo;
q->cName = cName;
q->scTeacher = scTeacher;
q->cNext = p->cNext;
p->cNext = q;
}
fin.close();
}
else
{
cerr << "打开文件失败!" << endl;
}
}
void saveStudentToLocal(sm head) {
ofstream outfile;
outfile.open("student.txt");
sm p;
p = head->sNext;
while (p != NULL) {
outfile << p->sNo << " ";
outfile << p->sName << " ";
outfile << p->sSex << " ";
outfile << p->sClass << "\n";
p = p->sNext;
}
outfile.close();
}
void readStudentFromLacal(sm head) {
fstream fin("student.txt");
if (fin)
{
sm p;
p = head;
sm q;
int rowNum = 0;
string sTel;
char sSex;
string sClass,sNo,sName;
while (fin >> sNo >> sName >> sSex >> sClass)
{
q = new StudentMessage;
q->sNo = sNo;
q->sName = sName;
q->sSex = sSex;
q->sClass = sClass;
q->sNext = p->sNext;
p->sNext = q;
}
fin.close();
}
else
{
cerr << "打开文件失败!" << endl;
}
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓学生选课相关函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
void stdSelectCourse(sc course, string select, string sNo) {
//select是课程编号,sNo选课学生学号
int k=0,j = 0;
int f = locateCourse(course, select);
course = course->cNext;
while (course != NULL) {
j++; if (j == f) {
for (int i = 0; i < course->stdCourstcount; i++) {
course->stdNo[course->stdCourstcount] = sNo;
cout << "你已经选择了"<cName<<"课程" << endl;
k = 1;
break;
}
if(k!=1){
course->stdNo[course->stdCourstcount++] = sNo;
cout << "\n\t\t\t"<stdNo[course->stdCourstcount - 1] << "恭喜你选课选课成功!";
}
break;
}
course = course->cNext;
}
}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓main函数↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓//
void main() {
int i;
char s1,c;
sm sort, newHead;
string sname;
string numb;
StudentMessage std;
int flag = 1, cflag = 1;
sm head = init();
newHead = init();
sc chead = initC();
aboutMe();
// 导入学生信息
readStudentFromLacal(head);
readCourseFromLacal(chead);
while (flag == 1) {
cout << "\n\n\t\t\t*****************************\n";
cout << "\t\t\t 欢迎来到学生信息管理系统\n";
cout << "\t\t\t*****************************\n";
cout << " -------------------------------------------------------------------------------\n";
cout << "\t\t 选择功能:\n\t\t\t\t1.添加学生\n\t\t\t\t2.查找学生\n\t\t\t\t3.修改学生\n" <<
"\t\t\t\t4.删除学生\n\t\t\t\t5.学生排序\n\t\t\t\t6.课程管理\n\t\t\t\t7.学生选课\n\t\t\t\t8.学生列表\n\t\t\t\t9.导出学生\n\t\t\t\t0.退出学生管理系统";
cout << " \n\n-------------------------------------------------------------------------------\n";
cout << "\t\t\t请输入你的选择后按Enter键进入:";
cin >> s1;
// system("cls");
switch (s1) {
case '9':
system("cls");
savePersonFile(head, chead);
saveCourseToLocal(chead);
saveStudentToLocal(head);
cout << "\n\n\n----------------------------------导出学生信息----------------------------------\n";
cout << "\n*******************************导出文件成功************************************";
cout << "\n!!!!!!!!!!!!!!!已经存储Project16!!!!!!!!!!!!!!!!";
break;
case '8':
system("cls");
printfSMessge(head, chead);
break;
case '0':
system("cls");
flag = 0;
break;
case '1':
system("cls");
cout << "\n\n\n-----------------------------------增加学生-------------------------------------\n";
addStudent(head);
break;
case '2':
system("cls");
cout << "\n\n\n----------------------------------查找学生信息----------------------------------\n";
cout << "1.按学号查询\n2.按姓名查询\n请输入你的选择:";
cin >> s1;
switch (s1) {
case '1':
cout << "输入学生学号(6位数字):";
cin >> numb;
i = locateStdfByNo(head, numb);
if (head->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; }
if (0 != i) printfPerson(head, i, chead); else {
cout << "没有找到\n";
}
break;
case '2':
cout << "输入学生姓名:";
cin >> sname;
if (head->sNext == NULL) { cout << "没有学生数据,请添加学生" << endl; }
i = locateByName(head,sname,chead);
if (0 != i) printfPerson(head, i, chead); else {
cout << "没有找到\n";
}
break;
}
break;
case '3':
system("cls");
cout << "\n\n\n----------------------------------更新学生信息----------------------------------\n";
i = updates(head);
if (0 != i) printfPerson(head, i, chead); else {
cout << "没有找到该学生!-_-!\n";
}
break;
case '4':system("cls");
cout << "\n\n\n----------------------------------删除学生-------------------------------------\n";
i = deletesMessage(head);
break;
case '5':
system("cls");
cout << "\n\n\n----------------------------------学生排序信息----------------------------------\n";
sort = selectsort(head, newHead);
if (sort) printfSMessge(head, chead);
//printfSMessge(head, chead);
break;
case '6':
system("cls");
cflag = 1;
while (cflag == 1){
cout << "\n\n\n------------------------------课程管理系统-------------------------------------\n";
cout << "\n\t\t输入你选择的功能:\n\t\t\t\t1.添加课程信息\n\t\t\t\t2.查找课程\n\t\t\t\t3.修改课程信息\n\t\t\t\t4.删除课程\n\t\t\t\t5.显示课程\n\t\t\t\t0.退出图书管理\n";
cout << "\n------------------------------课程管理系统-------------------------------------\n\n请输入你的选择:";
cin >> c;
switch (c)
{
case '1':
system("cls");
cout << "\n\n\n----------------------------------增加课程-------------------------------------\n";
addCourse(chead); ptfSCourse(chead);
break;
case '2':
system("cls");
cout << "\n\n\n----------------------------------查找课程信息----------------------------------\n";
cout << "输入课程编号:";
cin >> numb;
if (chead->cNext == NULL) { cout << "没有课程数据,请添加课程" << endl;}
else i = locateCourse(chead, numb);
if (i != 0) printfCourse(chead, i); else {
cout << "没有找到课程\n";
}break;
case '3':
system("cls");
cout << "\n\n\n----------------------------------更新课程信息----------------------------------\n";
i = updatesCourse(chead);
if (i != 0) printfCourse(chead, i); else {
cout << "没有找到该课程课程\n";
}
break;
case '4':
system("cls");
cout << "\n\n\n----------------------------------删除课程--------------------------------------\n";
deletesCourse(chead); break;
case '5':
system("cls");
cout << "\n\n\n----------------------------------显示课程--------------------------------------\n";
ptfSCourse(chead);
break;
case '0':
system("cls");
cflag = 0;
break;
default:
break;
}
}
break;
case '7':
system("cls");
cout << "\n\n\n-----------------------------------学生选课-------------------------------------\n";
bool f = true;
if(ptfSCourse(chead)!=0){
string stdNo, select;
while (f) {
if (head->sNext == NULL) {
cout << "没有学生信息,选课成功"; f = false;
}
cout << "请输入你的(学生)的学号:";
cin >> stdNo;
f = false;
i = locateStdfByNo(head, stdNo);
if (0 == i) {
cout << "不存在该学生,请重新输入\n"; f = true;
}
}
f = true;
while(f){
f = false;
cout << "请输入你要选的课程编号:";
cin >> select;
if (locateCourse(chead, select) == 0) {
cout << "不存在该课程,请重新输入\n"; f = true; ptfSCourse(chead);
}
}
stdSelectCourse(chead,select, stdNo);
}
break;
}
cflag = 1;
}
system("cls");
goodbye();
}
当然自己水平有限,写的不好,还有很多bug没有完善,希望大家见谅,仅仅供大家参考,希望吐槽。