學生信息管理系統課程設計實驗報告_第1頁
學生信息管理系統課程設計實驗報告_第2頁
學生信息管理系統課程設計實驗報告_第3頁
學生信息管理系統課程設計實驗報告_第4頁
學生信息管理系統課程設計實驗報告_第5頁
已閱讀5頁,還剩20頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

*********大學課程設計報告課程名稱高級語言程序設計設計題目學生信息管理系統專業計算機科學與技術班級學號姓名完成日期課程設計任務書設計題目:學生信息管理系統設計設計內容與要求:內容:對學生信息進行管理,學生信息包括學號、姓名、性別、年齡、學歷、學號、住址、等〔學號不重復〕。要求:(1) 系統以菜單方式工作(2) 學生信息錄入功能(學生信息用文件保存)。(3) 輸出學生信息、瀏覽學生信息功能。(4) 查詢和排序功能:(至少一種查詢方式),如按學號查詢、按學歷查詢等。(5) 學生信息刪除、修改功能(任選項)。指導教師:_______________年月日課程設計評語成績:指導教師:_______________年月日【問題描述】學生信息管理軟件設計。對學生信息進行管理,學生信息包括:學號,姓名,年齡,性別,出生年月,地址,,E-mail等。試設計一個學生信息管理軟件。【根本要求】一、輸入的形式和輸入值的范圍形式:用scanf輸入學生的學號,姓名,年齡,性別,出生年月,地址,,E-mail。輸入一個學生信息一個回車。用輸入的學號p1->num來控制輸入,當輸入的學號為0時,用break跳出循環。即if(p1->num==0)break。輸入值的范圍:學號、年齡為整型longnum;intage;姓名為字符串型15個字節charname[15];性別為字符串型,10個字節charsex[10];出生為字符串型,20個字節charchushen[20];地址為字符串型,30個字節chardizhi[30];郵箱為字符串型,輸入11位數字charemail[11]。二、輸出的形式輸出是以表格的形式輸出,即表格的每一行都能顯示第一個學生的信息,第二行是顯示第二個學生的信息。三、程序所能到達的功能對學生信息進行管理,學生信息包括職學號,姓名,年齡,性別,出生年月,地址,,E-mail。(1)系統以菜單方式工作(2)學生信息錄入功能。(3)輸出學生信息、瀏覽學生信息功能。(4)查詢和排序功能:(至少一種查詢方式),如按學號查詢、按姓名查詢等。(5)學生信息刪除、修改功能(任選項)。(6)添加學生信息。【測試數據】輸入:設輸入四個學生信息,以最后一個學生的學號為0來結束輸入,學號是整型。預期的輸出結果:預期的輸出結果請參見程序后的運行結果。【數據結構】排序記錄的數據元素表采用一維數組存儲結構,每個元素包含8個關鍵字段,其類型描述為:#include<stdio.h>#include<malloc.h>//分配size字節的存儲區#include<string.h>//包含字符串處理函數的頭文件,可以直接調用現有的字符串處理的一系列函數#definelensizeof(structstudent)//宏定義求字節運算符#include<stdlib.h>//清屏功能structstudent//聲明一個結構體類型structstudent{longnum;//定義學號為long型數據charname[15];//定義姓名 intage;//定義年齡charsex[3];//定義性別 charchushen[10];//定義出生 chardizhi[20];//定義出生地址 charphone[11];//定義 charemail[20];//定義郵箱structstudent*next;//next是指針變量,指向結構體變量【算法思想】利用一維結構體存放所有學生的信息,輸入后,在輸出時要對學生按學號的上下排序,然后可以執行按學號查詢學生信息,輸入學號,刪除學生信息,輸入學號可以找出該學生信息,然后選擇修改學生信息,如果來了新學生,還可以添加學生信息。【總體設計】輸入一個學生學號,輸入一個學生學號,來刪除該學生信息輸入學號,修改的學生信息顯示主菜單輸入函數學生排序輸出學生信息刪除學生信息修改學生信息添加學生信息用鍵盤輸入學生信息按學生學號上下排序在原有的學生上添加學生信息以表格的形式輸出學生信息圖1-1學生管理總體設計【模塊劃分】一、主函數:main()顯示系統工作菜單,顯示該系統的所有功能。告訴使用者所有將會調用的被調函數,再運用選擇函數switch即可根據使用者所輸入的學號進入對應的功能程序。并且對菜單做了一個循環,進行完一個選擇后,按回車鍵可進行清屏功能,把屏幕上除了主菜單以外都清空,然后可以繼續選擇那些可以使用的功能,這樣可以方便使用者使用,并且每一步都很清晰。以8退出系統。二、輸入函數:structstudent*creat()在該程序的前面已經定義了一個結構體structstudent用來儲存學生的所有信息,〔學號、年齡、姓名、性別、出生日期、地址、、郵箱〕。定義p1和p2,structstudent*p1,*p2;p1,p2是指向structstudent類型數據的指針變量。定義一個n=0,n是輸入的個數,主要作用是:如果輸入一個學生信息,首地址指向p1,head=p1;否那么p2的下一個地址指向p1,p2指向p1.p2->next=p1;p2=p1;學號控制循環。三、排序函數:voidpaixu(structstudent*head)用一個for語句做循環,不是NULL的話,指針指向下一個,按學生學號上下排序。整形直接交換,字符型用strcpy交換,類型相當于兩個數據之間的交換。四、輸出函數:voidprintlist(structstudent*head)在主函數里邊用while控制循環,輸出學生信息,然后指針指向下一個。查詢函數:voidfindList_num(structstudent*head)和voidfindList_num(structstudent*head)輸入一個學號或姓名,做一個for循環,即指針pt指向第一個地址,再定義一個指針p1,讓它等于pt,他是緊跟著pt后面的一個指針,讓p1->next不等于NULL,pt指向下一個地址。這樣就能修改最后一個學生信息了。如果要查詢的學生的學號在學生里,就輸出該學生信息,否那么,就輸出查詢的學生信息不存在。六、刪除函數:intshanchu(structstudent*head)輸入一個學號,先找到這個學生的信息。如果輸入的學號在學生信息中,就進行以下循環:如果輸入的是第一個學生的話,就head等于第二個學生信息;如果輸入的學生信息是最后一個,就讓倒數第二個等于NULL;否那么的話,就讓下一個學生信息覆蓋前一個。如果輸入的學號不在學生信息中,輸出“此學生信息不存在〞。七、修改函數:structstudent*delList(structstudent*head,longdel_num)輸入要修改的學號,找到該學生并且輸出該學生的信息。然后屏幕上會出現學生信息的所有工程,用switch進行選擇修改的工程。選擇后輸入新的學生信息,用它來覆蓋原來的學生信息。八、添加函數:voidinsert(structstudent*head)用一個while語句while(p2->next!=NULL)控制循環,p2的指針指向下一個地址,即p2=p2->next;這是找到最后一個地址,然后開辟動態存儲區,p1=(structstudent*)malloc(len);輸入要添加的學號,用學號為0來終止循環,如果不為0,就繼續輸入學生信息。【源程序】#include<stdio.h>#include<malloc.h>//分配size字節的存儲區#include<string.h>//包含字符串處理函數的頭文件,可以直接調用現有的字符串處理的一系列函數#definelensizeof(structstudent)//求字節運算符#include<stdlib.h>//清屏功能FILE*fp;structstudent//聲明一個結構體類型structstudent{intnum;//學號為整型charname[20];//姓名為字符串chargenter[10];//性別為字符串intage;//年齡為整型charxueli[20];//學歷為字符串intgongzi;//學號為整型charaddress[30];//地址為字符串charphone[11];//為字符串structstudent*next;//next是指針變量,指向結構體變量};voidmenu(){printf("===========學生信息管理系統==========\n\n");printf("1、錄入學生信息\n");printf("2、瀏覽學生信息\n");printf("3、查詢學生信息\n");printf("4、刪除學生信息\n"); printf("5、插入學生信息\n");printf("6、修改學生信息\n"); printf("7、排序學生信息\n"); printf("8、退出管理系統\n");printf("=====================================\n");}structstudent*creat()//錄入學生信息{ intn; structstudent*head;structstudent*p1,*p2; n=0;p1=p2=(structstudent*)malloc(len);scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chushen,p1->dizhi,p1->phone,p1->email);head=NULL;while(p1->num!=0) { n=n+1; if(n==1)head=p1; elsep2->next=p1; p2=p1; p1=(structstudent*)malloc(len); scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p1->num,&p1->age,p1->name,p1->sex,p1->chushen,p1->dizhi,p1->phone,p1->email);} p2->next=NULL;return(head);}voidinsert(structstudent*head)//插入學生信息{intsearch_num;structstudent*p,*q,*s;p=head;printf("在哪個學生前插入請輸入學號:\n");scanf("%d",&search_num);while((p!=NULL)&&(p->num!=search_num)){q=p;p=p->next;}s=(structstudent*)malloc(len);q->next=s;system("cls");printf("請輸入學生信息:\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n");scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&s->num,&s->age,s->name,s->sex,s->chushen,s->dizhi,s->phone,s->email); s->next=p;}voidprintList(structstudent*head)//瀏覽全部學生信息{structstudent*p;p=head;if(head==NULL)printf("沒有學生信息!!\n");else{do{ fread(p,len,1,fp);printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->dizhi,p->phone,p->email);p=p->next;}while(p!=NULL);}}voidfindList_num(structstudent*head,longsearch_num)//按學號查找{structstudent*p;p=head;while((p!=NULL)&&(p->num!=search_num))p=p->next;if(p!=NULL)printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->dizhi,p->phone,p->email);elseprintf("沒有該學生信息!!\n");}voidfindList_name(structstudent*head,char*search_name)//按姓名查找{structstudent*p;intcmp1=0,cmp=0;p=head;while(p!=NULL)if(strcmp(p->name,search_name)!=0){p=p->next;cmp++;}else{printf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s\n",p->num,p->age,p->name,p->sex,p->chushen,p->dizhi,p->phone,p->email);p=p->next;cmp1=1;}if(cmp!=0&&cmp1==0)printf("沒有該學生信息!!\n");}voidxiugai(structstudent*p1,longxiu_num)//修改學生信息{ structstudent*p2; p2=p1; while((p2!=NULL)&&(p2->num!=xiu_num)) p2=p2->next;if(p2!=NULL) { scanf("%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&p2->num,&p2->age,p2->name,p2->sex,p2->chushen,p2->dizhi,p2->phone,p2->email); } elseprintf("沒有該學生信息!!\n");}structstudent*delList(structstudent*head,longdel_num)//刪除學生信息{structstudent*p,*q;p=head;q=head;while(p&&(p->num!=del_num)){q=p;p=p->next;}if(p==NULL)printf("無此學號!\n");else{if(p==head){head=p->next;free(p);}else{q->next=p->next;free(p);}}returnhead;}voidpaixu(structstudent*head)//按學號排序{ structstudent*p,*f,*t; charch[100]; inti; t=f=p=head; for(p=head;p->next!=NULL;p=p->next) { for(t=head,f=t->next;t->next!=NULL;t=t->next,f=f->next) { if(t->num>f->num>0) { i=t->num; t->num=f->num; f->num=i; i=t->age; t->age=f->age; f->age=i; strcpy(ch,t->name); strcpy(t->name,f->name); strcpy(f->name,ch); strcpy(ch,t->sex); strcpy(t->sex,f->sex); strcpy(f->sex,ch); strcpy(ch,t->chushen); strcpy(t->chushen,f->chushen); strcpy(f->chushen,ch); strcpy(ch,t->dizhi); strcpy(t->dizhi,f->dizhi); strcpy(f->dizhi,ch); strcpy(ch,t->phone); strcpy(t->phone,f->phone); strcpy(f->phone,ch); strcpy(ch,t->email); strcpy(t->email,f->email); strcpy(f->email,ch); } } }// returnhead;}voidsave(structstudent*head)//保存為磁盤文件{ structstudent*p; if((fp=fopen("keshe","w"))==NULL)//翻開一個文件 { printf("cannotopenthisfile\n"); exit(0); } p=head; while(p!=NULL) { fprintf(fp,"%d\n",p->num); fprintf(fp,"%d\n",p->age); fprintf(fp,"%s\n",p->name); fprintf(fp,"%s\n",p->sex); fprintf(fp,"%s\n",p->chushen); fprintf(fp,"%s\n",p->dizhi); fprintf(fp,"%s\n",p->phone); fprintf(fp,"%s\n",p->email); p=p->next; } fclose(fp);}structstudent*read()//從磁盤讀取文件{ structstudent*head=NULL; structstudent*p=NULL; structstudent*t=NULL; inta;// fp=fopen("keshe","r"); if((fp=fopen("keshe","r"))==NULL)//翻開一個文件 { printf("cannotopenthisfile\n"); exit(0); } while(1) { t=(structstudent*)malloc(len); a=fscanf(fp,"%d\t%d\t%s\t%s\t%s\t%s\t%s\t%s",&t->num,&t->age,t->name,t->sex,t->chushen,t->dizhi,t->phone,t->email); if(a==0||a==-1) returnhead; t->next=NULL; if(p==NULL) { p=t; head=t; } else { p->next=t; p=p->next; p->next=NULL; } } fclose(fp);}voidmain()//主函數{intcode=0;structstudent*pt=NULL;for(code=1;;code++)//控制循環{menu();//調用菜單函數printf("請輸入序號:\n");//提示輸入序號scanf("%d",&code); system("cls");//清屏〔下邊也是這樣的功能〕switch(code)//選擇序號進行功能選擇{case1:{system("cls");printf("===========================輸入學生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n");pt=creat();//調用輸入函數 save(pt);//將數據存儲到磁盤中system("cls");printf("===========================輸入學生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("************成功輸入學生信息***********!!\n\n");printf("按回車鍵返回主菜單\n");getchar();getchar();//按回車鍵返回system("cls");};break;case2: {system("cls");printf("===========================學生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n");printList(read());//調用輸出函數〔是從磁盤中讀出的〕printf("=====================================================================\n"); printf("---------------------------------------------------------------------\n");printf("\n按回車鍵返回主菜單\n");getchar();getchar();system("cls");};break;case3:{intsearch=0;system("cls");printf("===========================查詢學生信息==============================\n");printf("---------------------------------------------------------------------\n");while(search!=3)//進入查詢功能函數{printf("1、按學號查詢\n2、按姓名查詢\n3、退出查詢\n");scanf("%d",&search);//插入查找的方式switch(search){case1://選擇學號查詢{longsearch_num;system("cls");printf("請輸入學生學號\n");scanf("%d",&search_num);system("cls");printf("===========================查詢結果==================================\n"); printf("---------------------------------------------------------------------\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n");findList_num(read(),search_num);//調用查找函數,將數據從磁盤中讀出printf("=====================================================================\n"); printf("---------------------------------------------------------------------\n");printf("\n按回車鍵返回查詢菜單\n");getchar();getchar();system("cls");};break;case2://按姓名查找{charsearch_name[15];system("cls");printf("請輸入學生姓名\n");scanf("%s",search_name);//輸入要查找的學生的姓名system("cls");printf("===========================查詢結果==================================\n");printf("---------------------------------------------------------------------\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n");findList_name(read(),search_name);//調用姓名查找函數printf("=====================================================================\n"); printf("---------------------------------------------------------------------\n");printf("\n按回車鍵返回查詢菜單\n");getchar();getchar();system("cls");};}}system("cls");};break;case4://刪除學生信息{longdel_num;system("cls");printf("===========================刪除學生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("請輸入要刪除學生信息的學號:\n");scanf("%d",&del_num);//輸入要刪除的學號system("cls"); pt=delList(read(),del_num);//調用刪除函數 save(pt);printf("=========================刪除結果================================\n");printf("-------------------------------------------------------------------\n");printf("學號為%d的學生信息成功刪除\n",del_num);printf("\n按回車鍵返回主菜單\n");getchar();getchar();system("cls");};break;case5://插入函數{ system("cls");printf("===========================插入學生信息==============================\n");printf("---------------------------------------------------------------------\n");insert(pt);//調用輸入函數 save(pt);//保存到磁盤中system("cls");printf("===========================插入學生信息==============================\n");printf("---------------------------------------------------------------------\n");printf("****插入學生信息成功***!!\n\n");printf("按回車鍵返回主菜單\n");getchar();getchar();system("cls");}break;case6://修改函數{ longsearch_num;system("cls");printf("請輸入要修改的學生學號:\n");scanf("%d",&search_num);//輸入要修改的學生學號system("cls");printf("===========================修改學生信息==================================\n"); printf("-------------------------------------------------------------------------\n"); printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n"); findList_num(read(),search_num);//調用查找函數 printf("\n"); printf("請輸入修改信息:\n"); printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n"); pt=read();xiugai(pt,search_num);//調用修改函數 save(pt);//保存printf("=====================================================================\n"); printf("---------------------------------------------------------------------\n"); printf("****修改學生信息成功***!!\n\n");printf("\n按回車鍵返回查詢菜單\n");getchar();getchar();system("cls");};break;case7://排序函數{system("cls"); printf("按學號從小到大排序\n\n");printf("===========================學生信息表================================\n");printf("---------------------------------------------------------------------\n");printf("學號\t年齡\t姓名\t性別\t出生\t地址\t\te-mail\n"); pt=read(); paixu(pt);//調用排序函數printList(pt);//調用顯示函數 save(pt);printf("=====================================================================\n"); printf("---------------------------------------------------------------------\n");printf("\n按回車鍵返回主菜單\n");getchar();getchar();system("cls");};break;case8:read();break;//返回函數}}【測試情況】1.翻開程序,進入主菜單,“學生信息管理系統〞,包括七項功能,〔1〕輸入學生信息,以輸入學號位0結束;〔2〕瀏覽學生信息;〔3〕按學生好號或姓名查詢學生信息;〔4〕

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論