數(shù)據(jù)結構課程設計之日程計劃管理_第1頁
數(shù)據(jù)結構課程設計之日程計劃管理_第2頁
數(shù)據(jù)結構課程設計之日程計劃管理_第3頁
數(shù)據(jù)結構課程設計之日程計劃管理_第4頁
數(shù)據(jù)結構課程設計之日程計劃管理_第5頁
已閱讀5頁,還剩18頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、第一題:1,【實驗題目及要求】問題描述設計一個程序,記錄并管理日程計劃。基本要求(1)日程計劃信息包括日程計劃ID號,日程計劃開始日期和時間,日程計劃結束日期和時間,日程計劃名,日程計劃參與人員,日程計劃地點,日程計劃提醒日期和時間。(2)采用雙向循環(huán)鏈表表示日程計劃信息。采用三個雙向循環(huán)鏈表:第一個雙向循環(huán)鏈表表示未開始的日程計劃信息,按照日程計劃開始日期和時間先后排序;第二個雙向循環(huán)鏈表表示正在進行的日程計劃信息(可以多項計劃同時進行),按照日程計劃開始日期和時間先后排序;第三個雙向循環(huán)鏈表表示已過期的日程計劃信息,按照日程計劃開始的日期和時間倒序排序。(3)日程計劃信息采用文件方式輸入。

2、日程計劃信息信息示例如下,每條信息一行:日程計劃ID號開始日期開始時間結束日期結束時間計劃名20141011001;2014-10-11;8:00:00;2014-10-11;10:00:00;數(shù)據(jù)結構上課;張三;6202;2014-10-11;7:40:00(4)要求模擬數(shù)據(jù)中日程計劃信息至少30條以上。(5)實現(xiàn)以下功能:a.輸入新的計劃;b.根據(jù)當前時間查詢未開始的計劃,包括當天未開始的計劃、本周或本月未開始的計劃;c.查詢并輸出已結束的計劃;d.查詢正在進行的計劃;e.根據(jù)當前時間,輸出正提醒即將開始的計劃。(6)可在此要求基礎上進行功能擴展,比如周期性重復計劃的設置和提醒等。2,【源

3、代碼(C語言)#include<stdio.h>#include<stdlib.h>#include<time.h>#include<string.h>#defineNAMESIZE20/宏定義名字最大長度#definePLACESIZE20/地名最大長度#defineOK1#defineERROR0typedefstructPeoplecharpeoNameNAMESIZE;structPeople*next;People;/定義日程計劃參與人員結構體typedefstructTeamintpeoNumber;/參與人數(shù)People*peo;/

4、參與人員的具體姓名Team;/定義日程計劃結構體(核心)typedefstructPlancharID12;/日程IDtime_tstrartTime,finishTime,warnTime;/開始時間和結束時間charnameNAMESIZE;/日程名稱Teampeople;/參與人員charplacePLACESIZE;/地點structPlan*pre,*next;Plan;/定義個人日程結構體typedefstructcharnameNAMESIZE;/個人姓名time_tfirstTime;intprePlanNum,presentPlanNum,postPlanNum;/開啟日程管

