Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do i add file operations to keep records of the the table numbers and names

ID: 3755312 • Letter: H

Question

How do i add file operations to keep records of the the table numbers and names of people who reserve the tables/private rooms according to days in a week(monday to sunday) ?

Code:

#include<iostream>

#include<string>

using namespace std;

int mainMenu();

int tableMenu();

int privateRoom();

int main()

{

string table[20];

int ch;

int n;

string m

for(int i = 0 ; i < 20 ; i++)

table[i] = "AVAILABLE";

do{

int choice1,choice2,choice3;

bool cont=true;

while(true)

{

cout<<" Main menu "<<endl;

a:

choice1=mainMenu();

switch (choice1)

{

case 1:

cont=true;

while (cont)

{

cout<<" You are in Table reservation menu"<<endl;

choice2=tableMenu();

switch (choice2)

{

case 1:

cout<<" You are in View reservation "<<endl;

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is Available ";  

}

else

{

table[n] = "NOT AVAILABLE";

cout<<"Not available ";

}

break;

case 2:

cout<<" You are in Table reservation menu"<<endl;

cout<<"Enter Which Table You want to reserve: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is AVAILABLE, please enter your name: ";  

cin>>m;

table[n]= m;

}

else

{

cout<<"Table is already reserved ";

}

break;

case 3:

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is Available, nothing to clear ";  

}

else

{

table[n] = "AVAILABLE";

cout<<"Cleared ";

}

break;

case 4:

cout<<" You are in Search for any reservation "<<endl;

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "NOT AVAILABLE")

{

cout<<"Table is Not Available ";  

}

else

{

table[n] = "AVAILABLE";

cout<<"Table is available ";

}

break;

case 5:

cout<<"------------------------------REPORT------------------------------- ";

for(int i = 0 ; i < 20 ; i++)

cout<<"Table "<<i<<" : "<<table[i]<<endl;

break;

case 6:

goto a;

break;

}

}

break;

case 2:

cont=true;

while (cont)

{

cout<<" You are in private room reservation menu"<<endl;

choice2=tableMenu();

switch (choice2)

{

case 1:

cout<<" You are in View reservation "<<endl;

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is Available ";  

}

else

{

table[n] = "NOT AVAILABLE";

cout<<"Not available ";

}

break;

case 2:

cout<<" You are in Table reservation menu"<<endl;

cout<<"Enter Which Table You want to reserve: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is AVAILABLE, please enter your name: ";  

cin>>m;

table[n] = m;

}

else

{

cout<<"Table is already reserved ";

}

break;

case 3:

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "AVAILABLE")

{

cout<<"Table is Available, nothing to clear ";  

}

else

{

table[n] = "AVAILABLE";

cout<<"Cleared ";

}

break;

case 4:

cout<<" You are in Search for any reservation "<<endl;

cout<<"Enter table number: ";

cin>>n;

if(table[n] == "NOT AVAILABLE")

{

cout<<"Table is Not Available ";  

}

else

{

table[n] = "AVAILABLE";

cout<<"Table is available ";

}

break;

case 5:

cout<<"------------------------------REPORT------------------------------- ";

for(int i = 0 ; i < 20 ; i++)

cout<<"Table "<<i<<" : "<<table[i]<<endl;

break;

case 6:

goto a;

break;

}

}

break;

}

}

break;

return 0;

}while(ch!=0);

}

int mainMenu()

{

int cho;

cout<<" 1. Table Reservation."<<endl;

cout<<"2. Private room Reservation."<<endl;

cout<<"3. Exit"<<endl;

cout<<"Make your choice (1 to 3) :";

cin>>cho;

return cho;

}

int tableMenu()

{

int cho;

cout<<" 1. View reservation."<<endl;

cout<<"2. Add reservation."<<endl;

cout<<"3. Cancel reservation."<<endl;

cout<<"4. Search for reservation."<<endl;

cout<<"5. Review reservation."<<endl;

cout<<"6. Back to main menu."<<endl;

cout<<"Make your choice (1 to 6) :";

cin>>cho;

return cho;

}

int privateRoom()

{

int cho;

cout<<" 1. View reservation."<<endl;

cout<<"2. Add reservation."<<endl;

cout<<"3. Cancel reservation."<<endl;

cout<<"4. Search for reservation."<<endl;

cout<<"5. Review reservation."<<endl;

cout<<"6. Back to main menu."<<endl;

cout<<"Make your choice (1 to 6) :";

cin>>cho;

return cho;

}

Explanation / Answer

Using these modules in your code you can save reservation data into file and read and check for availability of reservation requested

*This code enters reservation data in to text file separated by comas

Reserve(int date, string name, string type, int allotted_number)

ofstream fout; // Create Object of Ofstream

fout.open ("reservations.txt",ios::app); // Append mode

if(fout.is_open())

        fout<< d << "," << m << "," << type << "," << number_alloted <<std::endl; //Writing data to file

    cout<<" Reserved";

    fout.close(); // Closing the file

    return 0;

*This code returns reservation data from text file separated by comas

Find_Reserve(int date, int allotted_number)

ifstream fin;

string *line;

char *token ;

fin.open("reservations.txt");

if(fin.is_open())

while(if(line=getline(file,line))

{

while (token != NULL)

    {

If(date== token || allotted_number==token)

Break;

        token = strtok(NULL, " ");

    }

   token== strtok(line, ", ");

if(token

    ++numline;

}   

fin.close();

    return 0;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote