东北大学软件学院C语言程序设计大作业:餐厅管理系统

东北大学软件学院C语言程序设计大作业

餐厅管理系统

这一份是自己做的,里面应该有超级多的bug来着,等我闲了改一下

//100张桌子
//1-4人  1-50号桌
//5-8人  51-70号
//9-15人 71-80号
//16-∞人 81-100号

#include 
#include 
#include 
#include 
#include 
#define NOT 99

//数组
char *array_name[10] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J"};                //菜名
double array_price[10] = {12.00, 23.00, 34.00, 45.00, 56.00, 67.00, 78.00, 89.00, 90.00}; //菜价
int array_rank[10] = {0};                                                                 //排名
unsigned int pin = 123456;                                                                //初始化密码
//变量
int num_of_consumers;       //顾客数量
int array_table[NOT] = {0}; //餐桌状态
FILE *fmenu;                //菜单文件
FILE *faccount;             //账单文件

//结构体
typedef struct Dish
{
    int Dish_ID;      //菜的编号
    char Dish_NP[20]; //菜名 价格
} DISH;

typedef struct Table
{
    /* data */
    int table_ID;           //桌子编号
    int dish_ID[100] = {0}; //点的菜
    struct Table *nextPtr;
    DISH array_dish[15]; //菜的信息的结构体数组
} TABLE;

//Funcation
void Fun_interface();                         //用户界面
int Fun_switch(int choose1);                  //选项
int Fun_search();                             //匹配合适桌号
TABLE *CreateOne(int table_ID2);              //点菜
void Fun_menu(FILE *fmenu1);                  //菜单文件
void Fun_account(TABLE *head, int table_ID2); //结账
double Fun_compare(double pay1, double sum1); //比较实际支付金额与应付金额
int Fun_pin();                                //密码
void Fun_interface2();                        //账目管理界面
int Fun_switch2(int choose2);                 //在账目管理界面选择操作
void Fun_rank();                              //排名

TABLE *head = (TABLE*)malloc(sizeof(TABLE));
TABLE *p = NULL;
TABLE *t = (TABLE*)malloc(sizeof(TABLE));

int main(void)
{
    int choose;

    Fun_interface();
    scanf("%d", &choose);
    //链接首尾
    head->nextPtr = t;
    t->nextPtr = NULL;
    Fun_switch(choose);
}

int Fun_switch(int choose1)
{
    int table_ID1;
    int flag; //检测密码是否正确,Y 1;N 0

    switch (choose1)
    {
    case 1:

        table_ID1 = Fun_search();
        Fun_menu(fmenu);
        *CreateOne(table_ID1);
        puts("Finished.Choose Again.");
        scanf("%d", &choose1);
        Fun_switch(choose1);
        break;
    case 2:
        puts("Please intput your tableID:");
        scanf("%d", &table_ID1);
        Fun_account(p, table_ID1);
        puts("Finished.Choose Again.");
        scanf("%d", &choose1);
        Fun_switch(choose1);
        break;
    case 3:
        Fun_interface2();
        Fun_switch2(choose1);
        puts("Finished.Choose Again.");
        scanf("%d", &choose1);
        Fun_switch(choose1);
        /*        flag = Fun_pin();
        while (flag == 0)
        {
            
            puts("Wrong.Again?");
            puts("Enter 0 for Yes,else for No.");
            scanf("%d", &yn);
            if (!yn)
            {
                
                flag = Fun_pin();
            }
            else
            {
                break; //Problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            }
        }
        */
        break;
    case 4:
        Fun_rank();
        puts("Finished.Choose Again.");
        scanf("%d", &choose1);
        Fun_switch(choose1);
        break;
    default:
        break;
    }
}

void Fun_rank()
{
    int array_rank1[10] = {0}; //排序
    int i, n;
    int temp, temp1;
//排序存在问题problem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    for (i = 9; i < 0; i--)
    {
        for (n = 0,i = 9; n < i - 1; n++)
        {
            if (array_rank1[i] < array_rank[n])
            {
                array_rank1[i] = array_rank[n];
            }
        }
    }

    puts("Stars Rank:\n");
    for (n = 0; n < 10; n++)
    {
        printf("%s:", array_name[n]);
        for (i = 0; i < array_rank[n]; i++)
        {
            printf("* ");
            temp = i;
        }
        if (temp < array_rank[temp1])
        {
            printf("\n");
        }
    }

    puts("Rank 4:");
    for (i = 0; i < 4; i++)
    {
        printf("No.%d:%s\n", i + 1, array_name[array_rank1[9 - i]]);
    }
}

