編程實(shí)習(xí)報(bào)告_第1頁(yè)
編程實(shí)習(xí)報(bào)告_第2頁(yè)
編程實(shí)習(xí)報(bào)告_第3頁(yè)
編程實(shí)習(xí)報(bào)告_第4頁(yè)
編程實(shí)習(xí)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

編程實(shí)習(xí)報(bào)告姓名:萬(wàn)林學(xué)院:自動(dòng)化學(xué)號(hào):09061334班級(jí):09062813指導(dǎo)老師:王春林朱勝利一、實(shí)習(xí)目的:通過編寫程序復(fù)習(xí)大一所學(xué)的C語(yǔ)言知識(shí),學(xué)習(xí)在MicrosoftVisualC++環(huán)境下編輯、編譯及運(yùn)行C程序。二、實(shí)習(xí)任務(wù)在熟練掌握C語(yǔ)言基礎(chǔ)下設(shè)計(jì)并實(shí)現(xiàn)一個(gè)學(xué)生信息系統(tǒng),管理一個(gè)班的學(xué)生的基本信息。每個(gè)學(xué)生的信息名片包含的主要信息有:姓名、電話、手機(jī)、學(xué)號(hào)、四項(xiàng)信息。要求該軟件實(shí)現(xiàn)以下功能:創(chuàng)建學(xué)生信息聯(lián)表添加學(xué)生信息刪除學(xué)生信息查找學(xué)生信息顯示所有學(xué)生信息保存鏈表數(shù)據(jù)到文件修改學(xué)生信息三、程序流程圖(見附錄)四、原代碼:#include<stdio.h>#include<stdlib.h>#include<string.h>#defineCH30/*最大字符數(shù),可修改*/structstudent{ charname[CH];/*姓名*/ intage;/*年齡*/ chartel[CH];/*電話*/ intnum; /*學(xué)號(hào)*/structstudent*next;};structstudent*creat() //創(chuàng)建鏈表函數(shù){inti; structstudent*p1,*p2; structstudent*head; intnum_node; printf("輸入學(xué)生人數(shù)及資料\n"); printf("人數(shù):");scanf("%d",&num_node); p1=p2=(structstudent*)malloc(sizeof(structstudent));//這里創(chuàng)建了一個(gè)節(jié)點(diǎn) printf("姓名:");scanf("%s",&p1->name);printf("年齡:");scanf("%d",&p1->age);printf("電話:");scanf("%s",&p1->tel); printf("學(xué)號(hào):"); scanf("%d",&p1->num); head=p1; for(i=1;i<num_node;i++) { if(num_node==1) { head=p1; head->next=NULL; returnhead; } else { p1=(structstudent*)malloc(sizeof(structstudent)); printf("姓名:"); scanf("%s",&p1->name); printf("年齡:"); scanf("%d",&p1->age); printf("電話:"); scanf("%s",&p1->tel); printf("學(xué)號(hào):"); scanf("%d",&p1->num); p2->next=p1; p2=p1; } } p2->next=NULL; returnhead;}voidprint(structstudent*head) //顯示鏈表信息{ structstudent*p; p=head; printf("輸出學(xué)生信息:\n"); while(p!=NULL) { printf("姓名:%s年齡:%d電話:%s學(xué)號(hào):%d",p->name,p->age,p->tel,p->num); p=p->next; }}structstudent*load()//把鏈表從文件中讀入到新的鏈表中{ structstudent*p1,*p2,*head=NULL; FILE*fp; if((fp=fopen("mm.txt","rb"))==NULL) //mm.txt為文件名,rb為只讀使用方式 { printf("打開失敗\n"); exit(1); } printf("\n-----文件讀取!-----\n"); p1=(structstudent*)malloc(sizeof(structstudent)); if(!p1) { printf("內(nèi)存溢出!\n"); returnhead; } head=p1; while(!feof(fp)) //feof函數(shù)判斷文件是否讀到末尾 { if(1!=fread(p1,sizeof(structstudent),1,fp)) //fread為輸入函數(shù)break; printf("姓名:%s,年齡:%d,電話:%s,學(xué)號(hào):%d\n",p1->name,p1->age,p1->tel,p1->num); p1->next=(structstudent*)malloc(sizeof(structstudent)); if(!p1->next) { printf("溢出內(nèi)存!\n"); returnhead; } p2=p1; p1=p1->next; } p2->next=NULL; fclose(fp); printf("---成功讀取文件!!!---\n"); returnhead;}structstudent*del(structstudent*head) //刪除學(xué)生信息{structstudent*p1,*p2;charname[CH];printf("請(qǐng)輸入要?jiǎng)h除的學(xué)生的姓名:");scanf("%s",&name);p1=head;while((strcmp(p1->name,name)!=0)&&(p1->next!=NULL))//字符串比較函數(shù){ p2=p1;p1=p1->next;}if(strcmp(p1->name,name)==0){if(p1==head)//是頭節(jié)點(diǎn){head=p1->next;free(p1);}elseif(p1->next==NULL)//是尾節(jié)點(diǎn){p2->next=NULL;free(p1);}else{p2->next=p1->next;free(p1);}printf("刪除成功\n");}returnhead;}structstudent*insert(structstudent*head) //增加學(xué)生信息{structstudent*pnew;pnew=(structstudent*)malloc(sizeof(structstudent));printf("姓名:");scanf("%s",&pnew->name);printf("年齡:");scanf("%d",&pnew->age);printf("電話:");scanf("%s",&pnew->tel);printf("學(xué)號(hào):");scanf("%d",&pnew->num);pnew->next=head;head=pnew;returnhead;}structstudent*find(structstudent*head) //查詢學(xué)生信息{ structstudent*p1,*p2; charname[CH]; printf("查詢學(xué)生姓名:"); scanf("%s",name);p1=head; while(strcmp(name,p1->name)!=0&&p1!=NULL) { p2=p1;p1=p1->next; } printf("姓名:%s年齡:%d電話:%s學(xué)號(hào):%d\n",p1->name,p1->age,p1->tel,p1->num); returnhead;}structstudent*gai(structstudent*head) //修改學(xué)生信息{structstudent*p1,*p2;charn;charname[30];printf("請(qǐng)輸入要修改的學(xué)生的姓名:");scanf("%s",&name);p1=head;while((strcmp(p1->name,name)!=0)&&(p1->next!=NULL)){ p2=p1;p1=p1->next;}if(strcmp(p1->name,name)==0)//找到了!{ printf("1.修改姓名\n"); printf("2.修改年齡\n"); printf("3.修改電話\n"); printf("4.修改學(xué)號(hào)\n"); printf("請(qǐng)選擇菜單編號(hào):"); scanf("%d",&n); switch(n) { case1:printf("輸入新姓名:"); scanf("%s",&p1->name);break; case2:printf("輸入新年齡:"); scanf("%d",&p1->age);break; case3:printf("輸入新電話:"); scanf("%s",&p1->tel);break; case4:printf("輸入新學(xué)號(hào):"); scanf("%d",&p1->num);;break; default:printf("請(qǐng)?jiān)?-4之間重新選擇\n"); }}returnhead;}voidsave(structstudent*head) //保存鏈表數(shù)據(jù)到文件{FILE*fp;structstudent*p;if((fp=fopen("mm.txt","w"))==NULL) //fopen函數(shù)使變量w與文件mm.txt相連{ printf("打開文件失敗\n"); exit(1);}printf("\n正在保存......\n");p=head;printf("保存完成,head:%d\n",head);while(p!=NULL){ printf("姓名:%s年齡:%d電話:%s學(xué)號(hào):%d\n",p->name,p->age,p->tel,p->num); fwrite(p,sizeof(structstudent),1,fp); //fwrite為輸出函數(shù) p=p->next;}fclose(fp); //關(guān)閉文件printf("-----保存成功!!-----\n");}voidmain(){ charch; structstudent*head; for(;;) { printf("\t\t學(xué)生信息系統(tǒng)\n");printf("*****系統(tǒng)功能菜單*****\n");printf("----------------------------\n"); printf("1.創(chuàng)建學(xué)生信息鏈表\n"); printf("2.顯示學(xué)生信息\n"); printf("3.刪除學(xué)生信息\n"); printf("4.增加學(xué)生信息\n"); printf("5.保存學(xué)生信息\n"); printf("6.查詢學(xué)生信息\n"); printf("7.修改學(xué)生信息\n"); prin

溫馨提示

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

最新文檔

評(píng)論

0/150

提交評(píng)論