第4章與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)_第1頁
第4章與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)_第2頁
第4章與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)_第3頁
第4章與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)_第4頁
第4章與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、第 4 章 與文件管理有關(guān)的系統(tǒng)功能調(diào)用實踐作業(yè)參照 “強(qiáng)化實踐能力培養(yǎng)課程內(nèi)容”中 “文件操作實踐能力培養(yǎng)考核選例 ”程序, 請構(gòu)造一個能管理文本文件的學(xué)生成績表的簡單數(shù)據(jù)庫管理系統(tǒng)。 設(shè)文本文件的學(xué)生成績表中每條學(xué)生成績記錄有3 個字段構(gòu)成:學(xué)號20 個字節(jié),姓名 20個字節(jié),成績10 個字節(jié),字段間用空格分割對齊。簡單數(shù)據(jù)庫管理系統(tǒng)具有基本的功能有:追加一條記錄, (僅允許文件主)按學(xué)號讀出一條記錄,按學(xué)號升序列出所有記錄.(提示:可建立一個學(xué)生成績表文件和一個以學(xué)號為主鍵的索引文件。 )答:實驗代碼及說明#include <malloc.h>#include <std

2、io.h>#include <stdlib.h>#define LEN sizeof(struct score)#define DEBUG#include <string.h>typedef struct scorechar no20;/ 記錄號char number20;/* 學(xué)號 */char name20;/* 姓名 */char grades10;/ 成績struct score *next;/ 下一個節(jié)點(diǎn)score;int m,n;score* load(score *head)score *p1,*p2;int m=0;char filepn10;FI

3、LE *fp;printf(" 請輸入文件路徑機(jī)文件名 n");scanf("%s",filepn);if(fp=fopen(filepn,"r+")=NULL)printf(" 不能打開文件n");exit(0);p1=(score *)malloc(LEN);head=NULL;while(!feof(fp)n=n+1;if(n=1)head=p1;else p2->next=p1;p2=p1;p1=(score *)malloc(LEN);fscanf(fp,"%s %s %s %s &quo

4、t;,p1->no,p1->number,p1->name,p1->grades);p2->next=p1;p1->next=NULL;n+;fclose(fp);return head;/ 追加score *append(score *head)score *p1,*p2,*p3;p3=(score *)malloc(LEN);printf(" 輸入學(xué)生信息: n");printf(" 記錄號 學(xué)號 姓名 成績 n");scanf("%s %s %s %s",p3->no,p3->nu

5、mber,p3->name,p3->grades);p1=head;if(head=NULL)/ 如果鏈表為空head=p3;p3->next=NULL;elseif(p1->next=NULL) p1->next=p3;p3->next=NULL;elsewhile(p1->next!=NULL)/ 若是還沒有到尾端的話p2=p1;p1=p1->next;p1->next=p3;p3->next=NULL;n+;return head;score * insert(score *head)score *p1,*p2,*p3;p3=(

6、score *)malloc(LEN);printf(" 輸入學(xué)生信息: n");printf(" 記錄號 學(xué)號 姓名 成績 n");scanf("%s %s %s %s",p3->no,p3->number,p3->name,p3->grades);p1=head;if(head=NULL)/ 如果鏈表為空head=p3;p3->next=NULL;elseif(p1->next=NULL) p1->next=p3;p3->next=NULL;elsewhile(p1!=NULL&am

7、p;&strcmp(p1->no,p3->no)<=0)/ 若是還沒有到尾端的話p2=p1;p1=p1->next;/p1->next=p3;/p3->next=NULL;p2->next=p3;p3->next=p1;n+;return head;score *del(score *head)score *p1,*p2,*p3;p3=(score *)malloc(LEN);printf(" 輸入刪除學(xué)生信息: n");printf(" 記錄號: n");scanf("%s",

8、p3->no);p1=head;if(head=NULL)/ 如果鏈表為空head=p3;/p3->next=NULL;printf(" 刪除失敗 n");return head;elseif(p1->next=NULL)if(p1->no=p3->no)head=NULL;return head;/p1->next=p3;/p3->next=NULL;elsewhile(p1!=NULL&&strcmp(p1->no,p3->no)!=0)/ 若是還沒有到尾端>的話p2=p1;p1=p1->

9、next;/p1->next=p3;/p3->next=NULL;p2->next=p1->next;/p3->next=p1;return head;score *search(score *head)score *p1,*p2,*p3;p3=(score *)malloc(LEN);printf(" 輸入查詢學(xué)生信息: n");printf(" 記錄號: n");scanf("%s",p3->no);p1=head;if(head=NULL)/ 如果鏈表為空head=p3;/p3->nex

10、t=NULL;printf(" 查詢失敗 n");return head;elseif(p1->next=NULL)if(p1->no=p3->no)return head;/p1->next=p3;/p3->next=NULL;elsewhile(p1!=NULL&&strcmp(p1->no,p3->no)!=0)/ 若是還沒有到尾端>的話p2=p1;p1=p1->next;/p1->next=p3;/p3->next=NULL;/p2->next=p1->next;/p3-&

11、gt;next=p1;printf("%s %s %s %sn",p1->no,p1->number,p1->name,p1->grades);return p1;void save(score *head)FILE *fp;score *p1;char filepn20;printf(" 輸入文件路徑以及文件名 n");scanf("%s",filepn);if(fp=fopen(filepn,"wt+")=NULL)printf(" 文件打開失敗n");exit(0)

12、;p1=head;while(p1!=NULL)fprintf(fp,"%s %s %s %s n",p1->no,p1->number,p1->name,p1->grades);p1=p1->next;fclose(fp);/return 0;void show(score *head)score *p;p=head;printf(" 學(xué)生信息 n");while(p!=NULL)printf("%s %s %s %s n",p->no,p->number,p->name,p->

13、grades);p=p->next;int main(int argc,char *argv)score *head=0;head=load(head);printf("Please input the operation you want to do:n""ttI.Insert a new record in a form of record-num() stu-num stu-name stu-scoren""ttA.Append a new record in a form of record-num() stu-num stu-n

14、ame stu-scoren""ttS.Sead a record by the value of record-numn""ttD.Delete a record by the value of record-numn""ttQ.Quit the DB systemn");char c;int flag=1;while(flag)/return;printf("Please enter the operation type you want to don");scanf("%c",&c);if(c>=96)c-=32;switch(c)cas

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論