5、理的時間Plan*prePlan,*presentPlan,*postPlan;PlanManege;ntInitPlanManege(PlanManege*);初始化日程管理ntInputNewPlan(PlanManege*);/添加新的計劃ntSearchPrePlan(PlanManege*);/查詢尚未開始的計劃ntSearchPostPlan(PlanManege*);/查詢已經結束的計劃ntSearchPresent(PlanManege*);/查詢正在進行的計劃ntSearchWarnPlan(PlanManege*);/查詢即將開始的計劃ntInputFileStr(FILE

6、*,char*);/輸入文件的字符串ntInputSevalFileStr(FILE*,Team*);/輸入多個文件字符串ntInputFileTime(FILE*,time_t*);/按格式輸入文件時間ntPlanSort(Plan*,PlanManege*);/計劃排序ntInsertPlan(Plan*,Plan*);/插入計劃ntInputScreenTime(time_t*);/按格式讀入時間/讀入多個字符串ntInputTeamName(People*);ntPrintPlan(Plan*);/計劃輸出函數(shù)voidmain()printf(6退出n");printf(*n

7、scanf("%d",&i);switch(i)case 1: InputNewPlan(&me);breakcase 2: SearchPrePlan(&me);breakcase 3: SearchPresentPlan(&me);break;case 4: SearchPostPlan(&me);breakcase 5: SearchWarnPlan(&me);breakcase6:system("PAUSE");exit(0);default:printf("輸入有誤!");br

8、eakntInitPlanManege(PlanManege*me)FILE*fp;time_tpresentTime;Plan*iplan;charch,peoName20;iplan=(Plan*)malloc(sizeof(Plan);me->postPlan=iplan;me->postPlan->next=iplan;me->postPlan->pre=iplan;me->postPlanNum=0;iplan=(Plan*)malloc(sizeof(Plan);me->prePlan=iplan;me->prePlan->ne

9、xt=iplan;me->prePlan->pre=iplan;me->prePlanNum=0;iplan=(Plan*)malloc(sizeof(Plan);me->presentPlan=iplan;me->presentPlan->next=iplan;me->presentPlan->pre=iplan;me->presentPlanNum=0;/打開myplans.txt文件,文件按照格式有一系列寫好的日程計劃fp=fopen("myplans.txt","r")if(!fp)print

10、f("文件myplans.txt不存在或無法打開!n");system("PAUSE")printf("已到文件末尾!”);while(!feof(fp)/printf("這是第一次");iplan=(Plan*)malloc(sizeof(Plan)/初始化planiplan->people.peoNumber=0;/把計劃參與人數(shù)初始化為0iplan->people.peo=NULL;/人名指向為空fgets(iplan->ID,12,fp);/printf("%s",iplan-&

11、gt;ID);fgetc(fp);fgetc(fp);InputFileTime(fp,&iplan->strartTime);InputFileTime(fp,&iplan->finishTime);InputFileStr(fp,iplan->name);InputSevalFileStr(fp,&(iplan->people);InputFileStr(fp,iplan->place);InputFileTime(fp,&iplan->warnTime);ch=fgetc(fp);/ch=fgetc(fp);/*pres

12、entTime=time(NULL);if(iplan->strartTime>presentTime)insertPlanList(iplan,me->prePlan);elseif(iplan->finishTime<present)insertPlanList(iplan,me->postPlan);elseinsertPlanList(iplan,me->presentPlan);*/PrintPlan(iplan);if(!PlanSort(iplan,me)printf("here!")returnERROR;/prin

13、tf("存儲完畢");ntInputNewPlan(PlanManege*me)/功能函數(shù),添加一個計劃Plan*planp;planp=(Plan*)malloc(sizeof(Plan);printf("請輸入計劃的ID號n")scanf("%s",&planp->ID);InputScreenTime(&planp->strartTime);InputScreenTime(&planp->finishTime);printf("請輸入計劃名稱n")scanf(&quo

14、t;%s",planp->name);printf("請輸入計劃參與人數(shù)n")scanf("%d",&planp->people.peoNumber);InputTeamName(&planp->people);printf(請輸入計劃地點nscanf("%s",planp->place);printf("請輸入提醒時間n(如2010-10-1018:00:00)n")InputScreenTime(&planp->warnTime);if(PlanS

15、ort(planp,me)returnOKelsereturnERRORntSearchPrePlan(PlanManege*me)time_tpresentTime;structtm*timep1,*timep2;Plan*p;presentTime=time(NULL);timep1=gmtime(&presentTime);p=me->prePlan->pre;printf("今天未開始的計劃有:n")while(p!=me->prePlan)timep2=gmtime(&(p->strartTime);if(timep1-&g

16、t;tm_year=timep2->tm_year&&timep1->tm_mday=imep2->tm_mday&&timep1->tm_mon=timep2->tm_mon)PrintPlan(p);p=p->pre;breakprintf("本月開始的計劃有:n");while(p!=me->prePlan)timep2=gmtime(&(p->strartTime);if(timep1->tm_mon=timep2->tm_mon)PrintPlan(p);p=p-&

17、gt;pre;breakprintf("其他時間開始的計劃有:n");while(p!=me->prePlan)/無需比較,把剩下的都輸出PrintPlan(p);p=p->pre;returnOK;ntSearchPostPlan(PlanManege*me)inti=1;Plan*p;p=me->postPlan->next;while(p!=me->postPlan)printf("%d'n",i);PrintPlan(p);p=p->next;i+;returnOK;ntSearchPresentPla

18、n(PlanManege*meinti=0;Plan*p;p=me->presentPlan->next;while(p!=me->presentPlan)printf("%d'n",i);PrintPlan(p);p=p->next;ntSearchWarnPlan(PlanManege*me)Plan*planp;time_tpresentTime;presentTime=time(NULL)planp=me->prePlan->next;while(planp!=me->prePlan)if(presentTime&g

19、t;=planp->warnTime)PrintPlan(planp);planp=planp->next;ntInputFileStr(FILE*fp,char*str)charch;inti;ch=fgetc(fp);ch=fgetc(fp);for(i=0;ch!=''i+)if(ch=-1)return0;/printf("%s'n",str);returnOK;ntInputSevalFileStr(FILE*fp,Team*T)inti;charch;People*peop;doch=fgetc(fp);ch=fgetc(fp

20、);if(ch!=-1&&ch!='')peop=(People*)malloc(sizeof(People)for(i=0;ch!=''&&ch!=','i+)peop->peoNamei=ch;ch=fgetc(fp)peop->peoNamei='0/printf("%sn",peop->peoName);/把讀取到的姓名存入參與人員姓名鏈表后/插入第一個peop->next=T->peo;T->peo=peop;T->peoNumber+

21、;returnERROR;while(ch!='');returnOK;/InputSevalStrntInputFileTime(FILE*fp,timet*time)structtmitime;intyear,month;fscanf(fp,"%d-%d-%d;",&year,&month,&itime.tm_mday);fscanf(fp,"%d:%d:%d;",&itime.tm_hour,&itime.tm_min,&itime.tm_sec);itime.tm_year=year

22、-1900;itime.tm_mon=month-1;itime.tm_isdst=-1;*time=mktime(&itime);/printf("%dn",itime.tm_year);returnOK;/InputTimentPlanSort(Plan*p,PlanManege*pmtime_tpresentTime;presentTime=time(NULL)if(p->strartTime>presentTime)InsertPlan(p,pm->prePlan);elseif(p->finishTime<presentTim

23、e)InsertPlan(p,pm->postPlan);elseInsertPlan(p,pm->presentPlan);returnOK;ntInsertPlan(Plan*p,Plan*pl)/把計劃按照時間順序插入計劃鏈表中Plan*q;q=plwhile(1)if(q->next->strartTime<=p->strartTime|q->next=pl)/插入p->next=q->next;p->pre=q;q->next=pp->next->pre=pntInputScreenTime(timetst

24、ruct tm strTime;int year,month;scanf( "%d-%d-%d" ,&year,&month,&strTime.tm_mday);scanf( "%d:%d:%d” ,&strTime.tm_hour,&strTime.tm_min,&strTime.tm_sec);strTime.tm_year = year - 1900;strTime.tm_mon = month-1;nt PrintPlan( Plan *planp )int i;People *p;printf("

25、 計劃 ID: %sn" ,planp ->ID);printf(" 開始時間:s",ctime(&( planp ->strartTime );t)ntInputTeamName(Team*T)T->peo=NULL;printf("請依次輸入每個參與者姓名,每次以回車鍵結束n")for(i=0;i<T->peoNumber;i+)peop=(People*)malloc(sizeof(People)scanf("%s",&peop->peoName);peop->next=T->peo;T->peo=peop;returnOK;printf("結束

溫馨提示

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

評論

0/150

提交評論