



版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、精品數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)報(bào)告書學(xué)校青島科技大學(xué)學(xué)號姓名指導(dǎo)老師劉勇welcome精品課程設(shè)計(jì)的名稱: 學(xué)生成績管理1. 問題描述:學(xué)生成績管理是學(xué)校教務(wù)管理的重要組成部分,其處理信息量很大,該題目是對學(xué)生的成績管理作一個(gè)簡單的模擬,其中學(xué)生信息包括:學(xué)號、姓名與成績。成績分為課程1 成績、課程 2 成績、課程3 成績和總成績。要求設(shè)計(jì)一個(gè)簡易的成績管理系統(tǒng),輸入各門功課的成績后能自動求出總成績,并通過菜單選擇操作方式完成下列功能:登記學(xué)生成績;查詢學(xué)生成績;插入學(xué)生成績;刪除學(xué)生成績;按總成績降序排序。2. 基本要求:該題目涉及到單鏈表的各種操作,包括單鏈表的建立、結(jié)點(diǎn)的查找、 插入、刪除等基本運(yùn)
2、算。首先建立學(xué)生成績單鏈表,鏈表中每個(gè)結(jié)點(diǎn)由4 個(gè)域組成,分別為:學(xué)號、姓名、成績、存放下一個(gè)結(jié)點(diǎn)地址的next域。然后將要求完成的四項(xiàng)功能寫成四個(gè)函數(shù),登記學(xué)生成績對應(yīng)建立學(xué)生單鏈表的功能,后三個(gè)功能分別對應(yīng)單鏈表的查詢、插入與刪除三大基本操作。welcome精品3. 算法思想:Creat() 函數(shù)算法思想:從0 至 n 循環(huán)輸入n 個(gè)同學(xué)的三科成績,并且計(jì)算總成績。Inquiry()函數(shù)算法思想:將學(xué)號與已輸入的所有學(xué)號做比較,一旦相同則輸出該學(xué)號信息,否則顯示沒有該學(xué)生信息。Insert () 函數(shù)算法思想:生成一個(gè)新節(jié)點(diǎn),然后將其接到原有鏈表尾部。Delete()函數(shù)算法思想:通過ID
3、 找到該節(jié)點(diǎn),并刪去該節(jié)點(diǎn)。Sort( 函數(shù)算法思想:利用排序算法對每一個(gè)節(jié)點(diǎn)作比較并更換其在鏈表中的位置順序。4. 模塊劃分( 1 ) LinkList Creat(LinkList T,int n)其功能是創(chuàng)造節(jié)點(diǎn),錄入成績。( 2 ) void Inquiry(LinkList T)其功能是查詢與已知ID 一致的學(xué)生信息并展示出來。( 3 ) void Insert(LinkList T,int n)其功能是添加若干個(gè)學(xué)生的成績信息。( 4 ) void Delete(LinkList T)其功能是刪除若干個(gè)學(xué)生的成績信息。( 5 ) void Sort(LNode *p)其功能是排序并
4、展示若干個(gè)學(xué)生的成績信息。5. 數(shù)據(jù)結(jié)構(gòu):數(shù)據(jù)類型LNode定義如下:typedef struct LNodewelcome精品int ID;char name20;int score1;int score2;int score3;int total;struct LNode *next;LNode,*LinkList;6. 源程序:源代碼/main.c#include <stdio.h>#include <stdlib.h>typedef struct LNodeint ID;char name20;int score1;int score2;int score3;w
5、elcome精品int total;struct LNode *next;LNode,*LinkList;LinkList Creat(LinkList T,int n);void Delete(LinkList T);void Inquiry(LinkList T);void Insert(LinkList T,int n);void Sort(LNode *p);void Insert(LinkList T,int n)int i;LNode *r=T,*p;while(r->next)!=NULL)r=r->next;for(i=0;i<n;i+)p=(LNode *)
6、malloc(sizeof(LNode);printf("Please enter the student's student ID:");scanf("%d",&p->ID);welcome精品printf("Please enter the student's name: ");scanf("%s",p->name);printf("Please enter the student's score 1: ");scanf("%d"
7、;,&p->score1);printf("Please enter the student's score 2: ");scanf("%d",&p->score2);printf("Please enter the student's score 3: ");scanf("%d",&p->score3);p->total=p->score1+p->score2+p->score3;printf("The total sco
8、re is %dn",p->total);p->next=NULL;r->next=p;r=p;printf("nInsert is complete!");void Inquiry(LinkList T)int id;printf("Please enter the student ID you want to inquire about: ");scanf("%d",&id);welcome精品LNode *p=T;p=p->next;while(p!=NULL)if(p->ID=i
9、d)printf("nThestudentscoresinformationhasbeensuccessfullyinquired!n");printf("ID:%dnName:%snScore1:%dnScore2:%dnScore3: %dn",p->ID,p->name,p->score1,p->score2,p->score3); break;elsep=p->next;if(!p)printf("Sorry!Did not inquiry the student scores information
10、!");welcome精品void Delete(LinkList T)int id,flag=1;printf("Please enter the student ID you want to delete about: ");scanf("%d",&id);LNode *p=T;/LNode *q;while(p->next)!=NULL)if(p->next->ID=id)/q=p->next;p->next=p->next->next;/ delete q;printf("nT
11、hestudentscoresinformationhasbeensuccessfullydeleted!n");flag=0;break;elsep=p->next;welcome精品if(flag)printf("Sorry!Didnotdeletethestudentscoresinformationyouwanttodelete!");void Sort(LNode *p)LNode *r,*qian,*hou;qian=p->next;hou=qian->next;while(hou)if(qian->total>=hou-
12、>total)qian=hou;hou=hou->next;/ifelser=p;while(r->next->total>hou->total)welcome精品r=r->next;qian->next=hou->next;hou->next=r->next;r->next=hou;hou=qian->next;/elsep=p->next;int i=1;while(p)printf("Num:%dnID: %dnName:%snScore 1:%dnScore2: %dnScore3: %dnt
13、otal: %dnn",i,p->ID,p->name,p->score1,p->score2,p->score3,p->total);p=p->next;i+;LinkList Creat(LinkList T,int n)LNode *p,*r;int i;welcome精品T=(LNode *)malloc(sizeof(LNode);T->next=NULL;r=T;for(i=0;i<n;i+)p=(LNode *)malloc(sizeof(LNode);printf("Please enter the st
14、udent's student ID:");scanf("%d",&p->ID);printf("Please enter the student's name: ");scanf("%s",p->name);printf("Please enter the student's score 1: ");scanf("%d",&p->score1);printf("Please enter the student'
15、;s score 2: ");scanf("%d",&p->score2);printf("Please enter the student's score 3: ");scanf("%d",&p->score3);p->total=p->score1+p->score2+p->score3;printf("The total score is %dn",p->total);p->next=NULL;r->next=p;r=p;
16、welcome精品return T;int main()LNode *p;int n;while(1)system("cls");printf("Student Scores Managementnn");printf("1-Enter the student's scoren");printf("2-Query the student's scoren");printf("3-Insert the student's scoren");printf("4-De
17、lete the student's scoren");printf("5-Sort the student's scoren");printf("0-Exit systemnn");printf("Please enter a number selection(0-5):");int choice;scanf("%d",&choice);system("cls");if(choice=0)exit(0);welcome精品switch(choice)case
18、1:printf("Please enter the number of students you want to enteryour student's scores: ");scanf("%d",&n);p=Creat(p,n);printf("nnPleaseenteryourchoice(1):");printf("1-Esc");scanf("%d",&n);if(n)break;case 2:printf("Please enter the numb
19、er of students you want to queryyour student's scores: ");scanf("%d",&n);int i=0;while(i<n)Inquiry(p);i+;printf("nPleaseenteryourchoice(1):");printf("1-Esc");scanf("%d",&n);break;case 3:printf("Please enter the number of students you w
20、ant to insertyour student's scores: ");scanf("%d",&n);Insert(p,n);printf("nPleaseenteryourchoice(1):");printf("1-Esc");scanf("%d",&n);break;case 4:printf("Please enter the number of students you want to deleteyour student's scores: &q
21、uot;);scanf("%d",&n);i=0;while(i<n)Delete(p);i+;printf("nPleaseenteryourwelcome精品choice(1):");printf("1-Esc");scanf("%d",&n);break;case 5:Sort(p);printf("nPleaseenteryourchoice(1):");printf("1-Esc");scanf("%d",&n);b
22、reak;default:break;return 0;7. 測試情況:截圖:welcome精品welcome精品程序輸出為:Num: 1ID: 1Name: n1Score 1: 78Score 2: 89Score 3: 84total: 251Num: 2ID: 3Name: n3Score 1: 68Score 2: 89Score 3: 90welcome精品total: 247課程設(shè)計(jì)的名稱: 停車場的管理1. 問題描述:設(shè)停車場內(nèi)只有一個(gè)可停放n 輛汽車的狹長通道,且只有一個(gè)大門可供汽車進(jìn)出。汽車在停車場內(nèi)按車輛到達(dá)時(shí)間的先后順序,依次由北向南排列(大門在最南端,最先到達(dá)的第一輛
23、車停放在車場的最北端),若車場內(nèi)已停滿n 輛汽車,則后來的汽車只能在門外的便道上等候,一旦有車開走,則排在便道上的第一輛車即可開入;當(dāng)停車場內(nèi)某輛車要離開時(shí),在它之后開入的車輛必須先退出車場為它讓路,待該輛車開出大門外,其它車輛再按原次序進(jìn)入車場,每輛停放在車場的車在它離開停車場時(shí)必須按它停留的時(shí)間長短交納費(fèi)用。試為停車場編制按上述要求進(jìn)行管理的模擬程序。2. 基本要求:綜合利用棧和隊(duì)列模擬停車場管理,學(xué)習(xí)利用棧和隊(duì)列解決實(shí)際問題。以棧模擬停車場,以隊(duì)列模擬車場外的便道,按照從終端讀入的輸入數(shù)據(jù)序列進(jìn)行模擬管理。每一組輸入數(shù)據(jù)包括三個(gè)數(shù)據(jù)項(xiàng):汽車“到達(dá)”或“離去”信息、汽車牌照號碼及到達(dá)或離去
24、的時(shí)刻,對每一組輸入數(shù)據(jù)進(jìn)行操作后的輸出數(shù)據(jù)為:若是車輛到達(dá),則輸出汽車在停車場內(nèi)或便道上的停車位置;若是車離去;則輸出汽車在停車場內(nèi)停留的時(shí)間和應(yīng)交納的費(fèi)用(在便道上停留的時(shí)間不收費(fèi))。棧以順序結(jié)構(gòu)實(shí)現(xiàn),隊(duì)列以鏈表welcome精品實(shí)現(xiàn)。需另設(shè)一個(gè)棧,臨時(shí)停放為給要離去的汽車讓路而從停車場退出來的汽車,也用順序存儲結(jié)構(gòu)實(shí)現(xiàn)。輸入數(shù)據(jù)按到達(dá)或離去的時(shí)刻有序。棧中每個(gè)元素表示一輛汽車,包含兩個(gè)數(shù)據(jù)項(xiàng):汽車的牌照號碼和進(jìn)入停車場的時(shí)刻。3. 算法思想:停車場運(yùn)用棧的算法思想管理車輛信息;便道運(yùn)用隊(duì)列的算法思想管理等待進(jìn)入停車場的車輛信息;臨時(shí)停放讓路的車輛信息也用隊(duì)列算法思想管理。4. 模塊劃分:
25、void PRINT(CarNode *p,int room其功能為打印出場車的信息voidArrive(SeqStackCar*Enter,LinkQueueCar*W)其功能為記錄進(jìn)場車和等待進(jìn)場車信息void Leave(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *W)其功能為記錄出場車信息void List1(SeqStackCar *S)其功能為顯示存車信息5. 數(shù)據(jù)結(jié)構(gòu):( 1 )數(shù)據(jù)類型Time 定義如下:typedef struct timeint hour;int min;welcome精品Time;( 2 )數(shù)據(jù)類型
26、CarNode定義如下:typedef struct nodechar num10;Time reach;Time leave;CarNode;( 3 )數(shù)據(jù)類型 SeqStackCar 定義如下:typedef struct NODECarNode *stackMAX+1;int top;SeqStackCar;( 4 )數(shù)據(jù)類型 QueueNode 定義如下:typedef struct carCarNode *data;struct car *next;QueueNode;( 5 )數(shù)據(jù)類型 LinkQueueCar 定義如下:typedef struct Nodewelcome精品Qu
27、eueNode *head;QueueNode *rear;LinkQueueCar;6. 源程序:源代碼#include <stdio.h>#include <stdlib.h>#include <windows.h>#define price 0.15#define max 2/=int flag;/=typedef struct timeint hour;int min;Time;welcome精品typedef struct nodelong num;Time reach;Time leave;CarNode;/ 車輛信息結(jié)點(diǎn)typedef stru
28、ct NODECarNode *stack10;int top;SeqStackCar;/ 模擬車場typedef struct carCarNode *data;struct car *next;QueueNode;typedef struct NodeQueueNode *head;QueueNode *rear;LinkQueueCar;/ 模擬通道welcome精品/=void InitStack(SeqStackCar *s)/ 初始化棧int i;s->top=0;for(i=0;i<=max;i+)s->stacks->top=NULL;void Init
29、Queue(LinkQueueCar *Q)/ 初始化便道Q->head=(QueueNode *)malloc(sizeof(QueueNode);if(Q->head!=NULL)Q->head->next=NULL;Q->rear=Q->head;return (1);elsereturn (-1);welcome精品void PRINT(CarNode *p,int room)/打印出場車的信息int A1,A2,B1,B2;printf("n請輸入離開的時(shí)間:/*:*/");scanf("%d:%d",&am
30、p;p->leave.hour,&p->leave.min);printf("離開車輛的車牌號為:%ldn",p->num);printf("其到達(dá)時(shí)間為: %d:%dn",p->reach.hour,p->reach.min);printf("離開時(shí)間為 : %d:%dn",p->leave.hour,p->leave.min);A1=p->reach.hour;A2=p->reach.min;B1=p->leave.hour;B2=p->leave.min;
31、printf("應(yīng)交費(fèi)用為 :%2.1f RMBn",(B1-A1)*60+(B2-A2)*price);free(p);/=arrivevoid Arrive(SeqStackCar *Enter,LinkQueueCar *W)CarNode *p;QueueNode *t;p=(CarNode *)malloc(sizeof(CarNode);welcome精品/flushall();printf("請輸入車牌號(例 :12345):n");scanf("%ld",&p->num);if(Enter->top
32、<max)/ 車輛未滿,車進(jìn)場Enter->top+;printf("車輛請停在第%d 位置 .n",Enter->top);printf("請輸入到達(dá)時(shí)間:n");scanf("%d:%d",&p->reach.hour,&p->reach.min);Enter->stackEnter->top=p;else/ 車輛已滿printf("該車須在便道等待!.n");t=(QueueNode *)malloc(sizeof(QueueNode);t->d
33、ata=p;t->next=NULL;W->rear->next=t;W->rear=t;printf("Return main meun(1.return 0.quit)n");scanf("%d",&flag);welcome精品switch(flag)case 0:system("cls");printf("Thanks,Welcome to use nextn");exit(0);case 1:system("cls");/=leavevoid Leave
34、(SeqStackCar *Enter,SeqStackCar *Temp,LinkQueueCar *W)int i,room;CarNode *p,*t;QueueNode *q;if(Enter->top>0)/ 盼斷車場內(nèi)是否有車while(1)printf("請輸入車在車場的位置/1-%d/:n",Enter->top);/ 請輸入車在車welcome精品場的位置scanf("%d",&room);if(room>=1&&room<=Enter->top)break;while(Ent
35、er->top>room) /車輛離開Temp->top+;Temp->stackTemp->top=Enter->stackEnter->top;Enter->stackEnter->top=NULL;Enter->top-;p=Enter->stackEnter->top;Enter->stackEnter->top=NULL;Enter->top-;while(Temp->top>=1)Enter->top+;Enter->stackEnter->top=Temp-&g
36、t;stackTemp->top;Temp->stackTemp->top=NULL;Temp->top-;welcome精品PRINT(p,room);/ 判斷通道上是否有車及車場是否已滿if(W->head!=W->rear)&&Enter->top<max)/ 便道的車輛進(jìn)場q=W->head->next;t=q->data;Enter->top+;printf("便道的 %s 號車進(jìn)入車場第%d 位置 .n",t->num,Enter->top);printf(&qu
37、ot;請輸入現(xiàn)在的時(shí)間/*:*/:n");scanf("%d:%d",&t->reach.hour,&t->reach.min);W->head->next=q->next;if(q=W->rear)W->rear=W->head;Enter->stackEnter->top=t;free(q);elseprintf("便道;里沒有車.n");elseprintf("車場里沒有車.n");/ 車場里沒有車printf("Return mai
38、n meun(1.return 0.quit)n");scanf("%d",&flag);welcome精品switch(flag)case 0:system("cls");printf("Thanks,Welcome to use nextn");exit(0);case 1:system("cls");/=showvoid List1(SeqStackCar *S)/ 顯示存車信息int i;if(S->top>0)/ 判斷車場內(nèi)是否有車printf("車場 n"
39、;);for(i=1;i<=S->top;i+)printf("位置到達(dá)時(shí)間:%d:%dt號碼 :%ldn",i,S->stacki->reach.hour,S->stacki->reach.min,S->stacki->num);welcome精品elseprintf("車場里沒有車.n");printf("Return main meun(1.return 0.quit)n");scanf("%d",&flag);switch(flag)case 0:sy
40、stem("cls");printf("Thanks,Welcome to use nextn");exit(0);case 1:system("cls");void List2(LinkQueueCar *W)QueueNode *p;p=W->head->next;if(W->head!=W->rear)welcome精品printf("等待車輛的號碼為:");while(p!=NULL)printf("%ldn",p->data->num);p=p-&g
41、t;next;elseprintf("便道里沒有車.n");printf("Return main meun(1.return 0.quit)n");scanf("%d",&flag);switch(flag)case 0:system("cls");printf("Thanks,Welcome to use nextn");exit(0);case 1:system("cls");void List(SeqStackCar S,LinkQueueCar W)welcome精品int tag;printf("1.車場 n");printf("2.便道 n&q
溫馨提示
- 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 微處理器與接口技術(shù) 課件 第5章 接口及標(biāo)準(zhǔn)化
- 2025年心理測量與評估方法學(xué)的綜合能力考試卷及答案
- 2025年教育法與教育政策的綜合能力考核試卷及答案
- 2025年健康行為與心理介入的實(shí)務(wù)能力考試試卷及答案
- 2025年化學(xué)工程師考核試卷及答案
- 2025年中國郵政集團(tuán)有限公司廣西壯族自治區(qū)分公司校園招聘筆試模擬試題及完整答案詳解1套
- 特定場所安全管理制度
- 特殊學(xué)校學(xué)生管理制度
- 特殊工時(shí)休假管理制度
- 特殊患者安全管理制度
- GB/T 11363-2008釬焊接頭強(qiáng)度試驗(yàn)方法
- GB 12995-2006機(jī)動輪椅車
- 40篇短文搞定高考英語3500詞
- 【山東】國際足球運(yùn)動小鎮(zhèn)概念規(guī)劃方案
- 海氏(hay)職位分析法-介紹、實(shí)踐與評價(jià)合集課件
- 煤礦安全規(guī)程露天部分參考題庫(含答案)
- 有趣的英漢互譯-課件
- (參考)菲達(dá)公司國內(nèi)電除塵器業(yè)績表
- 步進(jìn)式加熱爐耐材砌筑施工方案
- GB-T12232-2005- 通用閥門 法蘭連接鐵制閘閥
- 2022年中國電信店長技能四級認(rèn)證教材
評論
0/150
提交評論