/*
void Fun_rank()
{
    int array_rank1[10];

    for (int i = 0; i < 10; i++)
    {
        for (int n = 0; n < i - 1; n++)
        {
            if (array_rank1[i] < array_rank[n])
            {
                array_rank1[i] = array_rank[n];
            }
        }
    }

puts("******************");
for (int i = 0; i < 4; i++)
{
}
}
*/

int Fun_switch2(int choose2)
{
    int flag;
    int old_pin;
    puts("Please choose.");
    scanf("%d", &choose2);
    switch (choose2)
    {
    case 1:
        puts("Please enter your PIN:");
        if (flag = Fun_pin())
        {
            puts("Please enter your new PIN.");
            puts("Between 100000 and 999999.");
            old_pin = pin;
            scanf("%d", &pin);
            if (pin >= 100000 && pin <= 999999)
            {
                puts("Succeed.");
                puts("Please choose again.");
                scanf("%d", &choose2);
                Fun_switch2(choose2);
            }
            else
            {
                pin = old_pin;
                printf("Error.");
                puts("Please choose again.");
                scanf("%d", &choose2);
                Fun_switch2(choose2);
            }
        }
        break;
    case 2:
        puts("Please enter your PIN:");
        if (flag = Fun_pin())
        {
            faccount = fopen("Account.txt", "r");
            while (!feof(faccount))
            {
                int ch;
                if ((ch = fgetc(faccount)) != EOF)
                    putchar(ch);
            }
            fclose(faccount);
        }
    case 3:
        Fun_interface();
        scanf("%d", &choose2);
        Fun_switch(choose2);
    default:
        break;
    }
}

int Fun_again()
{
    int yn; //是否重新输入

    puts("Wrong Pin.Again?");
    puts("0 for Yes.Else for No.");

    scanf("%d", &yn);

    if (!yn)
    {
        return Fun_pin(); //调用函数输入密码
    }
}

int Fun_pin()
{
    int your_pin;
    scanf("%d", &your_pin);
    if (your_pin == pin)
    {

        return 1;
    }
    else
    {
        return Fun_again(); //调用函数确定是否再次输入
    }
}

void Fun_account(TABLE *pPtr, int table_ID2)
{
    int i = 0;
    int n;
    double sum = 0; //总价,后面会改变赋值
    double acc_sum; //输入到账本中的总数
    double pay;     //支付
    int flag = 0;
    //结账时间
    /*
    time_t timep;
    struct tm *time;
    time (&timep);

    time = gmtime(&timep);
    */
    while (pPtr != NULL)
    {
        if (pPtr->table_ID == table_ID2)
        {
            puts("You order is:");
            printf("%7s%7s%7s\n", "NUM", "NAME", "PRICE");
            for (i = 0; pPtr->dish_ID[i] != 0; i++)
            {
                printf("%7d%7s%7lf\n", pPtr->dish_ID[i], array_name[pPtr->dish_ID[i] - 1], array_price[pPtr->dish_ID[i] - 1]);
                sum += array_price[pPtr->dish_ID[i] - 1];
            }
            n = i + 1;
            break;
        }
        /*
        {
            for (int i = 0; pPtr->dish_ID[i] != 0; i++)
            {
                
                printf("%d%s", pPtr->dish_ID[i], pPtr->array_dish->Dish_NP[i]);
            }
            
        }
        */
        else
        {
            pPtr = pPtr->nextPtr;
        }
    }
    if (array_table[table_ID2 - 1] != 0)
    {
        printf("You have ordered %d dishes.\n", n);
        printf("You need to pay %.2lf yuan.\n", sum);
        acc_sum = sum;
        puts("You payed: ");
        scanf("%lf", &pay);
        flag = Fun_compare(pay, sum);

        while (flag != 0)
        {
            scanf("%lf", &pay);
            flag = Fun_compare(pay, flag);
        }
    }
    else
    {
        puts("No Account.");
    }
    SYSTEMTIME sys;

    GetLocalTime(&sys);

    faccount = fopen("Account.txt", "a+");
    fprintf(faccount, "%7s %7s %7s\n", "NUM", "NAME", "PRICE");

    for (i = 0; pPtr->dish_ID[i] != 0; i++)
    {
        fprintf(faccount, "%7d %7s %7lf\n", pPtr->dish_ID[i], array_name[pPtr->dish_ID[i] - 1], array_price[pPtr->dish_ID[i] - 1]);
    }
    fprintf(faccount, "%7s %7s %7s %7s %7s %7s\n", "MOUTH", "DAY", "HOURS", "MIN", "SECONDS", "YEAR");
    fprintf(faccount, "%4d %02d %02d %02d %02d %02d %03d %1d\n", sys.wYear, sys.wMonth, sys.wDay, sys.wHour, sys.wMinute, sys.wSecond, sys.wMilliseconds, sys.wDayOfWeek);
    fprintf(faccount, "%s\n", "Finial_Payment");
    fprintf(faccount, "%.2lf\n", acc_sum);

    fclose(faccount);

    array_table[table_ID2 - 1] = 0;
    free(pPtr);
    pPtr = NULL;

    puts("Save Susseed.");
}

