一些变量没有转到文本文件

大家好,我是正在学习工程学C ++的学生 我的教授让我做迷你计分 在此代码上我想做一个食堂餐桌预订(除了预订以外还有其他功能)程序,并保存餐桌编号,名称和时间,但是从此代码 在我的.txt文件中,只有保留时间 我该如何解决这个问题? ps1。对不起,语法不好 ps2。你们都可以建议我改善我的编码:D

#include <iostream>
#include <windows.h>
#include <ctime>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;


void table_set(int table[6][21]);
void reserve(int table[6][21],bool restatus[6][21],string name_data[6][21],bool time_data[101][20],string time_table[20]);
void table_map(int table[6][21]);
void time(bool time_data[100][20],string time_table[20],int cnum,string name);
void timetableshow(string time_table[]);







int main()
    {   
        ofstream outdata("E:/C++ PJ/Final Project/Reserving Data.txt");
        if(!outdata)
        {   
            cout << "Reserving Data File not found or cannot be open";
            exit(1);
        }
        //data_array
        const char *day[5]={"Mon","Tue","Wed","Thu","Fri"};
        //Array for table (5*20)
        int table[6][21]={0};
        bool restatus[6][21]={0};

        string name_data[6][21];//to store name (1name/1table)
        bool time_data[101][20]={0};// to store time 
        table_set(table);
        string time_table[20]={"0","7.30","8.00","8.30","9.00","9.30","10.00","10.30","11.00"
        ,"11.30","12.00","12.30","13.00","13.30","14.00","14.30","15.00","15.30","16.00","16.30"};


        //introduce
        cout << "Welcome to Canteen reserve program"<<endl;
        cout << "Student can reserve table and order the food and beverage from seller before you come to canteen!" << endl << endl;
        cout << "Please Enter alphabet to choose service below" << endl;
        cout << "-> T for Table Reserve service" << endl;

        reserve(table,restatus,name_data,time_data,time_table);

        for(int i=1;i<=5;i++)
            {
                for(int j=1;j<=20;j++)
                    {
                        cout << setw(3) << left << restatus[i][j];
                    }
                cout << endl;
            }
        outdata << setw(10) << right << "Table" << setw(10) << right << "name" << setw(10) << right << "time" << endl;
        outdata.close();




        return 0;
    }
void table_map(int table[6][21])
    {
        for(int i=1;i<=5;i++)
        {
            for(int j=1;j<=20;j++)
            {
                cout << setw(3) << left <<  table[i][j];
            }
            cout << endl;   
        }
    }
void reserve(int table[6][21],bool restatus[6][21],string name_data[6][21],bool time_data[101][20],string time_table[20])
    {
        ofstream outdata("E:/C++ PJ/Final Project/Reserving Data.txt");
        int cnum;
        cout << "Please choose your table to reserve" << endl;
        table_map(table);   
        cout << "TABLE ====> : ";
reserve:        
        cin >> cnum;
            while(cnum<1||cnum>100)
                {
                    cout << "Sorry we have only 100 table please choose again: ";
                    cin >> cnum;
                }
            for(int row=1;row<=5;row++)
                {
                for(int column=1;column<=20;column++)
                    {
                        if(table[row][column]==cnum)
                        {
                            while(restatus[row][column]!=0)
                            {
                                cout << "This table not available please choose another : ";;
                                goto reserve;
                            }
                            restatus[row][column]=1;
                        }
                    }
                }
        string name_for_reserve;
        cout << "Please let me know your name : ";
        cin >> name_for_reserve;
            for(int row=1;row<=5;row++)
                {
                for(int column=1;column<=20;column++)
                    {
                        if(table[row][column]==cnum)
                        {
                            {name_data[row][column]=name_for_reserve;}
                        }
                    }
                }
        cout << "I was reserve table#" << cnum << endl;
        cout << "By the name :" << setw(10) << left << name_for_reserve;
        outdata << setw(10) << right << cnum << setw(10) << right << name_for_reserve << setw(10) << right << "time" << setw(10) << "\t" << right << endl;
        time(time_data,time_table,cnum,name_for_reserve);





    }

void table_set(int table[6][21])
    {
        int table_counter=1;
        {for(int row=1;row<=5;row++)
            {for(int column=1;column<=20;column++)
                {
                    table[row][column]=table_counter;
                    table_counter++;
                }
            }
        }

    }

void time(bool time_data[100][20],string time_table[20],int cnum,string name_for_reserve)
    {
        const string name = name_for_reserve;
        ofstream outdata("E:/C++ PJ/Final Project/Reserving Data.txt");
        int timech[2];
        cout << "This is time table for reserve the table" << endl;
        cout << "Remember! if you're not arrive at canteen on time your reserve will be cancle!" << endl;
        cout << "And when check-out time arrive next students of your table can access the table immedietly!" << endl;
TIME:   for(int i=1;i<=19;i++)
            {
                cout << setw(7) << left << i << ".  " << time_table[i] << endl;
            }
        cout << "choose your check-in time By insert 1-19" << endl;
        cin >> timech[1];
        while(timech[1]<1||timech[1]>19)
            {
                cout << "Please insert correctly! :";
                cin >> timech[1];
            }
        while(time_data[cnum][timech[1]]=0)
            {
                cout << "Sorry But this time was reserve by other please choose new: ";
                cin >> timech[1];
            }
        cout << "next please choose your check-out time (1-19): ";
        cin >> timech[2];
        while(timech[2]<1||timech[2]>19)
            {
                cout << "Please insert correctly! :";
                cin >> timech[2];
            }
        while(time_data[cnum][timech[2]]=0)
            {
                cout << "Sorry But this time was reserve by other please choose new: ";
                cin >> timech[2];
            }
        bool timecheck=0;
        int error;
        for(int i=1;i<=20;i++)
            {
                if(time_data[cnum][i]=1)
                {
                    timecheck=0;            
                    error = i;
                    break;
                }
            }
        if(timecheck=0)
            {
                cout << "Sorry but on this period of time was reserved by someone at" << time_table[error] << "Please choose again:";
                goto TIME;
            }
        if(timecheck=1)
            {
                goto ACCEPT;
            }
ACCEPT: for(int i=timech[1];i<=timech[2];i++)
        {
            time_data[cnum][i]=1;
        }
        cout << cnum << endl;
        cout << name_for_reserve << endl;
    //  outdata << setw(10) << right << "Table" << setw(10) << right << "name" << setw(10) << right << "time" << endl;
        outdata << setw(10) << right << cnum << setw(10) << right << name << setw(10) << right << "time" << setw(10) << "\t" << right << time_table[timech[1]] << " - " << time_table[timech[2]] << endl;
    }



评论