




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
#include<stdio、h〉#include<string、h>#include<stdlib、h>structcourse{?intnum;?charname[20];?charkind[20];intttime,mark,term;}c;structstudent{intsnum;intcnum;charcnam[20];?charsnam[20];}s[500];intcount;//全局變量intmain()//主函數(shù){int n;int menu();intf1();?intluru();intliulan();?intchaxun();int xuanke();?inttongji();printf("\n ******************* ************** ************");?printf(”\n\n ******* *** 歡迎進入學生選課系統(tǒng)!**********");menu();?printf("\n");printf(" ******* ************ the end ********************* n”);printf("\n ********************** ***********************");?printf(”n\n 請 先選擇1進行課程 信息錄 入:");scanf(”%d",&n);//防止錯誤,請重新輸入?for(;n〉5||n<0;){?printf("\n 輸入 錯 誤!請 重 新 輸入 !\n ”);???scanf("%d",&n);?}while(n>0&&n<6)?{switch(n){case1:luru();break;//錄入課程信息?case2:liulan();break;//瀏覽課程信息case3:chaxun();break;//查詢課程信息case 4:xuanke();break;//進入選課操作? case 5:tongji();break;//統(tǒng)計選課情況}scanf("%d",&n);//選擇所需操作??for(;n〉5||n〈0;){n\n");???printf("\n 輸入 錯 誤! 請 重 新 輸 入?。躰 ”);???scanf("%d ",&n);//防止錯誤,提示重新輸入??}system(”cls");//清屏?}?if(n==0)?{??printf("\n\n\n\n\n”);??printf("**********謝謝使用!**********n");printf("n”);?}?exit(0);//退出選課系統(tǒng)return0;}intmenu()//菜單函數(shù){?intn;?printf("n");?printf("1、錄入課程信息\n\n");printf(”2、瀏覽課程信息\n\n");printf(”3、查詢課程信息n”);printf("4、進入選課操作n\n”);?printf("5、統(tǒng)計選課情況\n\n");?printf("0、退出選課系統(tǒng)n\n");return0;}intf1(){printf("\n 課程編號 課程名稱 課程性質(zhì) 總學時 學分 開課學期:\n”);?return0;}int luru()//錄入函數(shù){FILE*fp;//定義指向文件得指針structcoursec;inti;if((fp=fopen("D://course、txt",”w”))==NULL)//建立文件"course、txt"{printf( ”cannotopenfil n”);?exit(0);?}?printf("n 請輸入選擇得課 程 門 數(shù):");?scanf("%d",&count);printf(”\n\n");f1();for(i=0;i<count;i++)?{scanf("%d%s%s%d%d%d",&c、num,c、name,c、kind,&c、ttime,&c、mark,&c、term);?fprintf(fp,"%d\t%s\t%s t%d\t%dt",c、num,c、name,c、kind,c、ttime,c、mark,c、term);?}?fclose(fp);//關(guān)閉文件?printf("\n ********* 錄入成功!*********n");menu();return0;}int liulan()//瀏覽函數(shù){?inti=0;FILE*fp;//定義指向文件得指針struct coursec;//定義課程結(jié)構(gòu)體變量if((fp=fopen(”D://course、txt","r”))==NULL)//打開文件”course、txt"?{printf("\ncannot open course!\n");??exit(0);}f1();?while(?。妫錹f(fp)&&i〈count)fscanf(fp,"%d%s%s%d%d%d”,&c、num,c、name,c、kind,&c、ttime,&c、mark,&c、term);printf(”%7d%11s%10s%9d%9d%8d\n",c、num,c、name,c、kind,c、ttime,c、mark,c、term);i++;?}?fclose(fp);//關(guān)閉文件?menu();?return0;}int chaxun()//查詢函數(shù){?FILE*fp;//定義指向文件得指針structcoursec;//定義課程結(jié)構(gòu)體變量intscore;int b,i=0;?char kind[20];printf( n 1、按 學 分查詢\n");printf("\n 2、按 課 程 性 質(zhì)查詢");?printf(” 請選擇查 詢方式 n\n 輸入選 項 數(shù) 字:");scanf(”%d",&b);//防止錯誤,提示重新輸入?for(;b<1||b>2;)?{??printf(”\n 輸入錯誤!請 重新輸入?。?");??scanf("%d",&b);?}//按學分查詢?if(b==1)?{?printf(”\n 輸入您要查 詢得學分:");scanf(”%d”,&score);??if((fp=fopen("D://course、txt”,"r”))==NULL){?printf(”\ncannotopencourse?。埽睢保???exit(0);}f1();??while(!feof(fp)&&i〈count)//當沒有指向文件尾部 ,讀取文件“course、txt”中得數(shù)據(jù)?{fscanf(fp,”%d%s%s%d%d%d”,&c、num,c、name,c、kind,&c、ttime,&c、mark,&c、term);? if(c、mark==score)//比較輸入得分數(shù)與結(jié)構(gòu)體中得分數(shù) ,如果相同,輸出那組數(shù)據(jù)printf("%7d%11s%10s%9d%9d%8d\n",c、num,c、name,c、kind,c、ttime,c、mark,c、term);?i++;}}?elseif(b==2)//按課程性質(zhì)查詢?{?printf("\n\n 輸入您要 查詢得課程性 質(zhì):");?scanf(”%s”,kind);if((fp=fopen("D://course、txt","r"))==NULL)//打開文件”course、txt”?{printf(”\ncannot ope n”);}??f1();?while(!feof(fp)&&i<count)//當沒有到達文件尾部,讀取“c ourse、txt"中得數(shù)據(jù){??fscanf(fp,"%d%s%s%d%d%d”,&c、num,c、name,c、kind,&c、ttime,&c、mark,&c、term);? if(strcmp(c、kind,kind)==0)//比較輸入得字符串與原文件中得課程性質(zhì),如果相同,輸出那組數(shù)據(jù)?printf(”%7d%11s%10s%9d%9d%8d\n”、,cnum,c、name,c、kind,c、ttime,c、mark,c、term);i++;??}}?else?{??printf("輸入錯誤?。ⅲ?//選擇錯誤,就退出exit(1);?}?fclose(fp);?menu();?return0;}int xuanke()//選課函數(shù){?intt=0,flag;inti;/*structcoursec;//定義課程結(jié)構(gòu)體變量*/FILE*fp;//定義指向文件得指針?do{printf(”\n 請輸 入 學號 姓名 課程編號 及課 程名稱:");scanf(”%d%s%d%s",&s[t]、snum,s[t]、snam,&s[t]um,s[t]am);if((fp=fopen(”D://course、txt","r”))==NULL)//打開文件"course、txt"{? printf( \ncan”not opencourse?。睿ⅲ?;?exit(0);?}?while(!feof(fp))//如果課程編號與課程名稱與學生所選一致,就跳出,執(zhí)行下一步??{fscanf(fp,”%d%s%s%d%d%d",&c、num,c、name,c、kind,&c、ttime,&c、mark,&c、term);if((s[t]um==c、num)&&(s[t]am==c、name))?t++;?break;}?fclose(fp);?printf("\n就是否繼續(xù),就是1,否n");scanf("%d”,&flag);??if((fp=fopen(”D://student、txt”,”a+"))==NULL)//建立文件“ student、txt”??{? printf("\ncannotopenstudent?。躰");exit(0);} //建立,并將學生選課信息輸入 "student、txt"? for(i=0;i〈t;i++);?fprintf(fp,”% t%s\t%d\t%s\t\n",s[t]、snum,s[t]、snam,s[t]um,s[t]am);fclose(fp);//關(guān)閉選課文件” course、txt"?}while(flag);?printf("\n ********* 恭喜選課成功?。?**n");?menu();?return0;}int tongji()//統(tǒng)計函數(shù){?inttotal=0;?int t,i=0;FILE *fp;?if((fp=fopen(”D://student、txt”,"r"))==NULL)//打開文件“s tudent、txt"{printf("\ncannotopenstudent!\n”);exit(0);?}?printf("\n學號姓名課程編號及課程名稱\n");while(?。妫錹f(fp))//計數(shù)?{fs
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2028-13-15-入職時和公司簽了競業(yè)限制合同-競業(yè)限制合同
- 農(nóng)家樂勞動合同范例
- 合同作廢新合同范例
- 2024-2025學年江蘇省連云港市海州區(qū)高一上冊第一次月考數(shù)學檢測試題
- 合同范本先墊資
- 出租落地風扇合同范例
- 吊車運輸合同范本
- 關(guān)于訂門窗合同范例
- 單草簽合同范例
- 雙方快遞合作合同范例
- 《幼兒園課程》試題庫及答案2021
- 干細胞技術(shù)與臨床應(yīng)用0718合一康
- 鍋爐房風險管控措施告知牌
- 苔花如米小“艷過”牡丹開——名著導(dǎo)讀之《簡愛》
- 《西方服裝發(fā)展史》PPT課件(完整版)
- 《食管裂孔疝》PPT課件(完整版)
- 家庭醫(yī)生工作室和家庭醫(yī)生服務(wù)點建設(shè)指南
- 魯班尺和丁蘭尺速查表
- 企業(yè)年會搞笑相聲劇本《治病》
- 為夢想插上翅膀主題班會PPT授課課件
- JJF-1069-2000-法定計量檢定機構(gòu)考核規(guī)范
評論
0/150
提交評論