Question

This program is in C++ which reserves flight seats. It uses a file imported to get...

This program is in C++ which reserves flight seats. It uses a file imported to get the seat chart called "chartIn.txt" which looks like this

1 A B C D E F

2 A B C D E F

It continues until row 10.

Sorry unable to provide the chartIn.txt file.

I am having issues with function displaySeats, it displays then but when it comes to 10 the row looks like this 1 0 A B C D E , it shifts everything over and looses F. I believe when entering the seat like 2B it support to be a string not a char and int which I did, maybe that's the problem. In reserveSeats I'm in a loop when they entered the seat correctly or it prints "Your seat was successfully reserved" ten likes or more. In the cancel function I'm not sure how to reassign the seat back after it's been cancelled. And I need some major help in case 5 which is the stats . A file called statistics.txt with the same information is produced. number of available seats, number or reserves seats, percent of seats available and reserved. list of available seats and list of reserved seats is list. Thank you for the help.

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>


const int ROWS = 10; //for rows in airplane
const int COLS = 7;

//protypes for functions
void welcome(); //welcome function
void checkUser(valid_user);
void menu(); //displays options
void Quit();
void help();
void displaySeats(char[][COLS]);
void reserveSeat(char[][COLS]);
void SaveFile(char[][COLS]);
void cancel(char[][COLS]);

int main() {

ifstream eds; //used to write systemUser
ofstream pds; //used to read text


int number=0; //holder variable
string first, last, user, pass;
char seatChar[ROWS][COLS];

int choice; //input from menu
struct valid_user infor[4];
string outFile; //used for name of file from user
welcome();
string inFile;

bool repeat = true; //needed for switch loop

while (repeat = true) {
menu();
cout << "-----------------------" << endl;
cout << "Please enter Your Choice (1-7): " << endl;
cin >> choice;
cout << "----------------------" << endl;

switch (choice) {

case 1:
cout << "Seating chart looks like this:" << endl;
displaySeats(seatChar);
break;

case 2:
reserveSeat(seatChar);
break;


case 3:
cancel(seatChar);
break;

case 4:
SaveFile(seatChar);
break;

case 5:
break;


case 6:

help();
break;

case 7:

repeat = false;
Quit();
break;

default:
cout << "You need to enter a number 1-7" << endl;



}//end of switch


}




eds.close();
pds.close();
system ("pause");

return 0;
}

void welcome() {
cout << "---------------------------------------" << endl;
cout << " WELCOME TO AIR TICKETS SYSTEM " << endl;
cout << "---------------------------------------" << endl;


}

void menu() {

cout << "---------------------------------------" << endl;
cout << " WELCOME TO AIR TICKETS SYSTEM " << endl; //needs to add user first and last name
cout << "---------------------------------------" << endl;
cout << "1. Display Seat Chart" << endl;
cout << "2. Reserve Seat" << endl;
cout << "3. Cancel Reservation" << endl;
cout << "4. Save Seat Chart to File" << endl;
cout << "5. Statistics" << endl;
cout << "6. Help" << endl;
cout << "7. Quit" << endl;


}

void Quit()
{
cout << "Thank You!" << endl;
cout << "Enjoy your Flight" << endl;
system("pause");
exit(0); //Exit the program
}


void help(){
cout << "LOOKS LIKE YOU NEED A LITTLE HELP!!!" << endl;
cout << endl;
cout << "Option 1 Displays the avaible seats " << endl;
cout << "Option 2 Helps you find an avaiable seat to reserve " << endl;
cout << "Option 3 Cancels your reservation " << endl;
cout << "Option 4 Updates the seating chart file " << endl;
cout << "Option 5 Provides all the information about avaiable and reserved seats for flight " << endl;
cout << "Option 6 Brings you back to this screen " << endl;
cout << "Option 7 Quits the program " << endl;
}

