




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第C語言實現(xiàn)影院管理系統(tǒng)程序設(shè)計本文實例為大家分享了C語言實現(xiàn)影院管理系統(tǒng)程序的具體代碼,供大家參考,具體內(nèi)容如下
**影院管理系統(tǒng)基本運行圖**
下面是實現(xiàn)全部功能的函數(shù)與解析與思路
**結(jié)構(gòu)體與預(yù)定義**
#includestdio.h
#includestdlib.h
#includestring.h
#includeconio.h
#includewindows.h
typedefstructaccout
charpass[20];
charname[20];
structaccout*next;
}mm,*MM;
typedefstructmovie
charnumber[20];//電影序號
charname[20];//電影名稱
intprice;//電影價格
intgrade;//電影評分
inttime;//電影時長
structmovie*next;
}Linklist;
下面基本分為三大部分
一.登錄與注冊
1.注冊函數(shù)
voidRegister(MMhead)//注冊
system("cls");//清屏
charusername[20]="";
charpassword[13]="";
charpass[13]="";
charq;
inti;
FILE*fp;
printf("\n\n\n");
printf("\t\t\t\t賬號:");
scanf("%s",username);
getchar();
printf("\t\t\t\t密碼:");
i=0;
while(1)
{
q=getch();
if(q=='\r')
{
password[i]='\0';
break;
}
elseif(q=='\b')
{
printf("\b\b");
password[i++]=q;
}
else
{
password[i++]=q;
printf("*");
}
}
printf("\n");
printf("\t\t\t\t請確認密碼");
i=0;
while(1)
{
q=getch();
if(q!=13)
{
printf("*");
pass[i++]=q;
}
else
{
pass[i]='\0';
printf("\n");
break;
}
}
if(strcmp(pass,password)==0)
{
fp=fopen("d:\\課設(shè)\\accout.txt","ab+");
fprintf(fp,"%s%s",username,password);//把內(nèi)存中的文件輸入到硬盤之中
fclose(fp);
system("cls");
printf("\n\n\n注冊成功\n\n");
system("pause");
}
}
2.判斷函數(shù)
MMjudge(mm*head)//判斷密碼是否輸入正確
{
charname1[20]="",pass1[20]="";
charq;
MMp1;
inti=0,j=0;
system("cls");
printf("\n\n\n\n");
while(1)
{
j++;
p1=head-next;
printf("\t\t\t\t賬號");
scanf("%s",name1);
getchar();
printf("\t\t\t\t密碼");
i=0;
while(1)
{
j++;
q=getch();
if(q=='\r')
{
pass1[i]='\0';
break;
}
elseif(q=='\b')
{
printf("\b\b");
pass1[i++]=q;
}
else
{
pass1[i++]=q;
printf("*");
}
}
while(p1!=NULL)
{
if(strcmp(name1,p1-name)==0)
{
if(strcmp(pass1,p1-pass)==0)
{
printf("\n\n\t\t登錄成功");
system("pause");
returnhead;
}
else
{
printf("登陸失敗");
system("pause");
}
}
else
{
p1=p1-next;
}
}
if(p1==NULL)
{
printf("\n\n\n\n\t\t\t\t輸入有誤");
system("cls");
break;
}
}
returnhead;
}
3./打開讀取文件之前注冊的賬號和密碼
放到鏈表里面操作
MMAccountLibrary(MMhead)//打開讀取注冊的賬號和密碼,放到鏈表里面
{
//用戶數(shù)據(jù)庫
FILE*fp1=fopen("d:\\課設(shè)\\accout.txt","r");
while(!feof(fp1))
//feof()是檢測流上的文件結(jié)束符的函數(shù),如果文件結(jié)束,則返回非0值,否則返回0
{
MMq=(MM)malloc(sizeof(mm));
fscanf(fp1,"\n%s%s\n",q-name,q-pass);
q-next=head;
head=q;
}
fclose(fp1);
returnhead;
}
4.用戶或者管理員進行注冊或者登錄操作
以下代碼為具體部分操作函數(shù)
intE=judge(head);//將E作為判斷judge函數(shù)返回值的標志
if(!E)
guanliyuan();/user()
5.登錄主函數(shù)
voidlogin()
system("cls");
intbk=0;
intbb=0;
MMhead=0,p1=0;
//
chara[10]={0};
head=(mm*)malloc(sizeof(mm));
head-next=NULL;
while(1)
{
//
chara[200];
//
charb[200];
inta,b;
printf_d();
printf("請輸入");
scanf("%d",
switch(a)
{
case1:
{//登錄
printf1();
printf("請輸入");
scanf("%d",
switch(b)
{
case1:{
AccountLibrary(head);//在文件中查找注冊過的賬號和密碼
intE=judge(head);
if(!E)
guanliyuan();
}
case2:{
//judge(head);//用戶登錄
AccountLibrary(head);
intE=judge(head);
if(!E)
user();
break;
}
case0:{
printf("再見");
exit(0);
break;
}
default:printf("輸入錯誤");
}
case2:
{//注冊
Register(head);
break;
}
case0:
{//退出
printf("再見");
break;
}
}
}
}
}
二.管理員系統(tǒng)操作
管理員系統(tǒng)登錄之后函數(shù)
voidguanliyuan()//管理員系統(tǒng)
Linklist*head;
head=(Linklist*)malloc(sizeof(Linklist));
head-next=NULL;//創(chuàng)建頭結(jié)點
//錄入信息
inta=0,b=0;
while(1)
{
system("cls");
fflush(stdin);
printf2();
printf("請輸入指令");
scanf("%d",
fflush(stdin);
switch(a)
{
case1://錄入信息
{
head=Input();
Foutput(head);
system("cls");
break;
}
case2://修改
{
head=read();
change(head);
Foutput(head);
system("cls");
break;
}
case3://刪除
{
head=read();
delete_1(head);
Foutput(head);
system("cls");
break;
}
case4://排序
{
head=read();
sort(head);
output(head);
//Foutput(head);
system("cls");
break;
}
case5://添加
{
head=read();
insert(head);
Foutput(head);
system("cls");
break;
}
case6://查找
{
head=read();
fflush(stdin);
search(head);
system("cls");
break;
}
case7://預(yù)覽
preview();
break;
/*case8://修改密碼//砍掉的功能
{
MMhead;
head=NULL;
printf("\t\t\t歡迎修改密碼\n");
//head=duqu_cipher(head);
head=AccountLibrary(head);
change_cipher(head);
luru_cipher(head);
break;
}*/
case0://退出系統(tǒng)
{
printf("感謝使用\n");
exit(1);
}
default:{
printf("輸入錯誤!請重新輸入");
system("pause");
break;
}
}
}
free(head);
}
1.錄入信息
錄入信息分為兩部分
voidInput_1(Linklist*pNew)//輸入結(jié)點的值
inti=0,j=0,num=0,sum=0;
charch=0;
fflush(stdin);
//pNew=(Linklist*)malloc(sizeof(Linklist));
printf("請輸入電影序號\n");
scanf("%s",pNew-number);
fflush(stdin);//清除緩存區(qū)數(shù)據(jù)
if(pNew-number[0]=='#')
return;
printf("請輸入電影名稱\n");
scanf("%s",pNew-name);
fflush(stdin);
printf("請輸入電影價格\n");
scanf("%d",pNew-price);
fflush(stdin);
printf("請輸入電影評分\n");
scanf("%d",pNew-grade);
fflush(stdin);
printf("請輸入電影時長\n");
scanf("%d",pNew-time);
fflush(stdin);
printf("\n");
Linklist*Input()//手動輸入,錄入信息鏈表
Linklist*head=NULL,*pEnd,*pNew;
pEnd=head=(Linklist*)malloc(sizeof(Linklist));
printf("電影序號輸入#時停止輸入");
pNew=(Linklist*)malloc(sizeof(Linklist));
Input_1(pNew);
while(pNew-number[0]!='#')//尾插法
{
pEnd-next=pNew;
pNew-next=NULL;
pEnd=pNew;
pNew=(Linklist*)malloc(sizeof(Linklist));
Input_1(pNew);
printf("\n");
}
Foutput(head);
free(pNew);//最后一個pNew是沒有數(shù)據(jù)所以釋放掉
returnhead;
}
2.修改
voidchange(Linklist*head)//修改
read();
intn,j,k,l,y;
charm[20]="";
chari=0;
Linklist*p=head;
printf("1.名稱2.評分3.價格4.時長5.編號");
printf("請輸入要修改的項目");
scanf("%d",
switch(n)
{
case1:
{
printf("請輸入要修改的電影名稱");
scanf("%s",m);
while(p!=NULL)
{
if(strcmp(p-number,m)==0)
{
printf("輸入修改之后的名稱");
scanf("%s",p-name);
//strcpy()
printf("修改完成");
}
p=p-next;
}
}
case2:
{
printf("請輸入要修改的的電影評分");
scanf("%d",
while(p!=NULL)
{
if(p-grade==j)
{
printf("請輸入修改之后的評分");
scanf("%d",p-grade);
printf("修改成功");
}
}
}
case3:
{
printf("請輸入要修改的電影價格");
scanf("%d",
while(p!=NULL)
{
if(p-price==l)
{
printf("請輸入修改之后的價格");
scanf("%d",p-price);
printf("修改成功");
}
}
}
case4:
{
printf("請輸入要修改電影時長");
scanf("%d",
while(p!=NULL)
{
if(p-time==k)
{
printf("請輸入修改之后的電影時長");
scanf("%d",p-time);
printf("修改成功");
}
}
}
case5:
{
printf("請輸入要修改電影編號");
scanf("%d",
while(p!=NULL)
{
if(p-time==y)
{
printf("請輸入修改之后的電影時長");
scanf("%d",p-time);
printf("修改成功");
}
}
}
}
}
3.刪除
voiddelete_1(Linklist*head)//刪除
Linklist*p,*p1=head;
p=p1-next;
intn,i;
chara[20];
printf("請輸入1確認刪除");
scanf("%d",
switch(i)
{
case1:
{
printf("請輸入要刪除的電影編號\n");
scanf("%s",a);
while(p!=NULL)
{
if((strcmp(p-number,a))==0)
{
printf("\t\t以下是要刪除的電影信息\n\n");
printf("%s\t%s\t%d\t%d\t%d\n\n",p-number,p-name,p-price,p-grade,p-time);
p1-next=p-next;
free(p);
printf("刪除完畢");
}
p1=p;
p=p-next;
}
}
default:
{
printf("輸入錯誤.....");
break;
}
}
}
4.排序
這里用得是鏈表冒泡排序
有點難理解,附圖
voidsort(Linklist*head)//單鏈表冒泡排序
intn;
Linklist*p,*q,*p1;
p1=NULL;
printf("1.按票價從低到高排序2.按評分從低到高排序3.按時長從短到長排序\n");
printf("請選擇排序方式");
scanf("%d",
switch(n)
{
case1:
{
while((head-next-next)!=p1)//相當于數(shù)組第一層循環(huán)
{
p=head;//一個數(shù)據(jù)
q=head-next;//下一個數(shù)據(jù)
while(q-next!=p1)
{
if(q-priceq-next-price)
{
p-next=q-next;//第一步
q-next=q-next-next;//第二步
p-next-next=q;//第三步
q=p-next;//第四補3
}
q=q-next;//接著往后走
p=p-next;
}
p1=q;//相當于數(shù)組比較的下一個外層
}
printf("排序完成");
output(head);
system("pause");
break;
}
case2:
{
while((head-next-next)!=p1)//相當于數(shù)組第一層循環(huán)
{
p=head;//一個數(shù)據(jù)
q=head-next;//下一個數(shù)據(jù)
while(q-next!=p1)
{
if(q-gradeq-next-grade)
{
p-next=q-next;//第一步
q-next=q-next-next;//第二步
p-next-next=q;//第三步
q=p-next;//第四補3
}
q=q-next;//接著往后走
p=p-next;
}
p1=q;//相當于數(shù)組比較的下一個外層
}
printf("排序完成");
output(head);
break;
}
case3:
{
while((head-next-next)!=p1)//相當于數(shù)組第一層循環(huán)
{
p=head;//一個數(shù)據(jù)
q=head-next;//下一個數(shù)據(jù)
while(q-next!=p1)
{
if(q-timeq-next-time)
{
p-next=q-next;//第一步
q-next=q-next-next;//第二步
p-next-next=q;//第三步
q=p-next;//第四補3
}
q=q-next;//接著往后走
p=p-next;
}
p1=q;//相當于數(shù)組比較的下一個外層
}
printf("排序完成");
output(head);
break;
}
}
}
5.添加
voidinsert(Linklist*head)//添加新的電影信息
Linklist*p=head,*p1;
//p=p1-next;
intn,i;
printf("請輸入1進行添加信息操作");
scanf("%d",
switch(n)
{
case1:
{
printf("請輸入要插入信息前面的電影編號");
scanf("%d",
while(p!=NULL)
{
if(atoi(p-number)==i)
{
p1=(Linklist*)malloc(sizeof(Linklist));//開辟新的空間
printf("請輸入電影編號");
scanf("%s",p-number);
printf("請輸入電影名稱");
scanf("%s",p-name);
printf("請輸入電影價格");
scanf("%d",p-price);
printf("請輸入電影評分");
scanf("%d",p-grade);
printf("請輸入電影時長");
scanf("%d",p-time);
printf("電影信息添加完畢");
p1-next=p-next;//
p-next=p;
}
p=p-next;//遍歷
}
}
default:
{
printf("輸入錯誤。。。。");
}
}
Foutput(head);
}
*6.查找
voidsearch(Linklist*head)//查詢
Linklist*p=head;
//intn;
chara[20]="";
printf("請輸入要查詢電影編號");
scanf("%s",a);
while(p!=NULL)
{
if((strcmp(p-number,a))==0)
{
printf("編號\t名稱\t價格\t評分\t時長\n");
printf("%s\t%s\t%d\t%d\t%d\t\t",p-number,p-name,p-price,p-grade,p-time);
break;
}
p=p-next;
}
system("pause");
}
三.用戶操作系統(tǒng)
用戶登錄主函數(shù)
voiduser()
fflush("stdin");
Linklist*head;
head=(Linklist*)malloc(sizeof(Linklist));
head-next=NULL;
intn;
printf3();
printf("請輸入要選擇的操作");
scanf("%d",
system("pause");
charc[20]="";
//
printf("")
switch(n)
{
case1:
{
printf("\t\t\t歡迎預(yù)覽\n");
preview();
system("pause");
break;
}
case2:
{
printf("\t\t歡迎來到查詢系統(tǒng)\n");
head=read();
fflush(stdin);
search(head);
system("cls");
break;
}
case3:
{
printf("\t\t\t歡迎來到購票系統(tǒng)\n");
head=read();
fflush(stdin);
Linklist*p=head;
//p=(Linklist*)malloc(sizeof(Linklist));
printf("\t\t\t請輸入要購買電影的編號\n");
scanf("%s",c);
//printf("ggdggd");
while(p)
{
if((strcmp(p-number,c))==0)
{
printf("*****************************");
printf("|--------電影名字%s----------|\n",p-name);
printf("|--------電影價格%d----------|\n",p-price);
printf("|--------電影時間%d----------|\n",p-time);
printf("|--------恭喜購票成功--------|\n");
printf("|----------------------------|\n");
printf("*****************************");
system("pause");
break;
}
p=p-next;
}
break;
}
case4:
{
printf("感謝使用");
exit(1);
}
}
}
預(yù)覽
voidpreview()
printf("\t\t***********************************************\n");
printf("\t\t|電影名稱:CaptainAmerica
價格:35
|\n");
printf("\t\t|評分:9
時長:135
|\n");
printf("\t\t***********************************************\n");
printf("\t\t***********************************************\n");
printf("\t\t|電影名稱:TheShawshankRedemption
價格:36|\n");
printf("\t\t|評分:8
時長:126
|\n");
printf("\t\t***********************************************\n");
printf("\t\t***********************************************\n");
printf("\t\t|電影名稱:CitizenKaneRedemption
價格:34
\n");
printf("\t\t|評分:10
時長:123
|\n");
printf("\t\t***********************************************\n");
printf("\t\t***********************************************\n");
printf("\t\t|電影名稱:Casablanca
價格:32
|\n");
printf("\t\t|評分:6
時長:157
|\n");
printf("\t\t***********************************************\n");
printf("\t\t***********************************************\n");
printf("\t\t|電影名稱:TheGodfatherPartII
價格:31
|\n");
printf("\t\t|評分:5
時長:134
|\n");
printf("\t\t***********************************************\n");
}
四.文件操作
voidFoutput(Linklist*head)//電影信息錄入文件
Linklist*pt=head;
FILE*fp;
pt=pt-next;
fp=fopen("d:\\課設(shè)\\dgw.txt","wt+");
if(fp==NULL)
{
printf("文件打開失敗");
exit(1);
}
while(pt)
{
fprintf(fp,"%s%s%d%d%d",pt-number,pt-name,pt-price,pt-grade,pt-time);
pt=pt-next;
}
fclose(fp);
}
五.打印函數(shù)實現(xiàn)
voidprintf2()
system("cls");
printf("\t\t\t|*******************************|\n");
printf("\t\t\t|
歡迎來到影院管理系統(tǒng)(管理員)|\n");
printf("\t\t\t|*******************************
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 浙江省寧波市鎮(zhèn)海中學(xué)2025年5月第二次模擬考試 生物試卷+答案
- 大班繪畫活動《美麗的衣服》
- 人類的起源和發(fā)展教學(xué)設(shè)計
- 因式分解知識點總結(jié)模版
- 開展法制教育進校園活動方案
- 工程造價管理團隊年度工作總結(jié)
- 食管類癌的臨床護理
- 影城消防培訓(xùn)試題及答案
- 銀行總行面試題目及答案
- 銀行小組面試試題及答案
- 2025年甘肅省武威第二十中學(xué)生物七年級下冊新人教版期中模擬練習(xí)題(含答案)
- 倉庫7s管理制度培訓(xùn)
- 復(fù)式交分道岔檢查課件
- 2025-2030中國斯特林制冷機行業(yè)市場發(fā)展趨勢與前景展望戰(zhàn)略研究報告
- 制造業(yè)產(chǎn)品全生命周期管理流程
- 冷庫安全培訓(xùn)
- 2024-2025北師版七下數(shù)學(xué)-第五章 圖形的軸對稱-章末復(fù)習(xí)【課件】
- 物業(yè)管理答辯5分鐘
- 屋面保溫工程施工方案
- 土木工程專業(yè)就業(yè)能力展示
- 中鋁物資有限公司招聘筆試沖刺題2025
評論
0/150
提交評論