C語(yǔ)言實(shí)現(xiàn)旅游資訊管理系統(tǒng)
本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)旅游資訊管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
題目:
一、主體功能點(diǎn)要求
1.設(shè)計(jì)主菜單實(shí)現(xiàn)用戶交互
a、添加旅游資訊記錄
每條記錄至少包含如下項(xiàng):編號(hào)、日程安排、費(fèi)用、點(diǎn)贊數(shù)。添加旅游資訊記錄時(shí),要求鍵盤輸入對(duì)應(yīng)的編號(hào)、日程安排等信息。添加成功后屏幕打印出相應(yīng)的提示信息。
b、查詢旅游資訊記錄
查詢旅游資訊記錄時(shí),打印相應(yīng)提示語(yǔ)句,用戶輸入“1~3”之間的整數(shù),如果輸入1,按編號(hào)大小升序排序顯示所有的記錄;如果輸入2,按點(diǎn)贊數(shù)降序排序顯示所有的記錄;如果輸入3,則提示輸入記錄的編號(hào),然后單獨(dú)顯示該編號(hào)對(duì)應(yīng)的記錄(若無(wú)該編號(hào)的記錄,打印出錯(cuò)的提示信息,并返回主菜單)。
c、修改旅游資訊記錄
修改旅游資訊記錄時(shí),打印相應(yīng)提示語(yǔ)句,輸入待修改記錄的編號(hào)(若無(wú)該編號(hào)的記錄,打印出錯(cuò)的提示信息,并返回主菜單),然后輸入需修改記錄的字段名稱,比如編號(hào)、日程安排、費(fèi)用等(點(diǎn)贊數(shù)不能在此處修改),再輸入相應(yīng)字段修改后的值。
d、刪除旅游資訊記錄
刪除旅游資訊記錄時(shí),打印相應(yīng)提示語(yǔ)句,輸入待刪除記錄的編號(hào)(若無(wú)該編號(hào)的記錄,打印出錯(cuò)的提示信息,并返回主菜單),然后打印是否刪除的提示語(yǔ)句,輸入y,刪除選中的記錄,否則不進(jìn)行刪除操作。
e、點(diǎn)贊旅游資訊記錄
點(diǎn)贊旅游資訊記錄時(shí),打印相應(yīng)提示語(yǔ)句,輸入待刪除記錄的編號(hào)(若無(wú)該編號(hào)的記錄,打印出錯(cuò)的提示信息,并返回主菜單),該記錄的點(diǎn)贊數(shù)增1。
2、擴(kuò)展要求:
能夠?qū)崿F(xiàn)將編輯完畢的旅游資訊記錄保存在txt文件中,每次重新打開(kāi)程序能夠?qū)胫按鎯?chǔ)的旅游資訊記錄。
二、編程要求
1、注意每條旅游資訊記錄至少包含編號(hào)、日程安排、費(fèi)用、點(diǎn)贊數(shù)這四個(gè)字段,并且要求將字段的信息定義為一個(gè)結(jié)構(gòu)體。
2、若采用鏈表存儲(chǔ)每條旅游資訊記錄,則屬于擴(kuò)展實(shí)現(xiàn),可加分。
3、注意將程序的功能點(diǎn)進(jìn)行模塊化設(shè)計(jì),避免將全部功能點(diǎn)實(shí)現(xiàn)代碼寫在主函數(shù)main中。
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> ?typedef struct Tour *tour,TOUR; ? ? struct Tour ?? ?{ ?? ??? ?int id;//編號(hào) ?? ??? ?char plan[30];//日程安排 ?? ??? ?float cost;//花費(fèi) ?? ??? ?int agree;//點(diǎn)贊數(shù) ?? ??? ?tour next; ?? ?}; ?? ?tour head,tail; void read_tour();// 從data.txt中讀取信息保存到單鏈表中 void write_cars();//把旅游資訊記錄存儲(chǔ)到data.txt中 void add_tour();//添加旅游資訊記錄 void search_tour();//查詢旅游資訊記錄 void display_tourid();//按編號(hào)大小來(lái)顯示旅游資訊記錄 void display_touragree();//按點(diǎn)贊數(shù)大小來(lái)顯示旅游資訊記錄 void display();//將所有的旅游資訊記錄輸出到顯示器中 void search_tourid();//按照編號(hào)來(lái)查詢某個(gè)旅游資訊記錄 void change_tour();//修改旅游資訊記錄 void delect_tour();//刪除旅游資訊記錄 void agree_tour();//點(diǎn)贊某個(gè)旅游資訊記錄 int main(){ ?? ?printf("==========歡迎使用旅游資訊管理系統(tǒng)==========\n"); ?? ?read_tour();//讀取文件 ?? ?int i; ?? ?while(true)//每當(dāng)執(zhí)行完一個(gè)功能時(shí),都會(huì)自動(dòng)顯示主菜單 ?? ?{ ?? ??? ?while(1)//判斷數(shù)字輸入是否正確,如果不正確繼續(xù)循環(huán)輸入 ?? ??? ?{ ?? ??? ??? ?printf("請(qǐng)選擇相關(guān)操作:\n1.增加旅游資訊記錄\n2.查詢旅游資訊記錄\n3.瀏覽旅游資訊記錄\n"); ?? ??? ??? ?printf("4.修改旅游資訊記錄\n5.刪除旅游資訊記錄\n6.點(diǎn)贊旅游資訊記錄\n7.保存數(shù)據(jù)并退出管理系統(tǒng)\n"); ?? ? ? ? ? ?printf("請(qǐng)輸入數(shù)字選擇要實(shí)現(xiàn)的功能:\n"); ?? ??? ??? ?scanf("%d",&i); ?? ??? ??? ?if(i>=1&&i<=7) ?? ??? ??? ?{ ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?printf("數(shù)字錯(cuò)誤,請(qǐng)重新輸入"); ?? ??? ? ? ?} ?? ??? ?} ?? ??? ?switch(i) ?? ??? ?{ ?? ??? ?case 1: add_tour();;break;//進(jìn)入添加旅游資訊信息功能 ?? ??? ?case 2: search_tour();;break;//進(jìn)入查詢旅游資訊信息功能 ?? ??? ?case 3: display();break;//進(jìn)入瀏覽旅游資訊信息功能 ?? ??? ?case 4: change_tour();;break;//進(jìn)入修改旅游資訊信息功能 ?? ??? ?case 5: delect_tour();break;//進(jìn)入刪除旅游資訊信息功能 ?? ??? ?case 6: agree_tour();break;//進(jìn)入點(diǎn)贊功能 ?? ??? ?case 7: write_cars();//把數(shù)據(jù)信息保存到文件里 ?? ??? ??? ?printf("謝謝使用!\n"); ?? ??? ??? ?exit(0); ?? ??? ?} ?? ?} ?? ?return 0; } void read_tour(){ ?? ?FILE *fp; ?? ?if (0 != fopen_s(&fp, "data.txt", "a+b")) ?? ?{ ?? ??? ?perror("打開(kāi)文件失敗,原因是"); ?? ??? ?getch(); ?? ??? ?exit(1); ?? ?} ?? ?tour T; ?? ?head = (tour)malloc(sizeof(TOUR)); ?? ?if (NULL == head) ?? ?{ ?? ??? ?printf("內(nèi)存分配失??!\n"); ?? ??? ?exit(EXIT_FAILURE); ?? ?} ?? ?head->next = NULL; ?? ?tail = head; ?? ?while (1) ?? ?{ ?? ??? ?T= (tour)malloc(sizeof(TOUR)); ?? ??? ?if (fread(T, sizeof(TOUR), 1, fp) == 0) ?? ??? ?{ ?? ??? ??? ?free(T); ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?T->next = NULL; ?? ??? ?tail->next = T; ?? ??? ?tail = T; ?? ?} ?? ?fclose(fp);//關(guān)閉文件 } void write_cars() { ?? ?FILE *fp; ?? ?if (0 != fopen_s(&fp, "data.txt", "w+")) ?? ?{ ?? ??? ?perror("打開(kāi)文件失敗,原因是"); ?? ??? ?_getch(); ?? ??? ?return; ?? ?} ?? ?tour T = head->next; ?? ?while (T != NULL) ?? ?{ ?? ??? ?fwrite(T, sizeof(TOUR), 1, fp); ?? ??? ?T = T->next; ?? ?} ?? ?fclose(fp);//關(guān)閉文件 } void add_tour() { ?? ?tour T,temp; ?? ?T=(tour)malloc(sizeof(TOUR)); ?? ?if(T==NULL) ?? ?{ ?? ??? ?printf("空間分配失?。?); ?? ? ? ?exit(1); ?? ?} ?? ?printf("請(qǐng)輸入編號(hào):"); ?? ?scanf("%d",&T->id); ?? ?printf("請(qǐng)輸入日程安排:"); ?? ?scanf("%s",T->plan); ?? ?printf("請(qǐng)輸入費(fèi)用:"); ?? ?scanf("%f",&T->cost); ?? ?printf("請(qǐng)輸入點(diǎn)贊數(shù):"); ?? ?scanf("%d",&T->agree); ?? ?if(head->next==NULL) ?? ?{ ?? ??? ?head->next=T; ?? ??? ?T->next=NULL; ?? ?}else ?? ?{ ?? ??? ?temp=head->next;//頭插法 ?? ??? ?head->next=T; ?? ??? ?T->next=temp; ?? ?} ?? ?printf("%-15s|%-15s|%-15s|%-15s\n", ?? ??? ?"編號(hào)", "日程安排", "費(fèi)用", "點(diǎn)贊數(shù)"); ?? ?printf("%-16d%-16s%-16.1f%-7d%\n",T->id,T->plan,T->cost,T->agree); } void search_tour(){ ?? ?int i; ?? ?while(1){ ?? ??? ?printf("1.按編號(hào)大小升序排序顯示所有的記錄\n2.按點(diǎn)贊數(shù)降序排序顯示所有的記錄\n3.輸入編號(hào)查詢記錄\n"); ?? ??? ?printf("請(qǐng)選擇查詢的方式:\n"); ?? ??? ?scanf("%d",&i); ?? ??? ?if(i>=1&&i<4)break; ?? ??? ?else ?? ??? ??? ?printf("輸入的數(shù)字錯(cuò)誤,請(qǐng)重新輸入:\n"); ?? ?} ?? ?switch(i){ ?? ?case 1:display_tourid();break; ?? ?case 2:display_touragree();break; ?? ?case 3:search_tourid(); ?? ?} } void display_tourid(){ ?? ?tour T; ?? ?T=head->next; ?? ?tail=NULL;? ?? ?if(T==NULL||T->next==NULL){ ?? ??? ?printf("目前該系統(tǒng)尚未保存有旅游資訊記錄,返回主菜單!\n"); ?? ??? ?return;//退出 ?? ?} ?? ?while(T!=tail){ ?? ??? ?while(T->next!=tail){ ?? ??? ??? ?if(T->id>T->next->id){ ?? ??? ??? ??? ?int temp=T->id; ?? ??? ??? ??? ?T->id=T->next->id; ?? ??? ??? ??? ?T->next->id=temp; ?? ??? ??? ??? ?char tempplan[30]; ?? ??? ??? ??? ?strcpy(tempplan, T->plan); ? ?? ??? ??? ??? ?strcpy(T->plan,T->next->plan); ?? ??? ??? ??? ?strcpy(T->next->plan,tempplan);? ?? ??? ??? ??? ?float tempcost=T->cost; ?? ??? ??? ??? ?T->cost=T->next->cost; ?? ??? ??? ??? ?T->next->cost=tempcost; ?? ??? ??? ??? ?int tempagree=T->agree; ?? ??? ??? ??? ?T->agree=T->next->agree; ?? ??? ??? ??? ?T->next->agree=tempagree; ?? ??? ??? ?} ?? ??? ??? ?T=T->next; ?? ??? ?} ?? ??? ?tail=T; ?? ??? ?T=head; ?? ?} ?? ?display();//將信息輸出到顯示器中 } void display_touragree(){ ?? ?tour T; ?? ?T=head->next; ?? ?tail=NULL;? ?? ?if(T==NULL||T->next==NULL){ ?? ??? ?printf("目前該系統(tǒng)尚未保存有旅游資訊記錄,返回主菜單!\n"); ?? ??? ?return; ?? ?} ?? ?while(T!=tail){ ?? ??? ?while(T->next!=tail){ ?? ??? ??? ?if(T->agree>T->next->agree){ ?? ??? ??? ??? ?int temp=T->id; ?? ??? ??? ??? ?T->id=T->next->id; ?? ??? ??? ??? ?T->next->id=temp; ?? ??? ??? ??? ?char tempplan[30]; ?? ??? ??? ??? ?strcpy(tempplan, T->plan); ? ?? ??? ??? ??? ?strcpy(T->plan,T->next->plan); ?? ??? ??? ??? ?strcpy(T->next->plan,tempplan);? ?? ??? ??? ??? ?float tempcost=T->cost; ?? ??? ??? ??? ?T->cost=T->next->cost; ?? ??? ??? ??? ?T->next->cost=tempcost; ?? ??? ??? ??? ?int tempagree=T->agree; ?? ??? ??? ??? ?T->agree=T->next->agree; ?? ??? ??? ??? ?T->next->agree=tempagree; ?? ??? ??? ?} ?? ??? ??? ?T=T->next; ?? ??? ?} ?? ??? ?tail=T; ?? ??? ?T=head; ?? ?} ?? ?display();//將信息輸出到顯示器中 } void search_tourid(){ ?? ?tour T; ?? ?T=head->next; ?? ?printf("請(qǐng)輸入要查找的編號(hào):"); ?? ?int searchid; ?? ?scanf("%d",&searchid); ?? ?int j=0; ?? ?printf("%-15s|%-15s|%-15s|%-15s\n", ?? ??? ?"編號(hào)", "日程安排", "費(fèi)用", "點(diǎn)贊數(shù)"); ?? ?while(T!=NULL) ?? ?{ ?? ??? ?if(T->id ==searchid) ?? ??? ?{ ?? ??? ??? ?printf("%-16d%-16s%-16.1f%-7d%\n",T->id,T->plan,T->cost,T->agree); ?? ??? ??? ?T=T->next; ?? ??? ??? ?j++; ?? ??? ?} ?? ??? ?else ?? ??? ?T=T->next; ?? ?} ?? ??? ?if(j==0) ?? ??? ?{ ?? ??? ??? ?printf("該系統(tǒng)無(wú)該編號(hào)的旅游信息\n"); ?? ??? ?} } void display(){ ?? ?tour T=head->next; ?? ?if(NULL == head->next) ? ? { ? ? ? printf("無(wú)旅游信息\n"); ? ? return ; ? ? } ?? ?printf("%-15s|%-15s|%-15s|%-15s\n", ?? ??? ?"編號(hào)", "日程安排", "費(fèi)用", "點(diǎn)贊數(shù)"); ?? ?for(;T!=NULL;T=T->next) ?? ?{ ?? ??? ?printf("%-16d%-16s%-16.1f%-7d%\n",T->id,T->plan,T->cost,T->agree); ?? ??? ? ?? ?} } void change_tour(){ ?? ?int j=0; ?? ?tour T; ?? ?T=head->next; ?? ?int changeid; ?? ?printf("請(qǐng)輸入待修改的編號(hào):"); ?? ?scanf("%d",&changeid); ?? ?for(;T!=NULL;T=T->next){ ?? ??? ?if(T->id==changeid){ ?? ??? ??? ?j++; ?? ??? ??? ?char arr[30]; ?? ??? ??? ?printf("請(qǐng)輸入要修改的項(xiàng)目:編號(hào)、日程安排、費(fèi)用\n"); ?? ??? ??? ?scanf("%s",arr); ?? ??? ??? ?if (strcmp(arr,"編號(hào)")==0){ ?? ??? ??? ??? ?printf("請(qǐng)輸入修改后的值:"); ?? ??? ??? ??? ?int changeid; ?? ??? ??? ??? ?scanf("%d",&changeid); ?? ??? ??? ??? ?T->id=changeid; ? ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(arr,"日程安排")==0){ ?? ??? ??? ??? ?printf("請(qǐng)輸入修改后的值:"); ?? ??? ??? ??? ?char str[20]; ?? ??? ??? ??? ?scanf("%s",str); ?? ??? ??? ??? ?strcpy(T->plan, str);? ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(arr,"費(fèi)用")==0){ ?? ??? ??? ??? ?printf("請(qǐng)輸入修改后的值:"); ?? ??? ??? ??? ?float changecost; ?? ??? ??? ??? ?scanf("%f",&changecost); ?? ??? ??? ??? ?T->cost=changecost; //賦值 ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ?} ?? ?} ? ? ? ? ? if(j==0){ ?? ??? ??? ?printf("系統(tǒng)無(wú)該編號(hào)的信息\n"); ?? ??? ??? ?exit(1); ?? ??? ? ?} } void delect_tour(){ ?? ?int j=0; ?? ?tour T,temp; ?? ?T=head; ?? ?int delectid; ?? ?printf("請(qǐng)輸入待刪除的編號(hào):"); ?? ?scanf("%d",&delectid); ?? ?getchar(); ?? ?while(T->next!=NULL) ?? ?{ ?? ??? ?if(T->next->id==delectid) ?? ??? ?{ ?? ??? ??? ?j++; ?? ??? ??? ?printf("是否要?jiǎng)h除(Y/N),請(qǐng)選擇:\n"); ?? ??? ??? ?char ch; ?? ??? ??? ?scanf("%c",&ch); ?? ??? ??? ?if(ch=='y'||ch=='Y'){ ?? ??? ??? ? ?temp=T->next; ? ? ? ? ? ? ? T->next = T->next->next; ?? ??? ??? ? ?free(temp); ?? ??? ??? ? ?printf("數(shù)據(jù)刪除成功!\n"); ?? ??? ??? ? ?break; ?? ??? ??? ?}else{ ?? ??? ??? ??? ?printf("不進(jìn)行刪除操作!\n"); ?? ??? ??? ??? ?exit(0); ?? ??? ??? ?} ?? ??? ?} ?? ??? ?else ?? ??? ?T=T->next; ?? ?} ?? ?if(j==0){ ?? ??? ??? ?printf("系統(tǒng)無(wú)該編號(hào)的信息\n"); ?? ??? ??? ?exit(0); ?? ??? ?} } void agree_tour(){ ?? ?int j=0; ?? ?tour T; ?? ?T=head; ?? ?int agreeid; ?? ?printf("請(qǐng)輸入待點(diǎn)贊的編號(hào):"); ?? ?scanf("%d",&agreeid); ?? ?getchar(); ?? ?for(;T!=NULL;T=T->next){ ?? ??? ?if(T->next->id==agreeid){ ?? ??? ??? ?j++; ? ? ? ? ? ? printf("是否要?jiǎng)h除(Y/N),請(qǐng)選擇:\n"); ?? ??? ??? ?char ch; ?? ??? ??? ?scanf("%c",&ch); ?? ??? ??? ?if(ch=='y'||ch=='Y'){ ?? ??? ??? ? ?T->next->agree=T->next->agree+1;//點(diǎn)贊數(shù)+1 ?? ??? ??? ? ?break; ?? ??? ??? ?}else{ ?? ??? ??? ??? ?printf("不進(jìn)行點(diǎn)贊操作!\n"); ?? ??? ??? ??? ?exit(0); ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ? ? ? if(j==0){ ?? ??? ??? ?printf("系統(tǒng)無(wú)該編號(hào)的信息\n"); ?? ??? ??? ?exit(0); ?? ? ? ? } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++控制臺(tái)實(shí)現(xiàn)俄羅斯方塊游戲
這篇文章主要為大家詳細(xì)介紹了C++控制臺(tái)實(shí)現(xiàn)俄羅斯方塊游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Qt實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘
這篇文章主要為大家詳細(xì)介紹了Qt實(shí)現(xiàn)簡(jiǎn)易時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-07-07詳談全排列next_permutation() 函數(shù)的用法(推薦)
下面小編就為大家?guī)?lái)一篇詳談全排列next_permutation() 函數(shù)的用法(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03json格式解析和libjson的用法介紹(關(guān)于cjson的使用方法)
下面小編就為大家?guī)?lái)一篇json格式解析和libjson的用法介紹(關(guān)于cjson的使用方法)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-12-12C++數(shù)據(jù)結(jié)構(gòu)與算法的基礎(chǔ)知識(shí)和經(jīng)典算法匯總
終是到了標(biāo)志著大二結(jié)束的期末考試了,對(duì)于《算法設(shè)計(jì)與分析》這門課,我需要總結(jié)一下學(xué)過(guò)的所有算法的思想以及老師補(bǔ)充的關(guān)于兩個(gè)復(fù)雜度和遞歸的概念思想,以及更深層次的理解,比如用畫(huà)圖的方式表達(dá)出來(lái),我覺(jué)得可以用博客記錄總結(jié)一下,分享給大家,希望能有所幫助2022-05-05