void displaySeats(char seats[ROWS][COLS] ) {
ofstream pds;
ifstream eds;
char letters[ROWS] = "ABCDEF";
char letter;

eds.open("chartIn.txt");
if (eds.fail()) {
cout << "Unable to open chartIn.txt" << endl;
cout << "Default to orignal seating chart" << endl;
cout << endl;

cout << "Window" << "\t" << "Center" << "\t" << "Aisle" << "\t" << "Aisle" << "\t" << "Center" << "\t" << "Window" << endl;

for (int i = 0; i < ROWS; i++) {

//trying something from letter
letter = letters[ROWS];
for (int j = 0; j < COLS; j++) {
seats[letter][COLS] = '0';

}

}
}




else {

//FIX ROW TENNNN
cout << "\t\t" << "Window" << "\t" << "Center" << "\t" << "Aisle" << "\t" << "Aisle" << "\t" << "Center" << "\t" << "Window" << endl;
for (int i = 0; i < ROWS; i++) {
cout << "\t";
for (int j = 0; j < COLS; j++) {
if (eds.eof())
break; //ends loop at eof

eds >> seats[i][j];
cout << seats[i][j] << " \t";
if (seats[i][j] == 'F') {
cout << endl;
}
}

}
cout << endl;
}

}

void reserveSeat(char seat[ROWS][COLS]) {
int row;
char col;
cout << "Pleae enter a seat in the form ROW 1-10 and LETTER A-F [example 2B]: " << endl;
cin >> row >> col;
col = toupper(col);

while (((row > ROWS) || (row <= 0)) &&((col != 'A' || 'B'||'C'||'D'||'E'||'F'))) {
cout << "You entered a seat that does not exist!!" << endl;
cout << "Pleae try again" << endl;
cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
cin >> row >> col;
col = toupper(col);

}


//for (int i = 0; i < ROWS; i++) {
//for (int j = 0; j < COLS; j++) {
//if (i == col) {
if (seat[row][col] == 'X') {
do {
cout << "Seat is already taken." << endl;
cout << "Please try again!" << endl;
cout << "Pleae enter a seat in the form ROW 1-10 and LETTER A-F [example 2B]: " << endl;
cin >> row >> col;
col = toupper(col);

//DOUBLE GO OVER THIS WHEN CAN USE A FILE

while (((row > ROWS) || (row <= 0)) && ((col != 'A' || 'B' || 'C' || 'D' || 'E' || 'F'))) {
cout << "You entered a seat that does not exist!!" << endl;
cout << "Pleae try again" << endl;
cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
cin >> row >> col;
col = toupper(col);

}


//repeats until seat is not taken
} while (seat[row][col] != 'X');
}


// }//end of second if
else {
seat[row][col] = 'X';
cout << "Your seat was sucessful reserved!" << endl;
//break;
} //end of else



// }
}


//}//end of function


void SaveFile(char seat[ROWS][COLS]) {
ifstream eds;
ofstream pds;

string outFile; //file name from user

cout << "What is the name of the file you would like to open?" << endl;
cout << "Enter file name: " << endl;
cin >> outFile;

eds.open(outFile.c_str());
pds.open("chartIn.txt");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
pds << seat[i][j];
pds << " ";
if (j = 7) {
pds << endl;
}


}
}



}
//Program/Function Name: Cancel

