数据结构--酒店管理系统(C语言)
生活随笔
收集整理的這篇文章主要介紹了
数据结构--酒店管理系统(C语言)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
個人的第一篇文章, 現(xiàn)正處于新手學(xué)習(xí)階段,不當(dāng)之處希望大家多多指正。
編譯器為DEV C++ 5.4.0
廢話不多說直接上代碼
#include<stdio.h> #include <windows.h>//界面刷新睡眠 #include<stdlib.h> #include <string.h>//用于用戶驗證 #define MAX 100 //最大房間容量 #define Stytm 20 #define mAX 1024//文件讀取字符長 int fileHang(FILE *fp); int length=0;//房間順序 typedef int DataType; typedef struct Hos {int num[MAX];//房間號char type[MAX];//房間類型 float money[MAX];//價格 int flag[MAX]; //是否入住 int sumroom; //已入住房間數(shù) }SeqList; typedef struct login //注冊集合 {char username[20];char password[20];}Loginsys; typedef struct yanzheng //用戶輸入驗證; {char UUname[20];char UUpass[20]; }UUList; int Menu (int s);//聲明 void AddList(SeqList *L); void NewList(SeqList *L); void PrintfList(SeqList *L); void Strcte(Loginsys *S,UUList *P); void PrintfList(SeqList *L); void IntList(SeqList *L)//初始化住房房間數(shù); {L->sumroom=0;return; } void AddList(SeqList *L)//添加 {char x;FILE *file=fopen("1.txt","a");//文件打開如果沒有則創(chuàng)建 ,有的話繼續(xù)寫人 if(file==NULL){printf("error!");return;}do {char ant[10];int goub[10]; O: printf("輸入房間號 (本酒店房間號為三位):\n");scanf(" %d",&L->num[length]);if(L->num[length]<0||L->num[length]>999) {printf("請重新輸入房間號!!");goto O;}fprintf(file,"\n酒店存在的房間號:%d\n",L->num[length]);//使用fprintf寫入文件 printf("輸入房間類型:\n");scanf("%s",&L[length].type);//當(dāng)對數(shù)據(jù)進行打包時 ([length])該位置為打包的第幾組數(shù)據(jù); fprintf(file,"\n房間類型:%s\n",L[length].type);//字符串寫入文件printf("房間價格:\n");scanf("%f",&L->money[length]);fprintf(file,"\n%s的房間價格:%f\n",L[length].type,L->money[length]); S: printf("確認(rèn)是否入住(1(入住)/0(無)):\n");scanf("%d",&L->flag[length]);if(L->flag[length]==0){printf("不入住,即將返回頁面。");Sleep(2000);}if(L->flag[length]!=1){printf("請輸入合法字符!!!");goto S;}printf("是否繼續(xù)入住:(Y/N)\n");scanf(" %c",&x);if(x=='Y'||x=='y'){length++;system("cls");}}while(x=='Y'||x=='y');fclose(file);//一定要關(guān)閉文件PrintfList(L);return;} void PrintfList(SeqList *L)//數(shù)據(jù)展開 {int i,x;for(i=0;i<=length;i++){printf("\n\n第%d個房間信息:\n",i+1);printf("現(xiàn)有居住的房號:%d\n",L->num[i]);printf("房間居住類型:%s\n",L[i].type);printf("%s型房間價格為%f元\n",L[i].type,L->money[i]);}return; } void FindList(SeqList *L)//查找房間號; {int x,i;printf("\n輸入要查的房間號:\n");scanf("%d",&x);for(i=0;i<=length;i++){if(x==L->num[i]){printf("房間已有住客! 信息如下:\n");printf("\n現(xiàn)有居住的房號:%d\n",L->num[i]);printf("房間類型:%s\n",L[i].type);printf("%s型房間價格為%f\n",L[i].type,L->money[i]);break;}if(i==length)printf("該房間為空房間!!");}return; } void Findroomname(SeqList *L)//按照房間類型查找 {int s;char a[10];printf("請輸入房間類型:\n");scanf("%s",a);for(s=0;s<=length;s++){if(strcmp(a,L[s].type)==0){printf("房間已有住客! 信息如下:\n");printf("\n現(xiàn)有居住的房號:%d\n",L->num[s]);printf("房間類型:%s\n",L[s].type);printf("%s型房間價格為%f\n",L[s].type,L->money[s]);}}if(s>length){printf("不存在該房間類型!!!!\n");}return; } void NewList(SeqList *L)//添加房間信息 {printf("\n請?zhí)砑臃块g的數(shù)據(jù)\n");char x;length++;FILE *file=fopen("1.txt","a");//文件打開如果沒有則創(chuàng)建 ,有的話繼續(xù)寫人 if(file==NULL){printf("error!");return;}do {char ant[10];int goub[10];printf("輸入房間號 (本酒店房間號為三位):\n");scanf(" %d",&L->num[length]);fprintf(file,"\n酒店存在的房間號:%d\n",L->num[length]);//使用fprintf寫入文件 printf("輸入房間類型:\n");scanf("%s",&L[length].type);//當(dāng)對數(shù)據(jù)進行打包時 ([length])該位置為打包的第幾組數(shù)據(jù); fprintf(file,"\n房間類型:%s\n",L[length].type);//字符串寫入文件printf("房間價格:\n");scanf("%f",&L->money[length]);fprintf(file,"\n%s的房間價格:%f\n",L[length].type,L->money[length]);printf("確認(rèn)是否入住(1(入住)/0(無)):\n");scanf("%d",&L->flag[length]);printf("是否繼續(xù)入住:(Y/N)\n");scanf(" %c",&x);if(x=='Y'||x=='y'){length++;system("cls");}}while(x=='Y'||x=='y');fclose(file);//一定要關(guān)閉文件return; } void FixList(SeqList *L)//修改房間信息 {W: int room,i,x;PrintfList(L);printf("\n請輸入要修改的房間號:\n");scanf("%d",&room);for(i=0;i<=length;i++){if(room==L->num[i]){printf("房間已有住客! 信息如下:\n");printf("現(xiàn)有居住的房號:%d\n",L->num[i]);printf("房間類型:%s\n",L[i].type);printf("%s型房間價格為%f\n",L[i].type,L->money[i]);break;}if(i==length){printf("該房間為空房間!!");goto W;}}printf("\n請輸入您要修改的信息:\n");printf("修改房號請按 (1)\n");printf("修改房間類型請按(2) \n");printf("修改房間價格請按(3)\n"); scanf("%d",&x);switch(x){case 1: printf("\n輸入修改后的結(jié)果:\n");scanf("%d",&L->num[i]);break;case 2: printf("\n輸入修改后的結(jié)果:\n");scanf("%s",L[i].type);break;case 3: printf("\n輸入修改后的結(jié)果:\n");scanf("%f",&L->money[i]);break;default :printf("\n請輸入合法的要修改的字符\n"); }return; } void DeleteList(SeqList *L)//刪除 {int d,i,s;char x;printf("\n請輸入要刪除的房間號:");PrintfList(L);scanf("%d",&d);for(i=0;i<=length;i++){if(d==L->num[i]){printf("房間已有住客! 信息如下:\n");printf("現(xiàn)有居住的房號:%d\n",L->num[i]);printf("房間類型:%s\n",L[i].type);printf("%s型房間價格為%f\n",L[i].type,L->money[i]);break;}if(i==length){printf("該房間為空房間,無法刪除!!\n");}}printf("\n確認(rèn)刪除(Y/N): ");scanf(" %c",&x);if(x=='Y'||x=='y'){printf("刪除后:\n");for(s=0;s<length;s++){L->num[i+s]=L->num[i+s+1];//數(shù)據(jù)覆蓋 L->money[i+s]=L->money[i+s+1];length--;}}PrintfList(L);Menu(s);return; } char Endingclass()//退出界面 {char a;printf("確定退出系統(tǒng)(Y/y)\n");scanf(" %c",&a);if(a=='y'||a=='Y') printf("\t\t\t\t***********************************************\n");printf("\t\t\t\t------------歡迎下次使用本酒店管理系統(tǒng)---------\n");printf("\t\t\t\t***********************************************\n");return a; }int Menu(int s)//選單 {SeqList L;Loginsys S;UUList O;//Strcte(&S,&O);int m;printf("正在加載");for(int l=0;l<=4;l++){printf(".");Sleep(300);}//Sleep(4000);system("cls");//刷新; printf("...正在跳轉(zhuǎn)數(shù)據(jù)....\n");printf("...正在處理后臺數(shù)據(jù)...\n");printf("\t\t------- 歡迎使用GoodHotls后臺系統(tǒng)!!! ---------\t\t\t\t\n");printf("跳轉(zhuǎn)成功!\n\n\n");printf("\t\t*------- 1--創(chuàng)建新的數(shù)據(jù)記錄 ---------*\t\t\t\t\n");printf("\t\t*------- 2--增加新的數(shù)據(jù)記錄,并返回選單 ---------*\t\t\t\t\n");printf("\t\t*------- 3--按房間號查找相關(guān)信息 ---------*\t\t\t\t\n");printf("\t\t*------- 4--修改記錄信息 ---------*\t\t\t\t\n");printf("\t\t*------- 5--刪除記錄信息 ---------*\t\t\t\t\n");printf("\t\t*------- 6--列出所有數(shù)據(jù) ---------*\t\t\t\t\n");printf("\t\t*------- 7--退出 ---------*\t\t\t\t\n");printf("\t\t*------- 8--注冊 ---------*\t\t\t\t\n");printf("\t\t*------- 9--按照房間類型查找 ---------*\t\t\t\t\n");printf("-----------------------------------------------------------------------------------------------------------------\n");printf("要進行的操作:");scanf("%d",&m);system("cls");return m; } void Strcte(Loginsys *S,UUList *P)//注冊 ,登錄; { char q,l,m;int x=0,k=0,t=0;printf("\t\t\t\t**********************************************\n"); printf("\t\t\t\t*---------歡迎使用GoodHotls酒店管理系統(tǒng)------*\n");printf("\t\t\t\t**********************************************\n"); P: printf("\t\t\t\t*--------還未注冊? 請按 G 進行管理員注冊!---*\n");printf("\t\t\t\t**********************************************\n");printf(" "); scanf(" %c",&q);if(q=='G'||q=='g'){ printf(" "); B: printf("請輸入要注冊賬號(不長于20位):\n");printf(" "); scanf("%s",&S[x].username);printf(" "); printf("請輸入要注冊密碼(不長于20位):\n");printf(" "); scanf("%s",&S[x].password); } else{printf(" "); printf("請輸入合法注冊字符!\n");goto P;}printf(" "); printf("注冊成功,是否登錄賬號(Y/N)\n");printf(" "); scanf(" %c",&m);if(m=='y'||m=='Y'){system("cls");printf("正在跳轉(zhuǎn)");for(int n=0;n<3;n++){Sleep(100);printf(".");}system("cls");}elseif(m=='n'||m=='N'){printf("請重新注冊\n");goto B;}else{printf("請輸入合法字符!!\n");}if(S[0].username!=NULL&&S[0].password!=NULL){C: printf("已有賬號?請按(Y/y)進行登錄:\n");scanf(" %c",&l);if(l=='Y'||l=='y'){L: printf("請輸入賬號:\n");scanf("%s",&P[0].UUname);printf("請輸入密碼:\n");scanf("%s",&P[0].UUpass);}else{printf("請輸入合法字符!!!\n");goto C;}}K: if(strcmp(S[k].username,P[0].UUname)==0){if(strcmp(S[k].password,P[0].UUpass)==0)goto G;else{printf("密碼錯誤!\n");k=0;goto L;}} if(strcmp(S[k].username,P[0].UUname)!=0){k++;if(k<=x) goto K;if(k>x){ k=0; printf("無此用戶!\n"); goto L;} }G: return; }int main() { float sum=0;Loginsys S;//需要在主函數(shù)內(nèi)聲明 SeqList L;//需要在主函數(shù)內(nèi)聲明 UUList O;SeqList longth[50];//打包字符50個,用于儲存字符 Loginsys Names[10];UUList check[10];Strcte(&S,&O);int com;//Strcte(&S,&O);IntList(&L);A: com=Menu(0);switch(com){case 1: AddList(&L); goto A;break;case 2: NewList(&L);goto A;break;case 3: FindList(&L);goto A;break;case 4: FixList(&L);goto A;break;case 5: DeleteList(&L);goto A; break;case 6: PrintfList(&L); goto A;break;case 7: Endingclass(); if(Endingclass()=='Y'||Endingclass()=='y') break; else goto A;case 8: Strcte(&S,&O);goto A;break;case 9: Findroomname(&L); goto A; break;default: printf("請輸入合法數(shù)字!!\n"); goto A;break;}for(int s=0;s<=length;s++)//計算酒店目前收入 {sum=sum+L.money[s];}printf("該酒店現(xiàn)客房總收入為:%f\n\n\n\n\n",sum);char line[mAX];//文件讀取 int lines = 0;FILE *fp1 = fopen("1.txt","r"); // 創(chuàng)建文件指針及打開文本文件if (fp1 == NULL){printf("文件打開時發(fā)生錯誤");exit(1);}while(fgets(line,mAX,fp1) != NULL){// 或者使用whie(!feof(fp1)){fgets(line,MAX,fp1)}(不推薦,易報錯) lines++; // 統(tǒng)計行數(shù)printf(line);// 打印文本}printf("\n%d 個房間記錄",lines/2/3);//記錄共有多少房間記錄 fclose(fp1); // 關(guān)閉文件指針()return 0; }?其中含有文件寫入與讀取,添加,查找,修改,刪除,后臺登錄系統(tǒng)。
該程序純屬自制,如有雷同,純屬巧合。
總結(jié)
以上是生活随笔為你收集整理的数据结构--酒店管理系统(C语言)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java-n个人报数
- 下一篇: 第五十期:工作强度超996,失业半年即出