




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、第 4 章 與文件管理有關的系統(tǒng)功能調(diào)用實踐作業(yè)參照 “強化實踐能力培養(yǎng)課程內(nèi)容”中 “文件操作實踐能力培養(yǎng)考核選例 ”程序, 請構造一個能管理文本文件的學生成績表的簡單數(shù)據(jù)庫管理系統(tǒng)。 設文本文件的學生成績表中每條學生成績記錄有3 個字段構成:學號20 個字節(jié),姓名 20個字節(jié),成績10 個字節(jié),字段間用空格分割對齊。簡單數(shù)據(jù)庫管理系統(tǒng)具有基本的功能有:追加一條記錄, (僅允許文件主)按學號讀出一條記錄,按學號升序列出所有記錄.(提示:可建立一個學生成績表文件和一個以學號為主鍵的索引文件。 )答:實驗代碼及說明#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;/* 學號 */char name20;/* 姓名 */char grades10;/ 成績struct score *next;/ 下一個節(jié)點score;int m,n;score* load(score *head)score *p1,*p2;int m=0;char filepn10;FI
3、LE *fp;printf(" 請輸入文件路徑機文件名 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(" 輸入學生信息: n");printf(" 記錄號 學號 姓名 成績 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(" 輸入學生信息: n");printf(" 記錄號 學號 姓名 成績 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(" 輸入刪除學生信息: 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(" 輸入查詢學生信息: 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(" 學生信息 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)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 危險品經(jīng)營公司管理制度
- 國企市公司食堂管理制度
- 德州中小學校服管理制度
- 2025年天津市濱海新區(qū)高三三模-政治試卷
- 2025屆湖北省部分學校高三下學期考前信息卷三政治試題
- 部隊考試題型及答案
- 變配電考試題及答案
- 北宋募兵考試題及答案
- 巴薩考試題及答案
- 景區(qū)場地合作管理制度
- 中級工電氣設備安裝工題庫
- 2023年重慶市開州區(qū)事業(yè)單位面向萬州、達州、云陽遴選15人考試備考試題及答案解析
- 財務部崗位廉潔風險點及防范措施匯總表
- 托物言志文章講評評改
- 古代漢語Ⅰ學習通課后章節(jié)答案期末考試題庫2023年
- 1919課件酒店硬件管理
- 2022北京海淀初二(下)期末英語試題含答案
- 西方經(jīng)濟學吉林大學期末考試題庫答案 2023春
- 2023年北京定額及計算規(guī)則
- 廣樂高速公路混凝土拌和站施工標準化指南剖析
- 珠三角商圈網(wǎng)絡規(guī)劃課件
評論
0/150
提交評論