double Fun_compare(double pay1, double sum1)
{
    int flag1 = 0;
    if (pay1 < sum1)
    {

        printf("Please pay another %.2lf yuan.\n", sum1 - pay1);
        flag1 = 1;
        return sum1 - pay1;
    }
    else if (pay1 > sum1)
    {

        printf("This is your %.2lf yuan.\n", pay1 - sum1);
        return flag1;
    }
    else
    {
        printf("Welcome your next coming.\n");
        return flag1;
    }
}

TABLE *CreateOne(int table_ID2)
{
    int i = -1;
    int line = 0;
    char find_str[2];
    find_str[0] = '*';
    char file_str[256];

    p = (TABLE *)malloc(sizeof(TABLE));
    p->table_ID = table_ID2;

    find_str[1] = table_ID2;

    fmenu = fopen("menu1.txt", "r");

    do
    {
        ++i;
        puts("Please choose dishes.Enter 0 to end:");
        scanf("%d", &p->dish_ID[i]);
        array_rank[p->dish_ID[i] - 1]++;

        /*
        while (fgets(find_str, sizeof(find_str), fmenu))
        { 
            line++;
            if (strstr(file_str, find_str))
            {       
                head->array_dish->Dish_NP[i] = *file_str;
                fclose(fmenu);
            }   
        }   
        */

    } while (p->dish_ID[i] != 0);

    fclose(fmenu);
    p->nextPtr = head->nextPtr;
    head->nextPtr = p;
}

int Fun_search()
{
    int i;
    int n;
    int table_ID2;

    puts("Please inter the number of consumers:");
    scanf("%d", &num_of_consumers);
    if (num_of_consumers >= 1 && num_of_consumers <= 4)
    {

        i = 0;
        n = 4;
    }
    else if (num_of_consumers >= 5 && num_of_consumers <= 8)
    {

        i = 4;
        n = 8;
    }
    else if (num_of_consumers >= 9 && num_of_consumers <= 15)
    {

        i = 8;
        n = 15;
    }
    else if (num_of_consumers >= 16)
    {

        i = 15;
        n = 100;
    }
    for (; i < n; i++)
    {
        if (array_table[i] == 0)
        {
            array_table[i] = 1;
            table_ID2 = i + 1;
            printf("You can eat at table *%d", table_ID2);
            break;
        }
    }
    return table_ID2;
}

void Fun_menu(FILE *fmenu1)
{
    fmenu1 = (fopen("menu1.txt", "r"));
    int num;
    char name[100];
    double price;

    printf("%7s%7s%7s\n", "NUM", "NAME", "PRICE");
    fscanf(fmenu1, "%d%29s%lf", &num, name, &price);
    while (!feof(fmenu1))
    {

        printf("%7d%7s%7.2lf\n", num, name, price);
        fscanf(fmenu1, "%d%29s%lf", &num, name, &price);
    }

    fclose(fmenu1);
}
void Fun_interface()
{
    puts("**********************");
    puts("Carteen Service System");
    puts("**********************");
    puts("1.Table");
    puts("2.Settle Accuouts");
    puts("3.Account Managment");
    puts("4.Rank");
    puts("5.Quit");
    puts("Please Choose:");
}

void Fun_interface2()
{
    puts("**********************");
    puts("Account Manage System");
    puts("**********************");
    puts("1.Modify PIN");
    puts("2.Check Account");
    puts("3.Return Service System");
}

你可能感兴趣的:(东北大学作业,程序设计)