網站首頁 編程語言 正文
本文實例為大家分享了C語言實現影院管理系統程序的具體代碼,供大家參考,具體內容如下
**影院管理系統基本運行圖**
下面是實現全部功能的函數與解析與思路
**結構體與預定義**
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<windows.h>
typedef struct accout
{
?? ?char pass[20];
?? ?char name[20];
?? ?struct accout* next;
}mm, * MM;
typedef struct movie
{
?? ?char number[20];//電影序號?
?? ?char name[20];//電影名稱?
?? ?int price;//電影價格?
?? ?int grade;//電影評分?
?? ?int time;//電影時長?
?? ?struct movie* next;
} Linklist;
下面基本分為三大部分
一.登錄與注冊
1.注冊函數
void Register(MM head)//注冊
{
?? ?system("cls");//清屏
?? ?char username[20] = "";
?? ?char password[13] = "";
?? ?char pass[13] = "";
?? ?char q;
?? ?int i;
?? ?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;
?? ??? ?}
?? ??? ?else if (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:\\課設\\accout.txt", "ab+");
?? ??? ??? ?fprintf(fp, "%s %s", username, password);//把內存中的文件輸入到硬盤之中
?? ??? ??? ?fclose(fp);
?? ??? ??? ?system("cls");
?? ??? ??? ?printf("\n\n\n注冊成功\n\n");
?? ??? ??? ?system("pause");
?? ??? ?}
}
2.判斷函數
MM judge(mm * head)//判斷密碼是否輸入正確?
?? ?{
?? ??? ?char name1[20] = "", pass1[20] = "";
?? ??? ?char q;
?? ??? ?MM p1;
?? ??? ?int i = 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;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else if (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");
?? ??? ??? ??? ??? ??? ?return head;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ??? ?else
?? ??? ??? ??? ??? ?{
?? ??? ??? ??? ??? ??? ?printf("登陸失敗");
?? ??? ??? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?p1 = p1->next;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?if (p1 == NULL)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("\n\n\n\n\t\t\t\t輸入有誤");
?? ??? ??? ??? ?system("cls");
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?return head;
?? ?}
3./打開讀取文件之前注冊的賬號和密碼
放到鏈表里面操作
MM AccountLibrary(MM head)//打開讀取注冊的賬號和密碼,放到鏈表里面?
?? ?{?? ?//用戶數據庫
?? ??? ?FILE* fp1 = fopen("d:\\課設\\accout.txt", "r");
?? ??? ?while (!feof(fp1))
?? ??? ?//feof()是檢測流上的文件結束符的函數,如果文件結束,則返回非0值,否則返回0
?? ??? ?{
?? ??? ??? ?MM q = (MM)malloc(sizeof(mm));
?? ??? ??? ?fscanf(fp1, "\n%s%s\n", q->name, q->pass);
?? ??? ??? ?q->next = head;
?? ??? ??? ?head = q;
?? ??? ?}
?? ??? ?fclose(fp1);
?? ??? ?return head;
?? ?}
4.用戶或者管理員進行注冊或者登錄操作
以下代碼為具體部分操作函數
int E=judge(head);//將E作為判斷judge函數返回值的標志?? ??? ??? ??? ??? ??? ??? ?
if (!E)
guanliyuan();/user()
5.登錄主函數
void login()
{
?? ?system("cls");
?? ?int bk = 0;
?? ?int bb = 0;
?? ?MM head = 0, p1 = 0;
?? ?//?? ?char a[10]={0};
?? ?head = (mm*)malloc(sizeof(mm));
?? ?head->next = NULL;
?? ?while (1)
?? ?{
?? ??? ?//?? ?char a[200];
?? ??? ?//?? ?char b[200];
?? ??? ?int a, b;
?? ??? ?printf_d();
?? ??? ?printf("請輸入 ");
?? ??? ?scanf("%d", &a);
?? ??? ?switch (a)
?? ??? ?{
?? ??? ?case 1:
?? ??? ?{//登錄?
?? ??? ??? ?printf1();
?? ??? ??? ?printf("請輸入 ");
?? ??? ??? ?scanf("%d", &b);
?? ??? ??? ?switch (b)
?? ??? ??? ?{
?? ??? ??? ?case 1: {
?? ??? ??? ??? ?AccountLibrary(head);//在文件中查找注冊過的賬號和密碼?
?? ??? ??? ??? ?int E=judge(head);?? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ?if (!E)
?? ??? ??? ??? ?guanliyuan();
?? ??? ??? ?}
?? ??? ??? ?case 2: {
?? ??? ??? ??? ?//judge(head);//用戶登錄?
?? ??? ??? ??? ?AccountLibrary(head);
?? ??? ??? ??? ?int E=judge(head);
?? ??? ??? ??? ?if(!E)
?? ??? ??? ??? ?user();
?? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ?case 0: {
?? ??? ??? ??? ?printf("再見");
?? ??? ??? ??? ?exit(0);
?? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ?default:printf("輸入錯誤");
?? ??? ??? ?}
?? ??? ?case 2:
?? ??? ?{//注冊?
?? ??? ??? ?Register(head);
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 0:
?? ??? ?{//退出?
?? ??? ??? ?printf("再見");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?}
?? ??? ?}
?? ?}
}
二.管理員系統操作
管理員系統登錄之后函數
void guanliyuan()//管理員系統
{
?? ?Linklist* head;
?? ?head = (Linklist*)malloc(sizeof(Linklist));
?? ?head->next = NULL;//創建頭結點
?? ?//錄入信息
?? ?int a = 0, b = 0;
?? ?while (1)
?? ?{
?? ??? ?system("cls");
?? ??? ?fflush(stdin);
?? ??? ?printf2();
?? ??? ?printf("請輸入指令");
?? ??? ?scanf("%d", &a);
?? ??? ?fflush(stdin);
?? ??? ?switch (a)
?? ??? ?{
?? ??? ?case 1://錄入信息?
?? ??? ?{
?? ??? ??? ?head = Input();
?? ??? ??? ?Foutput(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 2://修改?
?? ??? ?{
?? ??? ??? ?head = read();
?? ??? ??? ?change(head);
?? ??? ??? ?Foutput(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 3://刪除?
?? ??? ?{
?? ??? ??? ?head = read();
?? ??? ??? ?delete_1(head);
?? ??? ??? ?Foutput(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 4://排序?
?? ??? ?{
?? ??? ??? ?head = read();
?? ??? ??? ?sort(head);
?? ??? ??? ?output(head);
?? ??? ??? ?//Foutput(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 5://添加?
?? ??? ?{
?? ??? ??? ?head = read();
?? ??? ??? ?insert(head);
?? ??? ??? ?Foutput(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 6://查找?
?? ??? ?{
?? ??? ??? ?head = read();
?? ??? ??? ?fflush(stdin);
?? ??? ??? ?search(head);
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?case 7://預覽
?? ??? ??? ?preview();
?? ??? ??? ?break;
?? ??? ?/*case 8://修改密碼//砍掉的功能
?? ??? ?{
?? ??? ??? ?MM head;
?? ??? ??? ?head = NULL;
?? ??? ??? ?printf("\t\t\t歡迎修改密碼\n");
?? ??? ??? ?//head=duqu_cipher(head);
?? ??? ??? ?head = AccountLibrary(head);
?? ??? ??? ?change_cipher(head);
?? ??? ??? ?luru_cipher(head);
?? ??? ??? ?break;
?? ??? ?}*/
?? ??? ?case 0://退出系統?
?? ??? ?{
?? ??? ??? ?printf("感謝使用\n");
?? ??? ??? ?exit(1);
?? ??? ?}
?? ??? ?default: {
?? ??? ??? ?printf("輸入錯誤!請重新輸入");
?? ??? ??? ?system("pause");
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?}
?? ?}
?? ?free(head);
}
1.錄入信息
錄入信息分為兩部分
void Input_1(Linklist* pNew)//輸入結點的值?
{
?? ?int i = 0, j = 0, num = 0, sum = 0;
?? ?char ch = 0;
?? ?fflush(stdin);
?? ?//pNew = (Linklist*)malloc(sizeof(Linklist));
?? ?printf("請輸入電影序號\n");
?? ?scanf("%s", pNew->number);
?? ?fflush(stdin);//清除緩存區數據
?? ?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是沒有數據所以釋放掉
?? ?return head;
}
2.修改
void change(Linklist* head)//修改?
{
?? ?read();
?? ?int n, j, k, l, y;
?? ?char m[20] = "";
?? ?char i = 0;
?? ?Linklist* p = head;
?? ?printf("1.名稱2.評分3.價格4.時長5.編號");
?? ?printf("請輸入要修改的項目");
?? ?scanf("%d", &n);
?? ?switch (n)
?? ?{
?? ?case 1:
?? ?{
?? ??? ?printf("請輸入要修改的電影名稱");
?? ??? ?scanf("%s", m);
?? ??? ?while (p != NULL)
?? ??? ?{
?? ??? ??? ?if (strcmp(p->number, m) == 0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("輸入修改之后的名稱");
?? ??? ??? ??? ?scanf("%s", &p->name);
?? ??? ??? ??? ?//strcpy()
?? ??? ??? ??? ?printf("修改完成");
?? ??? ??? ?}
?? ??? ??? ?p = p->next;
?? ??? ?}
?? ?}
?? ?case 2:
?? ?{
?? ??? ?printf("請輸入要修改的的電影評分");
?? ??? ?scanf("%d", &j);
?? ??? ?while (p != NULL)
?? ??? ?{
?? ??? ??? ?if (p->grade == j)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("請輸入修改之后的評分");
?? ??? ??? ??? ?scanf("%d", &p->grade);
?? ??? ??? ??? ?printf("修改成功");
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?case 3:
?? ?{
?? ??? ?printf("請輸入要修改的電影價格");
?? ??? ?scanf("%d", &l);
?? ??? ?while (p != NULL)
?? ??? ?{
?? ??? ??? ?if (p->price == l)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("請輸入修改之后的價格");
?? ??? ??? ??? ?scanf("%d", &p->price);
?? ??? ??? ??? ?printf("修改成功");
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?case 4:
?? ?{
?? ??? ?printf("請輸入要修改電影時長");
?? ??? ?scanf("%d", &k);
?? ??? ?while (p != NULL)
?? ??? ?{
?? ??? ??? ?if (p->time == k)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("請輸入修改之后的電影時長");
?? ??? ??? ??? ?scanf("%d", &p->time);
?? ??? ??? ??? ?printf("修改成功");
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?case 5:
?? ?{
?? ??? ?printf("請輸入要修改電影編號");
?? ??? ?scanf("%d", &y);
?? ??? ?while (p != NULL)
?? ??? ?{
?? ??? ??? ?if (p->time == y)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("請輸入修改之后的電影時長");
?? ??? ??? ??? ?scanf("%d", &p->time);
?? ??? ??? ??? ?printf("修改成功");
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?}
}
3.刪除
void delete_1(Linklist* head)//刪除?
{
?? ?Linklist* p, * p1 = head;
?? ?p = p1->next;
?? ?int n, i;
?? ?char a[20];
?? ?printf("請輸入1確認刪除");
?? ?scanf("%d", &i);
?? ?switch (i)
?? ?{
?? ?case 1:
?? ?{
?? ??? ?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.排序
這里用得是鏈表冒泡排序
有點難理解,附圖
void sort(Linklist* head)//單鏈表冒泡排序?
{
?? ?int n;
?? ?Linklist* p, * q, * p1;
?? ?p1 = NULL;
?? ?printf("1.按票價從低到高排序2.按評分從低到高排序3.按時長從短到長排序\n");
?? ?printf("請選擇排序方式");
?? ?scanf("%d", &n);
?? ?switch (n)
?? ?{
?? ?case 1:
?? ?{
?? ??? ?while ((head->next->next) != p1)//相當于數組第一層循環?
?? ??? ?{
?? ??? ??? ?p = head;//一個數據?
?? ??? ??? ?q = head->next;//下一個數據
?? ??? ??? ?while (q->next != p1)
?? ??? ??? ?{
?? ??? ??? ??? ?if (q->price > q->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;//相當于數組比較的下一個外層?? ?
?? ??? ?}
?? ??? ?printf("排序完成");
?? ??? ?output(head);
?? ??? ?system("pause");
?? ??? ?break;
?? ?}
?? ?case 2:
?? ?{
?? ??? ?while ((head->next->next) != p1)//相當于數組第一層循環?
?? ??? ?{
?? ??? ??? ?p = head;//一個數據?
?? ??? ??? ?q = head->next;//下一個數據
?? ??? ??? ?while (q->next != p1)
?? ??? ??? ?{
?? ??? ??? ??? ?if (q->grade > q->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;//相當于數組比較的下一個外層?? ?
?? ??? ?}
?? ??? ?printf("排序完成");
?? ??? ?output(head);
?? ??? ?break;
?? ?}
?? ?case 3:
?? ?{
?? ??? ?while ((head->next->next) != p1)//相當于數組第一層循環?
?? ??? ?{
?? ??? ??? ?p = head;//一個數據?
?? ??? ??? ?q = head->next;//下一個數據
?? ??? ??? ?while (q->next != p1)
?? ??? ??? ?{
?? ??? ??? ??? ?if (q->time > q->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;//相當于數組比較的下一個外層?? ?
?? ??? ?}
?? ??? ?printf("排序完成");
?? ??? ?output(head);
?? ??? ?break;
?? ?}
?? ?}
}
5.添加
void insert(Linklist* head)//添加新的電影信息?
{
?? ?Linklist* p = head, * p1;
?? ?//p=p1->next;
?? ?int n, i;
?? ?printf("請輸入1進行添加信息操作");
?? ?scanf("%d", &n);
?? ?switch (n)
?? ?{
?? ?case 1:
?? ?{
?? ??? ?printf("請輸入要插入信息前面的電影編號");
?? ??? ?scanf("%d", &i);
?? ??? ?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.查找
void search(Linklist* head) //查詢?
{
?? ?Linklist* p = head;
?? ?//int n;
?? ?char a[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");
}
三.用戶操作系統
用戶登錄主函數
void user()
{
?? ?fflush("stdin");
?? ?Linklist* head;
?? ?head = (Linklist*)malloc(sizeof(Linklist));
?? ?head->next = NULL;
?? ?int n;
?? ?printf3();
?? ?printf("請輸入要選擇的操作");
?? ?scanf("%d", &n);
?? ?system("pause");
?? ?char c[20] = "";
?? ?//?? ?printf("")
?? ?switch (n)
?? ?{
?? ?case 1:
?? ?{
?? ??? ?printf("\t\t\t歡迎預覽\n");
?? ??? ?preview();
?? ??? ?system("pause");
?? ??? ?break;
?? ?}
?? ?case 2:
?? ?{
?? ??? ?printf("\t\t歡迎來到查詢系統\n");
?? ??? ?head = read();
?? ??? ?fflush(stdin);
?? ??? ?search(head);
?? ??? ?system("cls");
?? ??? ?break;
?? ?}
?? ?case 3:
?? ?{
?? ??? ?printf("\t\t\t歡迎來到購票系統\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;
?? ?}
?? ?case 4:
?? ?{
?? ??? ?printf("感謝使用");
?? ??? ?exit(1);
?? ?}
?? ?}
}
預覽
void preview()
{
?? ?printf("\t\t***********************************************\n");
?? ?printf("\t\t| 電影名稱:Captain America ? ? ? 價格: 35 ? ? |\n");
?? ?printf("\t\t| 評分:9 ? ? ? ? ? ? ? ?時長: 135 ? ? ? ? ? ? |\n");
?? ?printf("\t\t***********************************************\n");
?? ?printf("\t\t***********************************************\n");
?? ?printf("\t\t| 電影名稱:The Shawshank Redemption ? 價格:36 |\n");
?? ?printf("\t\t| 評分:8 ? ? ? ? ? ? ? ?時長:126 ? ? ? ? ? ? ?|\n");
?? ?printf("\t\t***********************************************\n");
?? ?printf("\t\t***********************************************\n");
?? ?printf("\t\t| 電影名稱:Citizen Kane Redemption ? ?價格: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| 電影名稱:The Godfather Part II ? ?價格:31 ? |\n");
?? ?printf("\t\t| 評分:5 ? ? ? ? ? ? ? ?時長:134 ? ? ? ? ? ? ?|\n");
?? ?printf("\t\t***********************************************\n");
}
四.文件操作
void Foutput(Linklist* head)//電影信息錄入文件
{
?? ?Linklist* pt = head;
?? ?FILE* fp;
?? ?pt = pt->next;
?? ?fp = fopen("d:\\課設\\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);
}
五.打印函數實現
void printf2()
{
?? ?system("cls");
?? ?printf("\t\t\t|*******************************|\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| ? ? ? ? ?3.刪除 ??? ? ? ? ? ? ?|\n");
?? ?printf("\t\t\t| ? ? ? ? ?4.排序 ? ? ? ? ? ? ? |\n");
?? ?printf("\t\t\t| ? ? ? ? ?5.添加 ? ? ? ? ? ? ? |\n");
?? ?printf("\t\t\t| ? ? ? ? ?6.查詢 ? ? ? ? ? ? ? |\n");
?? ?printf("\t\t\t| ? ? ? ? ?7.預覽 ? ? ? ? ? ? ? |\n");
?? ?printf("\t\t\t|-------------------------------|\n");
?? ?printf("\t\t\t|-------------------------------|\n");
?? ?printf("\t\t\t| ? ? ? ? ?0.退出程序 ? ? ? ? ? |\n");
?? ?printf("\t\t\t|===============================|\n");
?? ?printf("\t\t\t請選擇你需要的操作\t\t");
}//管理員系統菜單
void printf3()//用戶登錄界面
{
?? ?system("cls");
?? ?printf("\t\t\t|*******************************|\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| ? ? ? ? ?3.購票并打印報表?? ? ?|\n");
?? ?printf("\t\t\t| ? ? ? ? ?0.退出程序 ? ? ? ? ? |\n");
?? ?printf("\t\t\t|===============================|\n");
}
void printf_d()
{
?? ?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 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");
}
原文鏈接:https://blog.csdn.net/weixin_50798782/article/details/114378677
相關推薦
- 2022-10-31 Kotlin擴展函數超詳細介紹_Android
- 2022-04-19 C#多線程系列之線程的創建和生命周期_C#教程
- 2022-10-23 Python?Pandas數據合并pd.merge用法詳解_python
- 2022-05-20 springCloud_Nacos服務搭建
- 2022-12-24 Kubernetes?controller?manager運行機制源碼解析_云和虛擬化
- 2022-12-28 Python中的Decorator裝飾器的使用示例_python
- 2022-10-11 React - 判斷焦點是否在某個元素上
- 2022-02-25 Oracle工具PL/SQL的基本語法_oracle
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支