您好,登錄后才能下訂單哦!
這篇文章主要講解了“C語(yǔ)言怎么實(shí)現(xiàn)影院管理系統(tǒng)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“C語(yǔ)言怎么實(shí)現(xiàn)影院管理系統(tǒng)”吧!
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<windows.h>#include"state.h"#define change 3int iCount;int n;//*****************注冊(cè)*****************//void router_registe(pAccout ahead){ system("cls"); char username[20]; char password[13]; char pass[13]; char q; int i; FILE *fp; loop2: printf("\n\n\n\n"); printf("\t\t\t\t賬號(hào):"); scanf("%s",username); getchar(); printf("\t\t\t\t密碼:"); i=0; while (1) { q = getch(); if (q != 13) { printf("*"); password[i++] = q; } else { password[i] = ''; printf("\n"); break; } } printf("\t\t\t\t請(qǐng)確認(rèn)密碼:"); i=0; while (1) { q = getch(); if (q != 13) { printf("*"); pass[i++] = q; } else { pass[i] = ''; printf("\n"); break; } } if(strcmp(pass,password)==0) { fp=fopen("e:\\課設(shè)\\Accout1.txt", "ab+"); fprintf(fp," %s %s",username,password); //把內(nèi)存中的文件輸入到硬盤(pán)中 fclose(fp); system("cls"); printf("\n\n\n\n注冊(cè)成功\n"); } else goto loop2;}//*****************登錄*****************//pAccout router_acc(pAccout ahead){ pAccout p1,p2; FILE *fp; int m=0; if((fp=fopen("e:\\課設(shè)\\Accout.txt", "rw"))==NULL) { printf("讀取失敗!"); return ahead; } ahead==NULL; p1=(pAccout)malloc(sizeof(Accout)); while(fscanf(fp,"%s %s",p1->name,p1->pass)==2) { //printf("%s\n",p1->name); //讀進(jìn)去了 m=m+1; if(m==1) { ahead->next=p1; p2=p1; p2->next = NULL; } else { p2->next=p1; p2=p1; p2->next=NULL; } p1=(pAccout)malloc(sizeof(Accout)); } fclose(fp); return ahead;}pAccout router_acc1(pAccout ahead){ pAccout p1,p2; FILE *fp; int m=0; if((fp=fopen("e:\\課設(shè)\\Accout1.txt", "rw"))==NULL) { printf("讀取失敗!"); return ahead; } ahead==NULL; p1=(pAccout)malloc(sizeof(Accout)); while(fscanf(fp,"%s %s",p1->name,p1->pass)==2) { //printf("%s\n",p1->name); //由于文件沒(méi)有讀入換行,讀出的時(shí)候?qū)⑾纫粋€(gè)人的密碼和 //printf("%s",p1->pass); //后一個(gè)人的名稱 m=m+1; if(m==1) { ahead->next=p1; p2=p1; p2->next = NULL; } else { p2->next=p1; p2=p1; p2->next=NULL; } p1=(pAccout)malloc(sizeof(Accout)); } fclose(fp); return ahead;}void login_printf(){ system("cls"); printf("\n\n\n\n"); printf("\t\t\t★☆★☆★☆★☆★☆★☆★☆★☆\n"); printf("\t\t\t☆ ★\n"); printf("\t\t\t☆ 1.登錄 ★\n"); printf("\t\t\t☆ 2.注冊(cè) ★\n"); printf("\t\t\t★ 0.退出 ☆\n"); printf("\t\t\t☆ ★\n"); printf("\t\t\t★☆★☆★☆★☆★☆★☆★☆★☆\n");}void login_printf1(){ system("cls"); printf("\n\n\n\n"); printf("\t\t\t********************************\n"); printf("\t\t\t|| ||\n"); printf("\t\t\t|| 1.管理員登錄 ||\n"); printf("\t\t\t|| 2.用戶登錄 ||\n"); printf("\t\t\t|| 0.退出 ||\n"); printf("\t\t\t|| ||\n"); printf("\t\t\t********************************\n");}void login_acc() { system("cls"); int bk; int bb; pAccout ahead,p1; ahead=(pAccout)malloc(sizeof(Accout)); ahead->next=NULL; while(1) { char a[200]; char b[200]; loop: login_printf(); printf("請(qǐng)輸入:"); scanf("%s",a); bk=back(a); switch(bk) { case 1:{ login_printf1(); printf("請(qǐng)輸入:"); scanf("%s",b); bb=back(b); switch(bb) { case 1:{ router_acc(ahead); ahead=login_panduan(ahead);//管理員登錄 meun(); break; } case 2:{ router_acc1(ahead); ahead=login_panduan(ahead);//用戶登陸 menu1(); break; } case 0: { print2(); exit(0); break; } default:printf("輸入錯(cuò)誤!"); Sleep(1000); system("cls"); break; } if(bb!=0)//丟失此處則會(huì)無(wú)法跳出循環(huán) break; } case 2:{ router_registe(ahead); goto loop; break; } case 0:{ // printf("BUG?。。?!\n");測(cè)試bug?。。。。? print2(); exit(0); break; } default:printf("輸入錯(cuò)誤!"); Sleep(1000); system("cls"); break; } if(bk!=0) break; }}pAccout login_panduan(pAccout ahead){ char name1[20],pass1[20]; char q; pAccout p1; int i=0,j=0; system("cls"); printf("\n\n\n\n"); loop1: while(1) { j++; p1=ahead->next; printf("\t\t\t\t賬號(hào):"); scanf("%s",name1); getchar(); printf("\t\t\t\t密碼:"); i=0; while (1) { j++; q = getch(); if (q != 13) { printf("*"); pass1[i++] = q; } else { pass1[i] = ''; printf("\n"); break; } } //printf("%s",pass1);密碼正確(加密最初出現(xiàn)問(wèn)題) while(p1!=NULL) { if(strcmp(name1,p1->name)==0) { if(strcmp(pass1,p1->pass)==0) { printf("\n\n\t\t\t\t登錄成功!"); Sleep(2000); return ahead; } else { p1=p1->next; } } else { p1=p1->next; } if(p1==NULL) { printf("\n\n\n\n\t\t\t\t輸入有誤"); system("cls"); printf("\n\n\n\n\t\t\t\t請(qǐng)重新輸入\n"); Sleep(2000); goto loop1; break; } } if(j>=change) { system("cls"); printf("\n\n\n\n"); printf("\t\t\t\t***************\n"); printf("\t\t\t\t你完蛋了!!!!!\n"); printf("\t\t\t\t***************\n"); Sleep(2000); print2(); exit (0); } } return ahead;}//登錄成功 int panduan(char choice){ while(1) { fflush(stdin); choice=getchar(); if(choice == 'y'|| choice =='Y') return 1; else if(choice == 'n'||choice == 'N') return 0; while(getchar() != '\n') continue; printf("輸入錯(cuò)誤!請(qǐng)重新輸入您的選擇:\n"); }}int back(char *a){ if(strlen(a)==1) { if(a[0]>='0'&&a[0]<='9') return ((int)a[0]-48); } else return 10;} void print1(){ int i; system("cls"); printf("\n\n\n\n"); printf("\t\t\t\t|******************************|\n"); printf("\t\t\t\t||****************************||\n"); printf("\t\t\t\t||| |||\n"); printf("\t\t\t\t||| 歡迎來(lái)到影院管理系統(tǒng) |||\n"); printf("\t\t\t\t||| |||\n"); printf("\t\t\t\t||****************************||\n"); printf("\t\t\t\t|******************************|\n"); printf("\n\t\t\t\t系統(tǒng)開(kāi)始啟動(dòng).........\n"); printf("===================================================================================================\r"); for(i=1;i<100;i++) { Sleep(40); printf(">"); }}void print() //主界面 { system("cls"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 歡迎來(lái)到影院管理系統(tǒng)(主菜單) |\n"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 1.插入信息 |\n"); printf("\t\t\t| 2.查看信息 |\n"); printf("\t\t\t| 3.查詢信息 |\n"); printf("\t\t\t| 4.修改信息 |\n"); printf("\t\t\t| 5.排序信息 |\n"); printf("\t\t\t| 6.刪除信息 |\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t| 0.退出程序 |\n"); printf("\t\t\t|===============================|\n");}void print2(){ system("cls"); printf("\n\n\n\n"); printf("\t\t\t|******************************|\n"); printf("\t\t\t||****************************||\n"); printf("\t\t\t||| |||\n"); printf("\t\t\t||| 謝謝使用 |||\n"); printf("\t\t\t||| |||\n"); printf("\t\t\t||****************************||\n"); printf("\t\t\t|******************************|\n"); Sleep(2000);}void print3(){ system("cls"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 歡迎來(lái)到影院購(gòu)票系統(tǒng)(主菜單) |\n"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 1.主頁(yè)信息 |\n"); printf("\t\t\t| 2.查詢信息 |\n"); printf("\t\t\t| 3.排序信息 |\n"); printf("\t\t\t| 4.打印報(bào)表 |\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t| 0.退出程序 |\n"); printf("\t\t\t|===============================|\n");}/*******************查詢模塊********************/ pticket searchmenu(pticket phead) //查詢子系統(tǒng)菜單 { fflush(stdin); system("cls"); int bk; while(1) { char P[200]; system("cls"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 查詢子系統(tǒng)菜單 |\n"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 1.按影院查詢 |\n"); printf("\t\t\t| 2.按電影查找 |\n"); printf("\t\t\t| 3.按價(jià)格區(qū)間查找 |\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t| 0.返回上一層 |\n"); printf("\t\t\t|*******************************|\n\n"); printf("請(qǐng)輸入指令:"); scanf("%s",P); bk=back(P); switch(bk) { case 1: { phead=search2(phead);//按影院查詢 break; } case 2: { phead=search3(phead);//按電影查詢 break; } case 3:{ phead=search4(phead);//按價(jià)格區(qū)間查詢 break; } case 0:break; default:printf("輸入錯(cuò)誤!請(qǐng)重新輸入\n"); system("pause"); break; } if(bk==0) break; } return phead;}pticket search2(pticket phead) //影院查詢 { system("cls"); char cinema1[30],choice; pticket p; int flag=0; char q; p=(pticket)malloc(sizeof(ticket)); while(1) { system("cls"); printf("\n\n\n\t\t\t請(qǐng)輸入影院名稱:"); scanf("%s",cinema1); if(strlen(cinema1)>=30) { system("cls"); printf("**************\n"); printf("請(qǐng)輸入正確的名字!\n"); printf("**************\n"); Sleep(1000); } else break; } while(1) { system("cls"); if(phead->next==NULL) { printf("\n\n\n\t\t\t沒(méi)有信息!\n"); system("pause"); break; } p=phead->next; print_stu2(); do { if(strcmp(p->cinema,cinema1)==0) { printf(" %-4s ",p->number); printf("%-12s ",p->name); printf("%-16s",p->cinema); printf(" %4d ",p->time); printf("%.2lf ",p->price); printf(" %.1lf ",p->grade); printf("\n"); flag=1; } p=p->next; }while(p!=NULL); if(flag==0) { printf("不存在的!\n"); } printf("是否繼續(xù)查找?(Y or N)"); q=getchar(); if(panduan(q)==1) { while(1) { system("cls"); printf("\n\n\n\t\t\t請(qǐng)輸入影院名稱:"); scanf("%s",cinema1); if(strlen(cinema1)>=30) { system("cls"); printf("**************\n"); printf("請(qǐng)輸入正確的名字!\n"); printf("**************\n"); Sleep(1000); } else break; } } else if(panduan(choice)==0) break; } return phead; }pticket search3(pticket phead) //按電影名稱查詢 { system("cls"); char name1[30],choice; pticket p; int flag=0; char q; while(1) { system("cls"); printf("\n\n\n\t\t\t請(qǐng)輸入電影名稱:"); scanf("%s",name1); if(strlen(name1)>=30) { system("cls"); printf("**************\n"); printf("請(qǐng)輸入正確的名字!\n"); printf("**************\n"); Sleep(1000); } else break; } while(1) { system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); system("pause"); break; } p=phead->next; print_stu2(); do{ if(strcmp(p->name,name1)==0) { printf(" %-4s ",p->number); printf("%-12s ",p->name); printf("%-16s",p->cinema); printf(" %4d ",p->time); printf("%.2lf ",p->price); printf(" %.1lf ",p->grade); printf("\n"); flag=1; } p=p->next; }while(p!=NULL); if(flag==0) { printf("不存在的!\n"); } printf("是否繼續(xù)查找?(Y or N)\n"); q=getchar(); if(panduan(q)==1) { while(1) { system("cls"); printf("請(qǐng)輸入電影名稱:"); scanf("%s",name1); if(strlen(name1)>=30) { system("cls"); printf("**************\n"); printf("請(qǐng)輸入正確的名字!\n"); printf("**************\n"); Sleep(1000); } else break; } } else if(panduan(choice)==0) break; } return phead; } pticket search4(pticket phead) //按價(jià)格區(qū)間名稱查詢 { system("cls"); int count=0; char choice; float x,y; pticket p; int flag=0; char q; loop2: system("cls"); printf("\n\n\n\t\t\t請(qǐng)輸入價(jià)格下限:"); scanf("%f",&x); printf("\n\t\t\t請(qǐng)輸入價(jià)格上限:"); scanf("%f",&y); while(1) { system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); system("pause"); break; } p=phead->next; print_stu2(); do{ if(p->price>x&&p->price<y) { printf(" %-4s ",p->number); printf("%-12s ",p->name); printf("%-16s",p->cinema); printf(" %4d ",p->time); printf("%.2lf ",p->price); printf(" %.1lf ",p->grade); printf("\n"); count++; flag=1; } p=p->next; }while(p!=NULL); printf("\t\t\t此價(jià)格區(qū)間內(nèi)的電影共有%d場(chǎng)\n",count); if(flag==0) { printf("不存在的!\n"); } system("pause"); printf("是否繼續(xù)查找?(Y or N)\n"); q=getchar(); if(panduan(q)==1) { count=0; goto loop2; } else if(panduan(choice)==0) break; } return phead; } /******************排序模塊*******************/ pticket sortmenu(pticket phead) //排序子系統(tǒng)菜單{ fflush(stdin); system("cls"); int bk; while(1) { system("cls"); char P[200]; printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 排序子系統(tǒng)菜單 |\n"); printf("\t\t\t|*******************************|\n"); printf("\t\t\t| 1.按價(jià)格排序 |\n"); printf("\t\t\t| 2.按時(shí)長(zhǎng)排序 |\n"); printf("\t\t\t| 3.按評(píng)分排序 |\n"); printf("\t\t\t|-------------------------------|\n"); printf("\t\t\t| 0.返回上一層 |\n"); printf("\t\t\t|*******************************|\n\n"); printf("請(qǐng)輸入指令:"); scanf("%s",P); bk=back(P); printf("%d",bk); switch(bk) { case 1:phead=sort1(phead);//按價(jià)格排序 break; case 2:phead=sort2(phead);//按時(shí)長(zhǎng)排序 break; case 3:phead=sort3(phead);// 按評(píng)分排序 break; case 0:break; default:printf("輸入錯(cuò)誤,重新輸入!"); Sleep(1000); system("cls"); break; } if(bk==0) break; } Save_Stu(phead); return phead;}pticket sort(pticket phead) { pticket pTemp,pj,pj_f,pj_b; int i,j,flag; for(i=0;i<iCount;i++) for(j=0,flag=0,pj=phead;j<iCount-1-i;j++) { if(flag==0) { pj_f=pj; pj=pj->next; pj_b=pj->next; } if(flag==1) { pj_f=pj_f->next; pj_b=pj->next; } flag=0; if(pj->price>pj_b->price) { pTemp=pj->next; pj->next=pj_b->next; pj_b->next=pTemp; pTemp=pj_f->next; pj_f->next=pj_b->next; pj_b->next=pTemp; flag=1; } } return phead;}pticket sort22(pticket phead) { pticket pTemp,pj,pj_f,pj_b; int i,j,flag; for(i=0;i<iCount;i++) for(j=0,flag=0,pj=phead;j<iCount-1-i;j++) { if(flag==0) { pj_f=pj; pj=pj->next; pj_b=pj->next; } if(flag==1) { pj_f=pj_f->next; pj_b=pj->next; } flag=0; if(pj->time<pj_b->time) { pTemp=pj->next; pj->next=pj_b->next; pj_b->next=pTemp; pTemp=pj_f->next; pj_f->next=pj_b->next; pj_b->next=pTemp; flag=1; } } return phead;}pticket sort11(pticket phead) { pticket pTemp,pj,pj_f,pj_b; int i,j,flag; for(i=0;i<iCount;i++) for(j=0,flag=0,pj=phead;j<iCount-1-i;j++) { if(flag==0) { pj_f=pj; pj=pj->next; pj_b=pj->next; } if(flag==1) { pj_f=pj_f->next; pj_b=pj->next; } flag=0; if(pj->grade<pj_b->grade) { pTemp=pj->next; pj->next=pj_b->next; pj_b->next=pTemp; pTemp=pj_f->next; pj_f->next=pj_b->next; pj_b->next=pTemp; flag=1; } } return phead;}pticket sort1(pticket phead) //按價(jià)格排序 { system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); Sleep(1000); return phead; } sort(phead); print_stu1(phead); return phead; } pticket sort2(pticket phead) //按時(shí)長(zhǎng)排序 { system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); Sleep(1000); return phead; } sort22(phead); print_stu1(phead); return phead;}pticket sort3(pticket phead) //評(píng)分排序 { system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); Sleep(1000); return phead; } sort11(phead); print_stu1(phead); return phead;} /********************增加模塊**********************/ pticket Insert(pticket phead){ system("cls"); pticket pNew,p=phead; /*if(phead->next==NULL) { printf("無(wú)信息!"); Sleep(1000); return phead; }*/ char choice; while(p->next!=NULL) p=p->next; do { pNew=(pticket)malloc(sizeof(ticket)); printf("請(qǐng)輸入序號(hào):"); scanf("%s",pNew->number); printf("請(qǐng)輸入名稱:"); scanf("%s",pNew->name); printf("請(qǐng)輸入影院:"); scanf("%s",&pNew->cinema); printf("請(qǐng)輸入時(shí)長(zhǎng):"); scanf("%d",&pNew->time); printf("請(qǐng)輸入價(jià)格:"); scanf("%lf",&pNew->price); printf("請(qǐng)輸入評(píng)分:"); scanf("%lf",&pNew->grade); p->next=pNew; p=pNew; p->next=NULL; iCount++; printf("是否繼續(xù)添加信息(Y or N):"); choice=getchar(); }while(panduan(choice)==1); printf("已增加電影信息.\n"); Sleep(1000); Save_Stu(phead); return phead;}/*****************輸出模塊******************/ void print_stu1(pticket phead){ system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); Sleep(1000); return ; } print_stu2(); pticket p; p=phead->next; while(p != NULL) { printf(" %-4s ",p->number); printf("%-12s ",p->name); printf("%-16s",p->cinema); printf(" %4d ",p->time); printf("%.2lf ",p->price); printf(" %.1lf ",p->grade); printf("\n"); p=p->next; } system("pause");}void print_stu2(){ printf("信息如下:\n"); printf("-----------------------------------------------------------------------\n"); printf("****序號(hào)******名稱*************影院**********時(shí)間*****價(jià)格*****評(píng)分****\n"); printf("-----------------------------------------------------------------------\n");} void print_stu3(){ printf("\t\t\t價(jià)格評(píng)分報(bào)表如下\n"); printf("-----------------------------------------------------------------------\n"); printf("*********名稱******************價(jià)格*******************評(píng)分*************\n"); printf("-----------------------------------------------------------------------\n"); }void print_stu4(pticket phead){ system("cls"); if(phead->next==NULL) { printf("沒(méi)有信息!\n"); Sleep(1000); return ; } print_stu3(); pticket p; p=phead->next; while(p != NULL) { printf("\t%-20s ",p->name); printf("%.2f\t\t\t",p->price); printf(" %.1lf ",p->grade); printf("\n"); p=p->next; } system("pause");}/*****************保存模塊***************/ void Save_Stu(pticket phead) //定義保存函數(shù){ system("cls"); FILE *fp; if((fp=fopen("e:\\課設(shè)\\Student", "wt"))==NULL) { printf("不能打開(kāi)文件\n"); exit(1); } pticket p; p=phead->next; while(p!=NULL) { fprintf(fp,"%s %s %s %d %lf %lf ", p->number,p->name,p->cinema,p->time,p->price,p->grade); //把內(nèi)存中的文件輸入到硬盤(pán)中 p=p->next; } fclose(fp); //關(guān)閉文件 //printf("文件已保存\n"); //成功保存,顯示提示 Sleep(1000);}/******************讀取模塊**********************/ pticket router_Stu(pticket phead){ system("cls"); FILE *fp; int m=0; if((fp=fopen("e:\\課設(shè)\\Student", "rw"))==NULL) { printf("讀取失敗!"); return; } pticket p1,p2; p1=(pticket)malloc(sizeof(ticket)); while(fscanf(fp,"%s %s %s %d %lf %lf ", &p1->number, &p1->name, &p1->cinema,&p1->time,&p1->price,&p1->grade)==6) { m=m+1; if(m==1) { phead->next=p1; p2=p1; p2->next = NULL; } else { p2->next=p1; p2=p1; p2->next=NULL; } p1=(pticket)malloc(sizeof(ticket)); } fclose(fp); //printf("讀取成功!"); iCount=m; //Sleep(1000); return phead;} /******************刪除模塊**********************/ pticket delete_Stu(pticket phead){ system("cls"); if(phead->next==NULL) { printf("\n\n\n\n\n\t\t\t\t沒(méi)有可刪除的信息!\n"); system("pause"); return phead; } char name1[30]; pticket pTemp,p; printf("\n\n\n\n\t\t\t\t輸入即將下線的電影名稱:"); scanf("%s",name1); pTemp=phead; while(strcmp(pTemp->name,name1)!=0&&pTemp->next!=NULL) { p=pTemp; pTemp=pTemp->next; } if(strcmp(pTemp->name,name1)==0) { if(p!=phead) { p->next=pTemp->next; } else { phead=pTemp->next; } printf("已刪除"); system("pause"); } else { printf("沒(méi)找到"); Sleep(1000); } getchar(); Save_Stu(phead); return phead;}/********************修改*******************/pticket revise(pticket phead){ system("cls"); char P[200]; int bk; char name[30]; pticket pTemp; if(phead->next==NULL) { printf("沒(méi)有可修改的信息!\n"); system("pause"); return phead; } pTemp=phead->next; printf("\n\n\n\n\t\t\t請(qǐng)輸入你要修改的電影名稱:"); scanf("%s",name); while(strcmp(pTemp->name,name)!=0&&pTemp->next!=NULL) { pTemp=pTemp->next; } if(strcmp(pTemp->name,name)==0) { while(1) { system("cls"); printf("\t\t\t請(qǐng)輸入你要修改的信息:\n"); printf("\t\t\t********************************\t\t\t\n"); printf("\t\t\t 1.修改代碼 2.修改名稱 \t\t\t\n"); printf("\t\t\t 3.修改影院 4.修改時(shí)長(zhǎng) \t\t\t\n"); printf("\t\t\t 5.修改價(jià)格 6.修改評(píng)分 \t\t\t\n"); printf("\t\t\t 0.返回上一層 \t\t\t\n"); printf("\t\t\t********************************\t\t\t\n"); printf("請(qǐng)輸入您的選擇:"); scanf("%s",P); bk=back(P); switch(bk) { case 1:{ system("cls"); printf("請(qǐng)輸入新代碼:"); scanf("%s",pTemp->number); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 2:{ system("cls"); printf("請(qǐng)輸入新的名稱:"); scanf("%s",pTemp->name); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 3:{ system("cls"); printf("請(qǐng)輸入新的影院:"); scanf("%s",&pTemp->cinema); printf("請(qǐng)輸入正確的影院:"); scanf("%s",&pTemp->cinema); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 4:{ system("cls"); printf("請(qǐng)輸入新的時(shí)長(zhǎng):"); getchar(); scanf("%d",&pTemp->time); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 5:{ system("cls"); printf("請(qǐng)輸入新的價(jià)格:"); scanf("%lf",&pTemp->price); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 6:{ system("cls"); printf("請(qǐng)輸入新的評(píng)分:"); scanf("%lf",&pTemp->grade); system("cls"); printf("修改成功!"); Sleep(1000); break; } case 0:break; default:printf("輸入錯(cuò)誤,請(qǐng)重新輸入"); system("pause"); } if(bk==0) break; } Save_Stu(phead); return phead; } else { printf("無(wú)該電影信息!"); Sleep(1000); return phead; }}void menu1(){ pticket phead; phead = (pticket)malloc(sizeof(ticket)); phead->next = NULL; router_Stu(phead); char P,a[200]; char choice; int bk; while(1) { system("cls"); print3(); fflush(stdin); printf("請(qǐng)輸入指令:"); scanf("%s",a); bk=back(a); switch(bk) { case 1: {print_stu1(phead); //查看 system("cls"); break;} case 2:{phead=searchmenu(phead); //查找 system("cls"); break;} case 3:{phead=sortmenu(phead); //排序 system("cls"); break;} case 4:{ print_stu4(phead); system("cls");//打印報(bào)表 break; } case 0:{ print2(); exit(1); } default:{printf("輸入錯(cuò)誤!請(qǐng)重新輸入\n"); system("pause");} } }}void meun(){ pticket phead; phead = (pticket)malloc(sizeof(ticket)); phead->next = NULL; router_Stu(phead); char P,a[200]; char choice; int bk; while(1) { system("cls"); print(); fflush(stdin); printf("請(qǐng)輸入指令:"); scanf("%s",a); bk=back(a); switch(bk) { case 1:{phead=Insert(phead); //插入 system("cls"); break;} case 2:{print_stu1(phead); //查看 system("cls"); break;} case 3:{phead=searchmenu(phead); //查找 system("cls"); break;} case 4:{phead=revise(phead); // 修改 system("cls"); break;} case 5:{phead=sortmenu(phead); //排序 system("cls"); break;} case 6:{phead=delete_Stu(phead); //刪除 system("cls"); break;} case 0:{ print2(); exit(1); } default:{printf("輸入錯(cuò)誤!請(qǐng)重新輸入\n"); system("pause");} } } free(phead);}void main() //主函數(shù) { system("color 3A"); print1(); login_acc();} pticket Create(pticket pHead) //創(chuàng)建鏈表 { fflush(stdin); system("cls"); char choice; while(1) { printf("確定重新輸入所有信息麼?\n如果重新輸入,之前所有信息會(huì)被刪除!\n請(qǐng)謹(jǐn)慎選擇!(Y or N)\n"); if(panduan(choice)==1) break; else return pHead; } pticket pNew,pEnd; iCount=0; fflush(stdin); pEnd=pHead; do { pNew=(pticket)malloc(sizeof(ticket)); if(pNew==NULL) return pHead; printf("請(qǐng)輸入代碼:"); scanf("%s",pNew->number); printf("請(qǐng)輸入名稱:"); scanf("%s",pNew->name); printf("請(qǐng)輸入影院:"); scanf("%s",&pNew->cinema); printf("請(qǐng)輸入時(shí)長(zhǎng):"); scanf("%d",&pNew->time); printf("請(qǐng)輸入價(jià)格:"); scanf("%lf",&pNew->price); printf("請(qǐng)輸入評(píng)分:"); scanf("%lf",&pNew->grade); pEnd->next=pNew; pEnd=pNew; iCount++; fflush(stdin); printf("是否繼續(xù)? Y or N\n"); choice=getchar(); getchar(); while(choice!='y'&&choice!='Y'&&choice!='n'&&choice!='N') { printf("輸入錯(cuò)誤!請(qǐng)重新輸入您的選擇:\n"); choice=getchar(); getchar(); } getchar(); }while(choice=='y'||choice=='Y'); pEnd->next=NULL; system("cls"); return pHead;}
很簡(jiǎn)易的一個(gè)影院管理系統(tǒng),寫(xiě)出來(lái)也只能是一個(gè)參考,菜雞代碼,希望有用。
另附 stata.h文件
#ifndef state_h#define state_htypedef struct accout{ char pass[20]; char name[20]; struct accout *next;}Accout,*pAccout; typedef struct ticket{ char number[15]; char name[30]; char cinema[30]; int time; double price; double grade; struct student *next;}ticket,*pticket; pAccout router_acc(pAccout ahead); //讀取賬戶信息//void pAccout save_acc(pAccout ahead); //保存賬戶void login_acc(); //登錄函數(shù) void login_printf(); //登錄界面 pAccout login_panduan(pAccout ahead); pticket Create(pticket phead); //聲明創(chuàng)建鏈表void meun(); //綜合 void print(); //主菜單 void print1(); //主界面void print2(); //退出界面 pticket searchmenu(pticket phead); //查詢子系統(tǒng)菜單 pticket search2(pticket phead); //學(xué)號(hào)查詢 pticket search3(pticket phead); //姓名查詢pticket search4(pticket phead); pticket sortmenu(pticket phead); //排序子系統(tǒng)菜單 pticket sort1(pticket phead); //年齡排序 pticket sort2(pticket phead); //平均分排序 pticket sort3(pticket phead); //總分排序 pticket sort_1(pticket phead);pticket sort_2(pticket phead); pticket sort_3(pticket phead); pticket Insert(pticket phead); //新學(xué)生信息錄入 void print_stu1(pticket phead);//打印學(xué)生信息 void print_stu2();//學(xué)生信息表格 pticket delete_Stu(pticket phead); //刪除信息 void Save_Stu(pticket phead);//信息保存 pticket router_Stu(pticket phead); //信息讀取 pticket revise(pticket phead); //修改信息 int panduan(char choice); //布爾判斷 int back(char *a); //返回整數(shù)函數(shù) #endif
具體的設(shè)計(jì)思路及流程圖如下所示:
各個(gè)模塊詳細(xì)的功能描述。
(1)、主函數(shù)
主函數(shù)從文件中讀取文件,根據(jù)每個(gè)字符對(duì)應(yīng)的ASCII碼的數(shù)值,統(tǒng)計(jì)各字符出現(xiàn)的次數(shù),用s數(shù)組存取出現(xiàn)的字符,用w數(shù)組存取各字符的權(quán)值,進(jìn)行樹(shù)的創(chuàng)建與各字符的編碼。
(2)、樹(shù)的創(chuàng)建
首先將哈夫曼樹(shù)置空,根據(jù)字符的個(gè)數(shù)確定需要的初始化的長(zhǎng)度,如果有n個(gè)字符,則會(huì)有2*n-1個(gè)結(jié)點(diǎn),將前n個(gè)結(jié)點(diǎn)的左右孩子父親結(jié)點(diǎn)置空,將對(duì)應(yīng)的權(quán)值存入,在前n個(gè)結(jié)點(diǎn)中選出沒(méi)有父親結(jié)點(diǎn)的最大值和最小值,進(jìn)行相加,將和存入新的節(jié)點(diǎn)中,并更新對(duì)應(yīng)孩子結(jié)點(diǎn)的父親結(jié)點(diǎn),及相應(yīng)的父親結(jié)點(diǎn)。
(3)、對(duì)每個(gè)字符進(jìn)行編碼
從葉子結(jié)點(diǎn)向根回溯,將建立好的哈夫曼樹(shù)進(jìn)行編碼,如果是左孩子則編碼為0,如果是右孩子則編碼為1,當(dāng)回溯到根結(jié)點(diǎn)時(shí),則這個(gè)字符編碼結(jié)束,將字符對(duì)應(yīng)的編碼存入到hc數(shù)組中,不斷重復(fù)此步驟,直至所有的字符都編碼結(jié)束。
(4)、對(duì)文件里的文件進(jìn)行編碼
將文件中的文章通過(guò)fgetc();進(jìn)行讀出,將讀出的字符一一的讀入到c數(shù)組中,如果c數(shù)組中的字符與s數(shù)組中的字符一致,則輸出其對(duì)應(yīng)的hc數(shù)組中的編碼,并將其存入到文件中。
(5)、對(duì)文件里的文件進(jìn)行譯碼
譯碼過(guò)程不同于編碼過(guò)程,譯碼過(guò)程是從根結(jié)點(diǎn)向葉子結(jié)點(diǎn)回溯如果是0則進(jìn)入左孩子,如果是1則進(jìn)入右孩子,由于哈夫曼樹(shù)是一棵最小二叉樹(shù),所以哈夫曼樹(shù)的結(jié)點(diǎn)只能是0或者2,其中一個(gè)結(jié)點(diǎn)若為空,則證明其為葉子結(jié)點(diǎn),當(dāng)遇到葉子結(jié)點(diǎn),則輸出葉子結(jié)點(diǎn)對(duì)應(yīng)的字符,將譯碼后的字符串記錄到文件中。
感謝各位的閱讀,以上就是“C語(yǔ)言怎么實(shí)現(xiàn)影院管理系統(tǒng)”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)C語(yǔ)言怎么實(shí)現(xiàn)影院管理系統(tǒng)這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。