毕业生选题管理系统模拟毕业生选择指导teacher提供的毕业课题。teacher可增加、删除、修改课题,学生可选择课题,teacher和学生都可以查看当前已经选择的结果。
7条回答 默认 最新
Watch the clown 2023-06-13 18:43关注。稍等给你找现成的,csdn自己的论坛搜索:https://blog.csdn.net/weixin_46047285/article/details/106878142
#include<iostream> #include<cstring> #include<fstream> #include<cstdlib> using namespace std; char A; //题目A int a = 0; //题目A的计数器 char B; int b = 0; char C; int c = 0; class Student {//定义一个学生类 friend class course; public: int stuid; // 学号 char stuname[10]; // 姓名 char clas[10]; // 年级 char specialty[10]; // 专业 string StuID;//登陆密码 public: void add(); // 添加学生信息 void total(); // 统计信息 void display(); // 显示信息 void write(int n); // 向文件中写入数据 int read(); // 从文件中读数据 }stu[40]; class Course { //定义一个课程设计类 friend class Student; private: string couId; // 课程编号 char couName[10]; // 课程名称 char couTitle; // 选题题目 char couTeacher[30]; // 指导教师 public: void search(); // 查询信息 void searchsid(); // 按学号查询信息 void alter(); // 修改信息 void del(); // 删除信息 }Cou[40]; //1. 向文件中写入数据 void Student::write(int n) { fstream myfile;//1.创建流对象 myfile.open("student.txt", ios::out | ios::binary); if (!myfile) { cout << "该文件不能打开 !" << endl; abort();//功能: 终止程序的执行。返回值依赖于执行,可以通过返回值显示错误。 } int count = n; myfile << count << endl << endl; for (int i = 0; i <= count; i++) { myfile << stu[i].stuid << " " << stu[i].stuname << " " << stu[i].clas << " " << stu[i].specialty << " " << Cou[i].couId << " " << Cou[i].couName << " " << Cou[i].couTitle << " " << Cou[i].couTeacher << " " << endl; } myfile.close(); } //2.从文件中读数据 int Student::read() { fstream myfile;//定义流对象 myfile.open("student.txt", ios::in | ios::binary); if (!myfile) { cout << "该文件不能打开 !" << endl; abort(); } int count; myfile.seekg(0); myfile >> count; for (int i = 0; i <= count; i++) { myfile >> stu[i].stuid >> stu[i].stuname >> stu[i].clas >> stu[i].specialty >> Cou[i].couId >> Cou[i].couName >> Cou[i].couTitle >> Cou[i].couTeacher; cout << endl; } myfile.close(); return count; } //录入功能 void Student::add() { int n = read();; int i = 0; char sign; cout << endl << "是否输入增加的学生的相关信息 :(Y or N) " << endl; cin >> sign; while (sign != 'N') { loop: cout << "学号 :"; cin >> stu[i].stuid; cout << endl; cout << "学生登陆密码 :"; cin >> stu[i].StuID; cout << endl; int c = 0; while (c < i) { c++; if (stu[i].stuid == stu[i - c].stuid) { cout << "你输入的学号已经存在 ! 请重新输入 " << endl; goto loop; } } cout << "请录入学生基本信息:" << endl; cout << "姓名 :"; cin >> stu[i].stuname; cout << endl; cout << "年级 :"; cin >> stu[i].clas; cout << endl; cout << "专业 :"; cin >> stu[i].specialty; cout << endl; cout << "请录入课程设计信息:" << endl; cout << "请输入......" << endl; cout << "课程编号 :" << endl; cin >> Cou[i].couId; cout << endl; cout << "课程名称 :"; cin >> Cou[i].couName; cout << endl; cout << "进入选题程序......" << endl; int id;//学号 string password;//登录密码 cout << "选题题目 :本系统每个课程有3道题目[A,B,C],每道题目限定3名学生" << endl; for (int j = 0; j < 3; j++) { cout << "用户名:[学号]" << endl; cin >> id; cout << "登录密码:" << endl; cin >> password; if (id == stu[i].stuid && password == stu[i].StuID) { cout << "登录成功,请选题:" << endl; cin >> Cou[i].couTitle; if (Cou[i].couTitle == 'A') { a++; if (a > 3) cout << "选择A题目人数已满" << endl; break; } if (Cou[i].couTitle == 'B') { b++; if (b > 3) cout << "选择B题目人数已满" << endl; break; } if (Cou[i].couTitle == 'C') { c++; if (c > 3) cout << "选择C题目人数已满" << endl; break; } break; } else { if (2 - j == 0) { cout << "3次登录失败,账号被锁定,请与指导老师联系!" << endl; } else { cout << "选题程序登录失败,你还有" << 2 - j << "次机会登录!" << endl; } } } cout << endl; cout << "指导教师 :"; cin >> Cou[i].couTeacher; cout << endl; cout << "提示:是否继续写入学生信息 ?(Y/N)"; cin >> sign; // 输入判断 i++; } write(i); } //查询学生信息、课程设计信息 void Course::search() { Student stu; int n = stu.read(); cout << "查询学生信息、课程设计信息:[确认查询:1]" << endl; cout << endl; int c; Course g; cout << "请输入选择 :"; cin >> c; switch (c) { case 1: g.searchsid(); default: cout << "输入错误 , 请重新输入 !" << endl; } stu.write(n); } //登录学号,密码,查询学生信息、课程设计信息 void Course::searchsid() { Student st; int n = st.read(); int s; int i = 0; cout << endl << "查找学生信息 :" << endl; cout << "请输入需要查找学生的学号 :" << endl; cin >> s; string id; cout << "请输入学生登陆密码:"; cin >> id; while ((stu[i].stuid - s) != 0 && i < n && (id == stu[i].StuID)) i++; // 查找判断 if (i == n) { cout << "登陆失败" << endl; cout << "提示:对不起,无法找到该学生的信息! " << endl; } else { cout << "查询中,请等待......" << endl; cout << "---------------查询结果如下----------------" << endl; cout << "学号 : " << stu[i].stuid << endl; cout << "姓名 : " << stu[i].stuname << endl; cout << "年级 : " << stu[i].clas << endl; cout << "专业 : " << stu[i].specialty << endl; cout << "课程编号 : " << Cou[i].couId << endl; cout << "课程名称 : " << Cou[i].couName << endl; cout << "选题题目 : " << Cou[i].couTitle << endl; cout << "指导教师 : " << Cou[i].couTeacher << endl; } } //修改学生信息、课程设计信息 void Course::alter() { Student st; int n = st.read(); int s; int i = 0; cout << endl << "修改学生信息 :" << endl; cout << "请输入需要修改学生的学号 :" << endl; cin >> s; while ((stu[i].stuid - s) != 0 && i < n) i++; // 查找判断 if (i == n) { cout << "提示:对不起,无该学生的信息 !!!" << endl; // 输入失败信息 } else { cout << "该学生的信息 :" << endl; cout << "学号: " << stu[i].stuid << '\n' << "姓名: " << stu[i].stuname << "年级: " << stu[i].clas << '\n' << "专业: " << '\n' << stu[i].specialty << '\n' << "课程编号 : " << Cou[i].couId << '\n' << "课程名称 : " << Cou[i].couName << '\n' << "选题题目 : " << Cou[i].couTitle << '\n' << "指导教师 : " << Cou[i].couTitle << '\n' << endl; cout << "请重新输入该学生的信息 " << endl; cout << "学号 :"; cin >> stu[i].stuid; cout << endl; cout << "姓名 :"; cin >> stu[i].stuname; cout << endl; cout << "年级 :"; cin >> stu[i].clas; cout << endl; cout << "专业 :"; cin >> stu[i].specialty; cout << endl; cout << "请重新输入课程设计信息:" << endl; cout << "课程编号 :"; cin >> Cou[i].couId; cout << endl; cout << "课程名称 :"; cin >> Cou[i].couName; cout << endl; cout << "进入选题程序......" << endl; int id;//学号 string password;//登录密码 cout << "选题题目 :本系统每个课程有3道题目[A,B,C],每道题目限定3名学生" << endl; for (int j = 0; j < 3; j++) { cout << "用户名:[学号]" << endl; cin >> id; cout << "登录密码:" << endl; cin >> password; if (id == stu[i].stuid && password == stu[i].StuID) { cout << "登录成功,请选题:" << endl; cin >> Cou[i].couTitle; if (Cou[i].couTitle == 'A') { a++; if (a > 3) cout << "选择A题目人数已满" << endl; break; } if (Cou[i].couTitle == 'B') { b++; if (b > 3) cout << "选择B题目人数已满" << endl; break; } if (Cou[i].couTitle == 'C') { c++; if (c > 3) cout << "选择C题目人数已满" << endl; break; } break; } else { if (2 - j == 0) { cout << "3次登录失败,账号被锁定,请与指导老师联系!" << endl; } else { cout << "选题程序登录失败,你还有" << 2 - j << "次机会登录!" << endl; } } } cout << endl; cout << "指导老师 :"; cin >> Cou[i].couTitle; cout << endl; char c; cout << "是否保存数据 ?(y/n)" << endl; cin >> c; if (c == 'y') cout << "修改成功 !" << endl; st.write(n); } } //删除学生信息、课程设计信息 void Course::del() { Student st; int n = st.read(); int s; int i = 0, j; cout << endl << "删除学生信息 :" << endl; cout << "请输入需要删除学生的学号 :" << endl; cin >> s; while ((stu[i].stuid - s) != 0 && i < n) i++; // 查找判断 if (i == n) { cout << "提示:记录为空 !!!" << endl; // 返回失败信息 } else { for (j = i; j < n - 1; j++) // 删除操作 { stu[j].stuid = stu[j + 1].stuid; strcpy(stu[j].stuname, stu[j + 1].stuname); strcpy(stu[j].clas, stu[j + 1].clas); strcpy(stu[j].specialty, stu[j + 1].specialty); // Cou[i].couId >> Cou[i].couName >> Cou[i].couTitle >> Cou[i].couTeacher; Cou[j].couId = Cou[j + 1].couId; strcpy(Cou[j].couName, Cou[j].couName); //strcpy(Cou[j].couTitle, Cou[j].couTitle); Cou[j].couTitle = Cou[j].couTitle; strcpy(Cou[j].couTeacher, Cou[j].couTeacher); } cout << "提示:已成功删除 !" << endl; // 返回成功信息 } cout << "你要删除的信息如下 :" << endl; cout << "姓名 :" << stu[i].stuname << endl; cout << "学号 :" << stu[i].stuid << endl; cout << "年级班级 :" << stu[i].clas << endl; cout << "专业 :" << stu[i].specialty << endl; cout << "课程编号 :" << Cou[i].couId << endl; cout << "课程名称 :" << Cou[i].couName << endl; cout << "选题题目 :" << Cou[i].couTitle << endl; cout << "指导老师 :" << Cou[i].couTeacher << endl; st.write(n - 1); } //统计学生信息、课程设计信息 void Student::total() { { int n = read(); char c[10]; cout << "请输入需要查找的课程名称 :" << endl; cin >> c; for (int i = 0; i < n; i++) if (strcmp(Cou[i].couName, c) == 0) { cout << "你要统计的信息如下 :" << endl; cout << "姓名 :" << stu[i].stuname << endl; cout << "学号 :" << stu[i].stuid << endl; cout << "年级班级 :" << stu[i].clas << endl; cout << "专业 :" << stu[i].specialty << endl; cout << "课程编号 :" << Cou[i].couId << endl; cout << "课程名称 :" << Cou[i].couName << endl; cout << "选题题目 :" << Cou[i].couTitle << endl; cout << "指导老师 :" << Cou[i].couTeacher << endl; } else { cout << "没有找到该课程的记录! " << endl; } } } //显示学生信息、课程设计信息 void Student::display() { int n = read(); cout << endl << "显示全部学生信息: " << endl; if (!stu) cout << "没有记录" << endl; else { for (int i = 0; i < n; i++) // 循环输入 cout << "学号: " << stu[i].stuid << '\n' << "姓名: " << stu[i].stuname << "年级: " << stu[i].clas << '\n' << "专业: " << '\n' << stu[i].specialty << '\n' << "课程编号 : " << Cou[i].couId << '\n' << "课程名称 : " << Cou[i].couName << '\n' << "选题题目 : " << Cou[i].couTitle << '\n' << "指导教师 : " << Cou[i].couTeacher << '\n' << endl; } } int main() { char choice; cout << "\n\n\ ********------欢迎使用课程设计选题管理系统------******** \n\n"; cout << "|----------------- 1.[录入]+[选题]功能 --------------|\n"; cout << "|----------------- 2.查询功能 --------------|\n"; cout << "|----------------- 3.修改功能 --------------|\n"; cout << "|----------------- 4.删除功能 --------------|\n"; cout << "|----------------- 5.统计功能 --------------|\n"; cout << "|----------------- 6.打印功能[学生+课程] --------------|\n"; cout << "|----------------- 0.退出选题系统功能 --------------|\n"; cout << endl; cout << "请输入对应功能的序号: "; cin >> choice; Course g; Student st; if (choice == '0') { cout << "感谢您使用课程设计选题管理系统!" << endl; exit(0); } else if (choice == '1') { st.add(); system("pause"); main(); } else if (choice == '2') { g.search(); system("pause"); main(); } else if (choice == '3') { g.alter(); system("pause"); main(); } else if (choice == '4') { g.del(); system("pause"); main(); } else if (choice == '5') { st.total(); system("pause"); main(); } else if (choice == '6') { st.display(); system("pause"); main(); } else { cout << "输入错误,请重新输入您的选择: "; main(); } return 0; }本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报 编辑记录解决 2无用 1