網站首頁 編程語言 正文
下面是詳細代碼分享:
#include<bits/stdc++.h> using namespace std;
聲明函數部分:
//聲明函數部分 void BuildMainMenu();//聲明主菜單函數 void SelectSytem(int AID,int who);//聲明選課系統 void MyCourse(int AID,int who);//聲明我的課表 void PrintC(int who);//聲明打印課表函數 void WrongW();//錯誤提示函數
前置數據處理:
- 現有課程數據
course.txt
- 現有學生數據
students.txt
- 現有老師數據
teacher.txt
- 按順序合并為
date.txt.
初始狀態為:
- 1.無任何課程->導入現有課程數據 (具體內容見
Course
類) - 2.無任何老師數據->導入老師數據 (具體內容見
teacher
類) - 3.此時老師并沒有設置任何課程
- ?? ?->需要老師登陸系統進行設置
- ?? ?該步驟需要手動鍵入數據,參考數據見
Setcourse.txt
- 4.無任何學生數據->導入學生數據 (具體內容見
student
類) - 5.暫且令助教來自于學生,則助教的數據和學生數據一致
- 6.對于學生和助教,需通過學號和所設密碼進入選課系統
//用于打印邊框 void PrintEgde(){puts("**********************************************");} //課程類 class Course { public: ?? ?int CourseId;//編號 ?? ?string cousreName;//名稱 ?? ?int credit;//學分 ?? ?bool HaveSet=0;//判斷該門課是否被老師設置,沒有設置(0)則不能被學生選擇 ?? ?Course(){}//默認構造函數,要記得寫 ?? ?//自定義的含參構造函數 ?? ?void SetCourse(int a,string b,int c){CourseId=a;cousreName=b;credit=c;} }; //AllList 存儲所有課程的信息 Course AllList[200]; int C_totalnum;//代表課程的總數 class Person { public: ?? ?string name;//姓名 ?? ?int age;//年齡 ?? ?//構造 ?? ?Person(){} ?? ?void SetPerson(string a,int b){name=a;age=b;} }; class teacher:public Person { public: ?? ?int teacherId;//老師的編號 ?? ?int Len;//需要教授的課程數量 ?? ?int TeachCourse[10];//所授課程ID編號 ?? ?int now_have=0;//已設置課程數量 ?? ?teacher(){}//默認構造函數 ?? ?void Set_Teacher(string Name,int Age,int ID,int n)//構造 ?? ?{ ?? ??? ?name=Name; ?? ??? ?age=Age; ?? ??? ?teacherId=ID; ?? ??? ?Len=n; ?? ?} ?? ?void teach(){cout<<"I am a teacher,I teach my student\n";} ?? ?//刪除已經設置的課程 ?? ?void DeleteC(int CID) ?? ?{ ?? ??? ?system("cls");//用于清空cmd窗口 ?? ??? ?//如果當前沒有課程可以刪除就直接返回 ?? ??? ?if(now_have==0)? ?? ??? ?{ ?? ??? ??? ?puts("You have set no course!"); ?? ??? ??? ?_sleep(500);//用于暫停0.5s ?? ??? ??? ?return; ?? ??? ?} ?? ??? ?//CAN用于判斷是否能取消設置某一門課(即要取消的課是否已被設置) ?? ??? ?int CAN=0; ?? ??? ?for(int i=1;i<=now_have;i++) ?? ??? ?{ ?? ??? ??? ?if(TeachCourse[i]==CID) ?? ??? ??? ?{ ?? ??? ??? ??? ?//可以取消,那么把原本設置好的最后一門課放到要取消的課的位置上 ?? ??? ??? ??? ?TeachCourse[i]=TeachCourse[now_have]; ?? ??? ??? ??? ?now_have--; ?? ??? ??? ??? ?CAN=1; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?if(CAN==1) puts("You successfully deleted the course!"); ?? ??? ?else puts("There is no such course!");//不能取消設置的情況 ?? ??? ?_sleep(800); ?? ?} ?? ?void PrintNowteach()//輸出已設置課程 ?? ?{ ?? ??? ?system("cls"); ?? ??? ?puts(" ? ? ? ? ? ? <M y C o u r s e> ? ? ? ? ? ? ?\n"); ?? ??? ?PrintEgde(); ?? ??? ?//如果沒有課 ?? ??? ?if(now_have==0) puts("You have no course now!"); ?? ??? ?//如果有課 ?? ??? ?for(int i=1;i<=now_have;i++) ?? ??? ?{ ?? ??? ??? ?int x=TeachCourse[i];//取出課程編號方便下一行書寫 ?? ??? ??? ?printf("*%5d ? ?%-29s %4d *\n",AllList[x].CourseId,AllList[x].cousreName.c_str(),AllList[x].credit); ?? ??? ?} ?? ??? ?PrintEgde();putchar('\n'); ?? ??? ?printf({"You can input The CourseID to delete:(or -1 to return)"}); ?? ??? ?int flag=0;scanf("%d",&flag); ?? ??? ?if(flag==-1) return;//返回上一級系統 ?? ??? ?else if(flag>0 && flag<=C_totalnum)//如果輸入的數字在限定范圍之內 ?? ??? ?{ ?? ??? ??? ?DeleteC(flag);//取消設置 ?? ??? ??? ?PrintNowteach();//并重置該頁面 ?? ??? ?} ?? ??? ?else//如果輸入的數字不在預設范圍內,進行報錯提示 ?? ??? ?{ ?? ??? ??? ?WrongW(); ?? ??? ??? ?PrintNowteach(); ?? ??? ?} ?? ?} ?? ?void setCourse(int CourseID) ?? ?//在已有課程中選擇屬于自己Teach的課程編號 ?? ?{ ?? ??? ?system("cls"); ?? ??? ?//如果已經選滿了 ?? ??? ?if(Len-now_have<=0)? ?? ??? ?{ ?? ??? ??? ?puts("You have already set all of your courses!"); ?? ??? ??? ?_sleep(800);return; ?? ??? ?} ?? ??? ?if(AllList[CourseID].HaveSet!=0)//如果已經被別人設置了 ?? ??? ??? ?puts("This course has been set!"); ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?puts("You successfully set the course!"); ?? ??? ??? ?TeachCourse[++now_have]=CourseID; ?? ??? ??? ?AllList[CourseID].HaveSet=1; ?? ??? ?} ?? ??? ?_sleep(800); ?? ?} }; teacher A_T[200];//所有老師的信息 int T_totalnum; class student:public Person { public: ?? ?long long number;//學號 ?? ?int courseCount=0;//已選課程數目 ?? ?int mycourse[20];//已選課程的課程編號 ?? ?int LeastNum;//至少選擇課程數目 ?? ?string key;//密碼 ?? ?student(){} ?? ?//此處age表示入學年份,如2021,2020 ?? ?void Set_student(string Name,int Age,long long Num,int n,string Key) ?? ?{ ?? ??? ?name=Name; ?? ??? ?age=Age; ?? ??? ?number=Num;//學號 ?? ??? ?LeastNum=n; ?? ??? ?key=Key; ?? ??? ?memset(mycourse,0,sizeof(mycourse));//初始化已選課程數組 ?? ?} ?? ?void selectCourse(int CourseID) ?? ?{ ?? ??? ?system("cls"); ?? ??? ?//用于判斷自己是否已經選過這門課程 ?? ??? ?bool HaveChoose = 0; ?? ??? ?for(int i=1;i<=courseCount;i++) ?? ??? ??? ?if(CourseID==mycourse[i])? ?? ??? ??? ??? ?HaveChoose=1; ?? ??? ?//如果該門課已經被老師設置并且自己沒有選過 ?? ??? ?if(AllList[CourseID].HaveSet && HaveChoose==0) ?? ??? ?{ ?? ??? ??? ?puts("You successfully stlect the course!"); ?? ??? ??? ?mycourse[++courseCount]=CourseID; ?? ??? ?} ?? ??? ?//老師沒有設置課程 ?? ??? ?else if(AllList[CourseID].HaveSet==0) puts("There is no such course!"); ?? ??? ?//自己已經選過 ?? ??? ?else if(HaveChoose==1) puts("This course you have chosen!"); ?? ??? ?_sleep(800); ?? ?} ?? ?void Delete(int CID) ?? ?{ ?? ??? ?system("cls"); ?? ??? ?if(courseCount==0) return; ?? ??? ?int CAN; ?? ??? ?for(int i=1;i<=courseCount;i++) ?? ??? ?{ ?? ??? ??? ?if(mycourse[i]==CID) ?? ??? ??? ?{ ?? ??? ??? ??? ?mycourse[i]=mycourse[courseCount]; ?? ??? ??? ??? ?courseCount--; ?? ??? ??? ??? ?CAN=1; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?if(CAN==1) puts("You successfully deleted the course!"); ?? ??? ?else puts("There is no such course!"); ?? ??? ?_sleep(800); ?? ?} ?? ?//判斷是否滿足學校要求 ?? ?void judge() ?? ?{ ?? ??? ?if(courseCount>=LeastNum) //比較已選課程和要求課程數量 ?? ??? ??? ?puts("You can complete the credits of this semester"); ?? ??? ?else? ?? ??? ??? ?printf("You need to choose %d more courses\n",LeastNum-courseCount); ?? ?} }; student A_S[2000];//所有學生的信息 int S_totalnum;//學生的總數 class TeachingAssistant:public teacher,public student { public: ?? ?void teach(){puts("I am a teaching assistant,I help my teacher teach his students");} ?? ?TeachingAssistant(){} ?? ?void selectCourse(int CourseID) ?? ?{ ?? ??? ?system("cls"); ?? ??? ?if(AllList[CourseID].HaveSet) ?? ??? ?{ ?? ??? ??? ?puts("You successfully stlect the course!"); ?? ??? ??? ?mycourse[++courseCount]=CourseID; ?? ??? ?} ?? ??? ?else puts("There is no such course!"); ?? ??? ?_sleep(800); ?? ?} ?? ?void Delete(int CID) ?? ?{ ?? ??? ?system("cls"); ?? ??? ?if(courseCount==0) return; ?? ??? ?int CAN; ?? ??? ?for(int i=1;i<=courseCount;i++) ?? ??? ?{ ?? ??? ??? ?if(mycourse[i]==CID) ?? ??? ??? ?{ ?? ??? ??? ??? ?mycourse[i]=mycourse[courseCount]; ?? ??? ??? ??? ?courseCount--; ?? ??? ??? ??? ?CAN=1; ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?if(CAN==1) puts("You successfully deleted the course!"); ?? ??? ?else puts("There is no such course!"); ?? ??? ?_sleep(800); ?? ?} }; TeachingAssistant A_TA[2500]; void Pre_course() { ?? ?//導入所有課程數據 ?? ?int a,b;string c; ?? ?freopen("date.txt","r",stdin); ?? ?scanf("%d",&C_totalnum); ?? ?for(int i=1;i<=C_totalnum;i++) ?? ?{ ?? ??? ?cin>>a>>c>>b; ?? ??? ?//輸入編號,名稱,學分 ?? ??? ?AllList[i].SetCourse(a,c,b); ?? ?} } void Pre_teacher() { ?? ?//導入所有老師數據 ?? ?int a,b,c;string d; ?? ?scanf("%d",&T_totalnum); ?? ?for(int i=1;i<=T_totalnum;i++) ?? ?{ ?? ??? ?cin>>d>>a>>b>>c; ?? ??? ?//輸入姓名,年齡,編號,應設置課程數量 ?? ??? ?A_T[i].Set_Teacher(d,a,b,c); ?? ?} } void Pre_student() { ?? ?//導入所有學生數據 ?? ?int a;long long b;string d,e; ?? ?scanf("%d",&S_totalnum); ?? ?for(int i=1;i<=S_totalnum;i++) ?? ?{ ?? ??? ?//姓名 入學年份 學號 至少選課數統一為2 ?? ??? ?cin>>d>>a>>b>>e; ?? ??? ?A_S[i].Set_student(d,a,b,2,e); ?? ??? ?A_TA[i].Set_student(d,a,b,2,e); ?? ?} } void Pre() //選課系統前置準備工作 { ?? ?Pre_course();//導入課程數據 ?? ?Pre_teacher();//導入老師數據 ?? ?Pre_student();//導入學生數據 } void WrongW()//報錯提示 { ?? ?system("cls"); ?? ?puts("You entered the wrong one!"); ?? ?_sleep(500); } void MyCourse(int AID,int who) { ?? ?system("cls"); ?? ?puts(" ? ? ? ? ? ? <M y C o u r s e> ? ? ? ? ? ? ?\n"); ?? ?PrintEgde(); ?? ?if(who==0)//學生 ?? ?{ ?? ??? ?//沒課的情況 ?? ??? ?if(A_S[AID].courseCount==0) puts("You have no course now!"); ?? ??? ?//有課的情況 ?? ??? ?for(int i=1;i<=A_S[AID].courseCount;i++) ?? ??? ?{ ?? ??? ??? ?int x=A_S[AID].mycourse[i]; ?? ??? ??? ?printf("*%5d ? ?%-29s %4d *\n",AllList[x].CourseId,AllList[x].cousreName.c_str(),AllList[x].credit); ?? ??? ?} ?? ??? ?PrintEgde();putchar('\n'); ?? ??? ?A_S[AID].judge(); ?? ?} ?? ?else ?? ?{ ?? ??? ?if(A_TA[AID].courseCount==0) puts("You have no course now!"); ?? ??? ?for(int i=1;i<=A_TA[AID].courseCount;i++) ?? ??? ?{ ?? ??? ??? ?int x=A_TA[AID].mycourse[i]; ?? ??? ??? ?printf("*%5d ? ?%-29s %4d *\n",AllList[x].CourseId,AllList[x].cousreName.c_str(),AllList[x].credit); ?? ??? ?} ?? ??? ?PrintEgde();putchar('\n'); ?? ?} ?? ?//是否進行退課操作 ?? ?printf({"You can input The CourseID to delete:(or -1 to return)"}); ?? ?int flag=0;scanf("%d",&flag); ?? ?if(flag==-1) SelectSytem(AID,who); ?? ?else if(flag>0 && flag<=C_totalnum) ?? ?{ ?? ??? ?if(who==0) A_S[AID].Delete(flag); ?? ??? ?else A_TA[AID].Delete(flag); ?? ??? ?MyCourse(AID,who); ?? ?} ?? ?else {WrongW();MyCourse(AID,who);} } void PrintC(int who) //打印所有課程信息 { ?? ?puts(" ? ? ? ? ? <Course Information> ? ? ? ? ? ? \n"); ?? ?PrintEgde(); ?? ?puts("*Course Id ? ? ? Name ? ? ? ? ? ? ? Credit ? *"); ? ? PrintEgde(); ?? ?if(who==1)//老師和助教 ? ? ?? ?for(int i=1;i<=C_totalnum;i++) ?? ??? ??? ?printf("*%5d ? ?%-29s %4d *\n",AllList[i].CourseId,AllList[i].cousreName.c_str(),AllList[i].credit); ?? ?else//學生 ?? ? ? ?for(int i=1;i<=C_totalnum;i++) ?? ??? ??? ?if(AllList[i].HaveSet) ?? ??? ??? ??? ?printf("*%5d ? ?%-29s %4d *\n",AllList[i].CourseId,AllList[i].cousreName.c_str(),AllList[i].credit); ?? ?PrintEgde();putchar('\n'); } void SelectSytem(int AID,int who) //who 0 代表學生 1 代表助教 { ?? ?system("cls"); ?? ?//打印所有課程信息 ?? ?PrintC(0); ?? ?//輸出學生姓名 .c_str()的作用是將string類型的數據轉成char類型,使得它可以用printf輸出 ?? ?printf("Student: %s .",A_S[AID].name.c_str()); ?? ?if(who==0)? ?? ??? ?A_S[AID].judge();//學生 ?? ?printf("Please enter the Course Id to select\nYou can input -1 to exit\nYou can input -2 to check Mycourse and delete course\nNow enter a number:"); ?? ?int flag=0;scanf("%d",&flag); ?? ?if(flag==-1) BuildMainMenu();//返回上一級菜單 ?? ?else if(flag==-2) MyCourse(AID,who);//查看已選課表 ?? ?else if(flag>0 && flag<=C_totalnum)//數據在預設范圍內,則選課 ?? ?{ ?? ??? ?if(who==0)//學生 ?? ??? ??? ?A_S[AID].selectCourse(flag),SelectSytem(AID,who); ?? ??? ?else A_TA[AID].selectCourse(flag),SelectSytem(AID,who);//助教 ?? ?} ?? ?else {WrongW();SelectSytem(AID,who);}//報錯 } void StudentSystem(int who) { ?? ?system("cls"); ?? ?//切換到從控制臺輸入數據 ?? ?freopen("CON","r",stdin);? ?? ?//接下來為登陸頁面 ?? ?puts("Please enter your student number and ?password\n"); ?? ?PrintEgde();putchar('\n'); ?? ?printf("Student number:");long long SN;//輸入學號 ?? ?scanf("%lld",&SN); ?? ?printf("Password: ? ? ?"); ?? ?char Pas[20],Acs[20];scanf("%s",Pas);//輸入密碼 ?? ?int AID;//在數據庫中的序號 ?? ?//在數據庫中找到學號對應的正確密碼 ?? ?for(int i=1;i<=S_totalnum;i++) ?? ??? ?if(A_S[i].number==SN){strcpy(Acs,A_S[i].key.c_str());AID=i;break;} ?? ?int times=2;//輸入密碼的機會 ?? ?while(strcmp(Acs,Pas)!=0 && times>0) ?? ?//看輸入的密碼與正確密碼是否匹配,以及次數是否耗盡 ?? ?{ ?? ??? ?puts("Wrong Password!!!"); ?? ??? ?printf("you have %d times to enter the correct password\n",times); ?? ??? ?times--;scanf("%s",Pas); ?? ?} ?? ?//次數耗盡推出系統 ?? ?if(times==0) ?? ?{ ?? ??? ?puts("I am sorry you can't enter our system!"); ?? ??? ?_sleep(800);exit(0); ?? ?} ?? ?if(who==0) SelectSytem(AID,who);//學生 ?? ?else SelectSytem(AID,1);//助教 } //老師設置課程 void Setcourse(int TID) { ?? ?system("cls"); ?? ?printf("Welcome : %s\n",A_T[TID].name.c_str()); ?? ?printf("You need to set %d courses\n\n",A_T[TID].Len-A_T[TID].now_have); ?? ?PrintC(1); ?? ?printf("Please enter the Course Id to set\nYou can input -1 to exit\nYou can input -2 to check Mycourse\nNow enter a number:"); ?? ?int flag=0;scanf("%d",&flag); ?? ?if(flag==-1) BuildMainMenu(); ?? ?else if(flag==-2) A_T[TID].PrintNowteach(),Setcourse(TID);//查看已設置的課程 ?? ?else if(flag>0 && flag<=C_totalnum)//設置課程 ?? ??? ?A_T[TID].setCourse(flag),Setcourse(TID); ?? ?else {WrongW();Setcourse(TID);} } void TeacherSystem() { ?? ?system("cls"); ?? ?freopen("CON","r",stdin); //切換到從控制臺輸入數據 ?? ?puts(" ? ? ? ? Welcome ?to ?Teacher ?system! ? ? ? ?"); ?? ?PrintEgde();putchar('\n'); ?? ?//輸入教師編號以進入系統 ?? ?printf("Please enter your Teacher Id:"); ?? ?int TID;scanf("%d",&TID); ?? ?if(TID>0 && TID<=T_totalnum) ?? ??? ?Setcourse(TID); ?? ?else{ ?? ??? ?WrongW();TeacherSystem(); ?? ?} } void TASystem() { ?? ?//實際上助教系統可以看錯和學生是一個系統的 ?? ?StudentSystem(1); } //構建主菜單 void BuildMainMenu() { ?? ?system("cls"); ?? ?freopen("CON","r",stdin); //切換到從控制臺輸入數據 ?? ?puts(" ? ? ?Welcome to course selection system! ? ? "); ?? ?PrintEgde(); ?? ?puts("* ? ? ? ? 1.Student entrance ? ? ? ? ? ? ? ? *"); ?? ?puts("* ? ? ? ? 2.Teacher entrance ? ? ? ? ? ? ? ? *"); ?? ?puts("* ? ? ? ? 3.TeachingAssistant ? ? ? ? ? ? ? ?*"); ?? ?puts("* ? ? ? ?-1.Exit this system ? ? ? ? ? ? ? ? *"); ?? ?PrintEgde();putchar('\n'); ?? ?printf("Please input 1,2,3 or -1 to enter this system:"); ?? ?int flag=-1;scanf("%d",&flag);//進入子系統 ?? ?if(flag==1) StudentSystem(0); ?? ?else if(flag==2) TeacherSystem(); ?? ?else if(flag==3) TASystem(); ?? ?else if(flag==-1) exit(0); ?? ?else ?? ?{ ?? ??? ?WrongW(); ?? ??? ?BuildMainMenu(); ?? ?} } int main()//主函數 { ? ? Pre();//前置數據導入 ?? ?BuildMainMenu();//構建主菜單 ?? ?return 0; }
/* date.txt 10? 1 Media_English 2 2 Literature_English 2 3 Drama_English 2 4 Academic_English 2 5 Cross-cultural_Communication 2 6 Public_Speaking 2 7 Intermediate_English_Speaking 2 8 Intermediate_English_Writing 2 9 Basic_Russian 2 10 Basic_French 2 5 Harry_potter 35 1 2 Hermione 34 2 3 Henry_rowen 36 3 1 Snape 55 4 2 Dumbledore 46 5 2 2 Jack 2021 2021001 123456! Tom 2021 2021002 abc123 */
原文鏈接:https://blog.csdn.net/fengzi8615/article/details/122255454
相關推薦
- 2022-11-09 Android?使用maven?publish插件發布產物(aar)流程實踐_Android
- 2022-11-01 Kotlin?ContentProvider使用方法介紹_Android
- 2022-08-20 在?pytorch?中實現計算圖和自動求導_python
- 2022-05-13 修復Qt程序長時間運行控件停止刷新
- 2023-02-15 Go語言中節省內存技巧方法示例_Golang
- 2022-06-23 python基礎之while循環、for循環詳解及舉例_python
- 2023-03-27 Android數據結構優化教程_Android
- 2022-01-12 修改node_modules的包
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支