C語言實現(xiàn)班檔案管理系統(tǒng)課程設(shè)計
本文實例為大家分享了C語言班檔案管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
做的挺長時間的課程設(shè)計,當作參考吧
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 20 struct student { long num; char name[20]; char sex[10]; int age; char bz[40]; struct student *next; }; int i,j,n,num2,num3,age3,k,m; char name3[20],sex3[20],bz3[20],ch; FILE *fp; int login() //登陸函數(shù) { char key[20]; printf(" ********************請輸入系統(tǒng)密碼******************** "); do { scanf("%s",key); if((strcmp("a",key))==0) { printf(" password correct ,welcome ! "); return 1; //當密碼正確時,返回1,進入系統(tǒng) } printf(" password incorrect,please input again! "); }while(key!=1);//當返回值不為1時,重新輸入密碼,直到輸入真確為止 system("cls"); } int menu() //菜單 { int c; printf(" **********歡迎進入通訊客戶端!************ "); printf(" |—————1.錄入學(xué)生的基本信息—————| "); printf(" |----------2.顯示學(xué)生的基本信息----------| "); printf(" |----------3.保存學(xué)生的基本信息----------| "); printf(" |----------4.刪除學(xué)生的基本信息----------| "); printf(" |----------5.修改學(xué)生的基本信息----------| "); printf(" |----------6.查詢學(xué)生的基本信息----------| "); printf(" |—————7.退出系統(tǒng)——————————| "); printf(" 請選擇您要進行的功能(0~7) "); scanf("%d",&c); return c; } struct student *creat() //錄入信息函數(shù) { struct student *head,*p1,*p2; n=0; p1=p2=(struct student *)malloc(sizeof(struct student)); head=NULL; printf("請輸入學(xué)生信息學(xué)號,姓名,性別,年齡,備注(鍵入學(xué)生學(xué)號為0時結(jié)束) "); while(1) //為1表真,p2->next不為0; { scanf("%d",&p1->num); if(p1->num==0) //判斷學(xué)生的學(xué)號是否為0,如果為0則停止輸入數(shù)據(jù); { break; } scanf("%s%s%d%s",p1->name,p1->sex,&p1->age,p1->bz); n=n+1; if(n==1) { head=p1; } else { p2->next=p1; } p2=p1; p1=(struct student *)malloc(sizeof(struct student)); } p2->next=NULL; system("cls"); return(head); } void print(struct student *head) //輸出信息函數(shù) { struct student *p; printf(" 這里有 %d 個學(xué)生的數(shù)據(jù)信息 ",n); p=head; if(head!=NULL) { do { printf(" 學(xué)號:%d 姓名:%s 性別:%s 年齡:%d 備注:%s ",p->num,p->name,p->sex,p->age,p->bz); p=p->next; }while(p!=NULL); } else { return 0; } printf(" "); } int save(struct student *p) //保存信息函數(shù) { FILE *fp; if((fp=fopen("keshe.txt","wb"))==NULL) { printf("open file fail "); } fp=fopen("stud","wb"); do { fwrite(p,sizeof(struct student),1,fp); p=p->next; }while(p!=NULL); printf(" 保存成功! "); fclose(fp); return 0; } struct student *del(struct student *head) { struct student *p1,*p2; printf(" 請輸入要刪除學(xué)生的學(xué)號 "); scanf("%d",&num2); p1=head; if(head->num==num2) { head=head->next; free(p1); n--; } else { p2=head; while(p2->num!=num2&&p2->next!=NULL) { p1=p2; p2=p2->next; } if(p2->num==num2) { p1->next=p2->next; n--; } printf("delete:%ld ",num2); } return (head); } int mod(struct student *head); //修改信息函數(shù) struct student *modify(struct student *head) { if(login()==0) { return 0; } else { struct student *p1; j=0; p1=(struct student *)malloc(sizeof(struct student)); printf(" 請輸入你要更改的學(xué)號 "); scanf("%d",&num2); printf(" 學(xué)號 "); scanf("%d",&num3); printf(" 姓名 "); scanf("%s",name3); printf(" 性別 "); scanf("%s",sex3); printf(" 年齡 "); scanf("%d",&age3); printf(" 備注 "); scanf("%s",bz3); p1=head; if(head->num==num2) { head->num=num3; strcpy(head->name,name3); strcpy(head->sex,sex3); head->age=age3; strcpy(head->bz,bz3); j=1; } else { p1=head->next; if(p1!=NULL) { while(p1->num!=num2) { p1=p1->next; } p1->num=num2; strcpy(p1->name,name3); strcpy(p1->sex,sex3); p1->age=age3; strcpy(p1->bz,bz3); j=1; } } if(j==0) { printf(" 更改失敗 "); } else { printf(" 更改成功 "); } } system("cls"); mod(head); } int mod(struct student *head) { printf(" 請選擇 "); printf(" 1:按學(xué)號修改學(xué)生信息 "); printf(" 2:輸出修改后的學(xué)生信息 "); printf(" 3:返回主菜單 "); scanf("%d",&m); switch(m) { case 1:head=modify(head);break; case 2:print(head);break; case 3:menu();break; default:printf(" input error! "); mod(head); } } int find(struct student *head); int find1(struct student *head) //以學(xué)號方式查找 { struct student *p1; p1=(struct student *)malloc(sizeof(struct student)); printf(" 請輸入你要查詢的學(xué)生學(xué)號 "); scanf("%d",&num2); p1=head; while(p1!=NULL) { if(p1->num==num2) { k=1; printf(" 學(xué)號:%d 姓名:%s 性別:%s 年齡:%d 備注:%s ",p1->num,p1->name,p1->sex,p1->age,p1->bz); break; } p1=p1->next; } if(k==0) { printf(" 沒有查詢到您要找的學(xué)生信息 "); } else { printf(" 這就是您要找的學(xué)生信息 "); } find(head); } int find2(struct student *head) //以姓名方式查找 { struct student *p1; p1=(struct student *)malloc(sizeof(struct student)); printf(" 請輸入您要查詢的學(xué)生姓名 "); scanf("%s",name3); p1=head; while(p1!=NULL) { if((strcmp(p1->name,name3))==0) { k=1; printf(" 學(xué)號:%d 姓名:%s 性別:%s 年齡:%d 備注:%s ",p1->num,p1->name,p1->sex,p1->age,p1->bz); break; } p1=p1->next; } if(k==0) { printf(" 沒有找到該學(xué)生信息 "); } else { printf(" 這就是您要查詢的學(xué)生信息 "); } find(head); } int find3(struct student *head) //以性別方式查找 { struct student *p1; p1=(struct student *)malloc(sizeof(struct student)); printf(" 請輸入你要查詢的學(xué)生的性別 "); scanf("%s",sex3); p1=head; while(p1!=NULL) { if((strcmp(p1->sex,sex3))==0) { k=1; printf(" 學(xué)號:%d 姓名:%s 性別:%s 年齡:%d 備注:%s ",p1->num,p1->name,p1->sex,p1->age,p1->bz); break; } p1=p1->next; } if(k==0) { printf(" 沒有找到該學(xué)生信息 "); } else { printf(" 這就是您要查詢的學(xué)生的信息 "); } find(head); } int find4(struct student *head) //以年齡方式查找 { struct student *p1; p1=(struct student *)malloc(sizeof(struct student)); printf(" 請輸入您要查詢的學(xué)生的年齡 "); scanf("%d",&age3); p1=head; while(p1!=NULL) { if(p1->age==age3) { k=1; printf(" 學(xué)號:%d 姓名:%s 性別:%s 年齡:%d 備注:%s ",p1->num,p1->name,p1->sex,p1->age,p1->bz); break; } p1=p1->next; } if(k==0) { printf(" 沒有找到該學(xué)生的信息 "); } else { printf(" 這就是您要找的學(xué)生的信息 "); } find(head); } int find(struct student *head) { printf(" 請選擇您要查詢學(xué)生信息的方式 "); printf(" 1:按學(xué)生學(xué)號查詢 "); printf(" 2:按學(xué)生姓名查詢 "); printf(" 3:按學(xué)生性別查詢 "); printf(" 4:按學(xué)生年齡查詢 "); printf(" 5:返回主菜單 "); scanf("%d",&m); switch(m) { case 1:find1(head);break; case 2:find2(head);break; case 3:find3(head);break; case 4:find4(head);break; case 5:system("cls");menu();break; default:printf(" input error,please input again "); } } int main() //主函數(shù) { struct student *phead; if(login()==0) { return 0; } printf(" "); while(1) { switch(menu()) { case 1:system("cls");phead=creat();break; case 2:system("cls");print(phead);break; case 3:system("cls");save(phead);break; case 4:system("cls");phead=del(phead);break; case 5:system("cls");mod(phead);break; case 6:system("cls");find(phead);break; case 7:system("cls");printf(" 歡迎使用,再見! ");return 0; default:printf(" 輸入有錯,請重新輸入 "); } } }
更多學(xué)習(xí)資料請關(guān)注專題《管理系統(tǒng)開發(fā)》。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。
上一篇:C語言實現(xiàn)飛機票務(wù)系統(tǒng)
欄 目:C語言
下一篇:C語言實現(xiàn)航班售票系統(tǒng) C語言實現(xiàn)航班管理系統(tǒng)
本文標題:C語言實現(xiàn)班檔案管理系統(tǒng)課程設(shè)計
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/24.html
您可能感興趣的文章
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用函數(shù)刪除字符
- 04-02c語言的正則匹配函數(shù) c語言正則表達式函數(shù)庫
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對數(shù)怎么表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段函數(shù)
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排序法函數(shù)
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段函數(shù)
- 04-02C語言中怎么打出三角函數(shù) c語言中怎么打出三角函數(shù)的值
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求階乘


閱讀排行
本欄相關(guān)
- 04-02c語言函數(shù)調(diào)用后清空內(nèi)存 c語言調(diào)用
- 04-02func函數(shù)+在C語言 func函數(shù)在c語言中
- 04-02c語言的正則匹配函數(shù) c語言正則表達
- 04-02c語言用函數(shù)寫分段 用c語言表示分段
- 04-02c語言中對數(shù)函數(shù)的表達式 c語言中對
- 04-02c語言編寫函數(shù)冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數(shù) round c語言
- 04-02c語言分段函數(shù)怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數(shù) c語言中怎
- 04-02c語言調(diào)用函數(shù)求fibo C語言調(diào)用函數(shù)求
隨機閱讀
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 04-02jquery與jsp,用jquery
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 01-10delphi制作wav文件的方法
- 01-10C#中split用法實例總結(jié)
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-11ajax實現(xiàn)頁面的局部加載
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 01-10使用C語言求解撲克牌的順子及n個骰子