void cancel(char seat[ROWS][COLS]) {
int row;
char col;

cout << "Sorry to hear you want to cancel your flight" << endl;
cout << "Please enter you seat you'd like to cancel in format, rows 1-10 and column A-F [example 2C]: "<<endl;
cin >> row >> col;
col= toupper(col);

while (((row > ROWS) || (row <= 0)) && ((col != 'A' || 'B' || 'C' || 'D' || 'E' || 'F'))) {

cout << "That seat is not valid!!" << endl;
cout << "Pleae try again" << endl;
cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
cin >> row >> col;
col = toupper(col);


}

if (seat[row][col] != 'X') {
do {
cout << "Error, you entered a seat that has not be reserved yet!" << endl;
cout << "Try again" << endl;
cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
cin >> row >> col;
col = toupper(col);
} while (seat[row][col] != 'X');

//cancelling seat



cout << "You cancelled seat: " << row << col << endl;


}//exit after entering resevered seat


//cancel seat when user typed in correctly
else {



}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

you are storing characters in an array, so it will print single character. Better to take first element as an integer in each line followed by characters. Here it should look like

void displaySeats(char seats[ROWS][COLS] ) {

.

.

int num=0;      
       for (int i = 0; i < ROWS; i++) {
           cout << "\t";
           for (int j = 0; j < COLS; j++) {
               if (eds.eof())
                   break; //ends loop at eof

               if(j==0)
               {
                   eds>>num;
                   cout<<num<<"\t";
               }
               else
               {              
                   eds >> seats[i][j];
                   cout << seats[i][j] << " \t";
               }
               if (seats[i][j] == 'F') {
                   cout << endl;
               }
           }

       }
       cout << endl;

}

********************************

when you run the application the output be like

---------------------------------------
WELCOME TO AIR TICKETS SYSTEM
---------------------------------------
---------------------------------------
WELCOME TO AIR TICKETS SYSTEM
---------------------------------------
1. Display Seat Chart
2. Reserve Seat
3. Cancel Reservation
4. Save Seat Chart to File
5. Statistics
6. Help
7. Quit
-----------------------
Please enter Your Choice (1-7):
1
----------------------
Seating chart looks like this:
       Window   Center   Aisle   Aisle   Center   Window
   1   A    B    C    D    E    F   
   2   A    B    C    D    E    F   
   3   A    B    C    D    E    F   
   4   A    B    C    D    E    F   
   5   A    B    C    D    E    F   
   6   A    B    C    D    E    F   
   7   A    B    C    D    E    F   
   8   A    B    C    D    E    F   
   9   A    B    C    D    E    F   
   10   A    B    C    D    E    F   

---------------------------------------
WELCOME TO AIR TICKETS SYSTEM
---------------------------------------
1. Display Seat Chart
2. Reserve Seat
3. Cancel Reservation
4. Save Seat Chart to File
5. Statistics
6. Help
7. Quit
-----------------------
Please enter Your Choice (1-7):

************************* here is the entire code

#include<iostream>
#include<string>
#include<fstream>
#include<cstdlib>

using namespace std;
const int ROWS = 10; //for rows in airplane
const int COLS = 7;

//protypes for functions
void welcome(); //welcome function
//void checkUser(valid_user);
void menu(); //displays options
void Quit();
void help();
void displaySeats(char[][COLS]);
void reserveSeat(char[][COLS]);
void SaveFile(char[][COLS]);
void cancel(char[][COLS]);

int main()
{

   ifstream eds; //used to write systemUser
   ofstream pds; //used to read text


   int number=0; //holder variable
   string first, last, user, pass;
   char seatChar[ROWS][COLS];

   int choice; //input from menu
//   struct valid_user infor[4];
   string outFile; //used for name of file from user
   welcome();
   string inFile;

   bool repeat = true; //needed for switch loop

   while (repeat = true)
   {
       menu();
       cout << "-----------------------" << endl;
       cout << "Please enter Your Choice (1-7): " << endl;
       cin >> choice;
       cout << "----------------------" << endl;

       switch (choice) {

           case 1:
           cout << "Seating chart looks like this:" << endl;
           displaySeats(seatChar);
           break;

           case 2:
           reserveSeat(seatChar);
           break;


           case 3:
           cancel(seatChar);
           break;

           case 4:
           SaveFile(seatChar);
           break;

           case 5:
           break;


           case 6:

           help();
           break;

           case 7:

           repeat = false;
           Quit();
           break;

           default:
           cout << "You need to enter a number 1-7" << endl;
       }//end of switch


   }

   eds.close();
   pds.close();
   system ("pause");

   return 0;
}

void welcome() {
   cout << "---------------------------------------" << endl;
   cout << " WELCOME TO AIR TICKETS SYSTEM " << endl;
   cout << "---------------------------------------" << endl;
}

void menu() {

   cout << "---------------------------------------" << endl;
   cout << " WELCOME TO AIR TICKETS SYSTEM " << endl; //needs to add user first and last name
   cout << "---------------------------------------" << endl;
   cout << "1. Display Seat Chart" << endl;
   cout << "2. Reserve Seat" << endl;
   cout << "3. Cancel Reservation" << endl;
   cout << "4. Save Seat Chart to File" << endl;
   cout << "5. Statistics" << endl;
   cout << "6. Help" << endl;
   cout << "7. Quit" << endl;
}

void Quit()
{
   cout << "Thank You!" << endl;
   cout << "Enjoy your Flight" << endl;
   system("pause");
   exit(0); //Exit the program
}


void help(){
   cout << "LOOKS LIKE YOU NEED A LITTLE HELP!!!" << endl;
   cout << endl;
   cout << "Option 1 Displays the avaible seats " << endl;
   cout << "Option 2 Helps you find an avaiable seat to reserve " << endl;
   cout << "Option 3 Cancels your reservation " << endl;
   cout << "Option 4 Updates the seating chart file " << endl;
   cout << "Option 5 Provides all the information about avaiable and reserved seats for flight " << endl;
   cout << "Option 6 Brings you back to this screen " << endl;
   cout << "Option 7 Quits the program " << endl;
}

void displaySeats(char seats[ROWS][COLS] ) {
   ofstream pds;
   ifstream eds;
   char letters[ROWS] = "ABCDEF";
   char letter;

   eds.open("chartIn.txt");
   if (eds.fail()) {
       cout << "Unable to open chartIn.txt" << endl;
       cout << "Default to orignal seating chart" << endl;
       cout << endl;

       cout << "Window" << "\t" << "Center" << "\t" << "Aisle" << "\t" << "Aisle" << "\t" << "Center" << "\t" << "Window" << endl;

       for (int i = 0; i < ROWS; i++) {

       //trying something from letter
           letter = letters[ROWS];
           for (int j = 0; j < COLS; j++) {
               seats[letter][COLS] = '0';

           }

       }
   }

   else {

       //FIX ROW TENNNN
       cout << "\t\t" << "Window" << "\t" << "Center" << "\t" << "Aisle" << "\t" << "Aisle" << "\t" << "Center" << "\t" << "Window" << endl;
       int num=0;      
       for (int i = 0; i < ROWS; i++) {
           cout << "\t";
           for (int j = 0; j < COLS; j++) {
               if (eds.eof())
                   break; //ends loop at eof

               if(j==0)
               {
                   eds>>num;
                   cout<<num<<"\t";
               }
               else
               {              
                   eds >> seats[i][j];
                   cout << seats[i][j] << " \t";
               }
               if (seats[i][j] == 'F') {
                   cout << endl;
               }
           }

       }
       cout << endl;
   }

}

void reserveSeat(char seat[ROWS][COLS]) {
   int row;
   char col;
   cout << "Pleae enter a seat in the form ROW 1-10 and LETTER A-F [example 2B]: " << endl;
   cin >> row >> col;
   col = toupper(col);

   while (((row > ROWS) || (row <= 0)) &&((col != 'A' || 'B'||'C'||'D'||'E'||'F'))) {
       cout << "You entered a seat that does not exist!!" << endl;
       cout << "Pleae try again" << endl;
       cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
       cin >> row >> col;
       col = toupper(col);

   }


   //for (int i = 0; i < ROWS; i++) {
   //for (int j = 0; j < COLS; j++) {
   //if (i == col) {
   if (seat[row][col] == 'X') {
       do {
           cout << "Seat is already taken." << endl;
           cout << "Please try again!" << endl;
           cout << "Pleae enter a seat in the form ROW 1-10 and LETTER A-F [example 2B]: " << endl;
           cin >> row >> col;
           col = toupper(col);

           //DOUBLE GO OVER THIS WHEN CAN USE A FILE

           while (((row > ROWS) || (row <= 0)) && ((col != 'A' || 'B' || 'C' || 'D' || 'E' || 'F'))) {
               cout << "You entered a seat that does not exist!!" << endl;
               cout << "Pleae try again" << endl;
               cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
               cin >> row >> col;
               col = toupper(col);

           }


       //repeats until seat is not taken
       } while (seat[row][col] != 'X');
   }


   // }//end of second if
   else {
       seat[row][col] = 'X';
       cout << "Your seat was sucessful reserved!" << endl;
       //break;
   } //end of else

   // }
}


//}//end of function


void SaveFile(char seat[ROWS][COLS]) {
   ifstream eds;
   ofstream pds;

   string outFile; //file name from user

   cout << "What is the name of the file you would like to open?" << endl;
   cout << "Enter file name: " << endl;
   cin >> outFile;

   eds.open(outFile.c_str());
   pds.open("chartIn.txt");
   for (int i = 0; i < ROWS; i++) {
       for (int j = 0; j < COLS; j++) {
           pds << seat[i][j];
           pds << " ";
           if (j = 7) {
               pds << endl;
           }


       }
   }

}
//Program/Function Name: Cancel

void cancel(char seat[ROWS][COLS]) {
   int row;
   char col;

   cout << "Sorry to hear you want to cancel your flight" << endl;
   cout << "Please enter you seat you'd like to cancel in format, rows 1-10 and column A-F [example 2C]: "<<endl;
   cin >> row >> col;
   col= toupper(col);

   while (((row > ROWS) || (row <= 0)) && ((col != 'A' || 'B' || 'C' || 'D' || 'E' || 'F'))) {

       cout << "That seat is not valid!!" << endl;
       cout << "Pleae try again" << endl;
       cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
       cin >> row >> col;
       col = toupper(col);


   }

   if (seat[row][col] != 'X') {
       do {
           cout << "Error, you entered a seat that has not be reserved yet!" << endl;
           cout << "Try again" << endl;
           cout << "Please enter a number 1-10 for the row and a letter A-F for the column: " << endl;
           cin >> row >> col;
           col = toupper(col);
       } while (seat[row][col] != 'X');

   //cancelling seat

   cout << "You cancelled seat: " << row << col << endl;


   }//exit after entering resevered seat


   //cancel seat when user typed in correctly
   else {

   }
}

*******************************chartIn.txt

1 A B C D E F
2 A B C D E F
3 A B C D E F
4 A B C D E F
5 A B C D E F
6 A B C D E F
7 A B C D E F
8 A B C D E F
9 A B C D E F
10 A B C D E F

Add a comment
Know the answer?
Add Answer to:
This program is in C++ which reserves flight seats. It uses a file imported to get...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Program is in C++, program is called airplane reservation. It is suppose to display a screen...

    Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...

  • Can I get help with adding the following to this code please? 1. When buying multiple...

    Can I get help with adding the following to this code please? 1. When buying multiple tickets, if one of the seats selected is already taken, give a message like "Sorry, one or more of the seats selected is already taken." and prompt the user to select the seats all over. (Or if possible to make it suggest a location where the seats are together that the user can select instead) 2. Print the total cost after all of the...

  • Hello, I am working on a project for my C++ class, I have the vast majority...

    Hello, I am working on a project for my C++ class, I have the vast majority of the code figured out but am running into a few issues. Mainly updating each * to an X. The problem is as follows:(Airplane Seating Assignment) Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business...

  • I wrote program that have to block all moves for player 1, for game TicTacTOE AI,...

    I wrote program that have to block all moves for player 1, for game TicTacTOE AI, but it is not working. Can someone check what I have not eliminated? #include using namespace std; const int ROWS = 3; const int COLS = 3; int counter = 0; void aITurn(char b[][COLS]); void fillBoard(char board[ROWS][COLS]); void getChoice(char b[][COLS], bool playerToggle); bool gameOver(char b[][COLS]); void showBoard(char board[ROWS][COLS]); int main() {    ///main is complete, nothing to do here    char board[ROWS][COLS];    bool playerToggle =...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • This is an advanced version of the game tic tac toe, where the player has to...

    This is an advanced version of the game tic tac toe, where the player has to get five in a row to win. The board is a 30 x 20. Add three more functions that will check for a win vertically, diagonally, and backwards diagonally. Add an AI that will play against the player, with random moves. Bound check each move to make sure it is in the array. Use this starter code to complete the assignment in C++. Write...

  • Hello, I am trying to write this program and have received a "Segmentation Fault" error but...

    Hello, I am trying to write this program and have received a "Segmentation Fault" error but cannot seem to figure out where. I haven't been able to find it and have been looking for quite a while. The goal is to basically create a version of Conway's Game of Life. I am able to generate a table if the input values for rows and columns are equal, but if they are not I receive a segmentation fault and cannot continue...

  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<i...

    I just need a help in replacing player 2 and to make it unbeatable here is my code: #include<iostream> using namespace std; const int ROWS=3; const int COLS=3; void fillBoard(char [][3]); void showBoard(char [][3]); void getChoice(char [][3],bool); bool gameOver(char [][3]); int main() { char board[ROWS][COLS]; bool playerToggle=false; fillBoard(board); showBoard(board); while(!gameOver(board)) { getChoice(board,playerToggle); showBoard(board); playerToggle=!playerToggle; } return 1; } void fillBoard(char board[][3]) { for(int i=0;i<ROWS;i++) for(int j=0;j<COLS;j++) board[i][j]='*'; } void showBoard(char board[][3]) { cout<<" 1 2 3"<<endl; for(int i=0;i<ROWS;i++) { cout<<(i+1)<<"...

  • You've been hired by Rugged Robots to complete a C++ console application that controls a robotic...

    You've been hired by Rugged Robots to complete a C++ console application that controls a robotic floor vacuum. Wayne State software engineers have already developed the following three files: File Description Lab20-01-Key.cpp This is the user application. RuggedRobotLibrary.h This is the library header file. It contains constant declarations and function prototypes. It is included by the other two files. RuggedRobotLibrary.cpp This is the library file. It contains functions that may be used in any user application. This is considered an...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT