// Program Name: ReservationSystem.cpp : Defines the entry point for the console
ID: 3759662 • Letter: #
Question
// Program Name: ReservationSystem.cpp : Defines the entry point for the console application.
// Version: 10.11
// Programmer:
// Class: CIS054 C/C++ Programming
// Date: Nov. 02, 2015
// Input: number of rows, number of seats,seat selection, and user answer (y/n)
// Output: display the # of rows and seats, display a message if all seats are taken,
// and display a dash character '-' when the seat identifier is replaced
#include <iostream>
#include <cctype>
using namespace std;
// Function declarations (prototypes)
char **CreateArrayOfSeats(int NumberOfRows, int SeatsOnRow);
void InitializeSeats(char **ArrayOfSeats, int NumberOfRows, int SeatsOnRow);
void DisplayArrayOfSeats(char **ArrayOfSeats, int NumberOfRows, int SeatsOnRow);
void MemoryCleanup(char **ArrayOfSeats, int NumberOfRows, int SeatsOnRow);
int main(int argc, char* argv[])
{
char **ArrayOfSeats;
int NumberOfRows;
int NumberOfSeats;
char answer; // user input for "Do you want another seat?"
//const char TAKEN = '-'; // seats taken
// get the number of NumberOfRows and SeatsOnRow from the user
cout << "Enter the number of rows: ";
cin >> NumberOfRows;
cout << "Enter the number of seats on each row: ";
cin >> NumberOfSeats;
ArrayOfSeats = CreateArrayOfSeats(NumberOfRows, NumberOfSeats);
InitializeSeats(ArrayOfSeats, NumberOfRows, NumberOfSeats);
DisplayArrayOfSeats(ArrayOfSeats, NumberOfRows, NumberOfSeats);
do
{
int rowSelection; // 1 to max NumberOfRows, input from the user
char seatSelection; // 'A' to max seats, input from the user, convert to a number
int row; // index into ArrayOfSeats, 0 to NumberOfRows-1
int seat; // index into ArrayOfSeats, 0 to seats-1
cout << "Enter a seat selection (example 5F): ";
cin >> rowSelection; // get row from the user
cin >> seatSelection; // get the seat from the user
seatSelection = toupper(seatSelection); // convert to upper case
row = rowSelection - 1; // count from zero to work with the array
seat = seatSelection - 'A'; // convert 'A' to 0, 'B' to 1, 'C' to 23, etc.
// Verify that a valid row and seat were entered
// See if all the seats are taken
// hint, keep a count each time a seat is taken
// and compare to the maximum number of seats (NumberOfRows*seats)
// See if the seat selection is already taken (see if it has an '-')
// if it has an '-', display a message that the seat is taken
// else, put an '-' in that location
DisplayArrayOfSeats(ArrayOfSeats, NumberOfRows, NumberOfSeats);
cout << "Do you want to select another seat (y/n)? ";
cin >> answer;
answer = toupper(answer);
} while (answer == 'Y');
MemoryCleanup (ArrayOfSeats, NumberOfRows, NumberOfSeats); // return the memory that was allocated
cout << "Press the ENTER key to continue...";
char buff[100];
cin.getline (buff, 100);
return 0;
}
char **CreateArrayOfSeats(int NumberOfRows, int SeatsOnRow) // ** means pointer to pointers
{
char **ArrayOfSeats;
ArrayOfSeats = new char*[NumberOfRows]; // create an array of pointers for the NumberOfRows
for(int r = 0; r < NumberOfRows; r++)
ArrayOfSeats[r] = new char[SeatsOnRow]; // create an array of SeatsOnRow for each row
return ArrayOfSeats; // return pointer to the array back to the main program
}
void InitializeSeats(char **ArrayOfSeats, int NumberOfRows, int SeatsOnRow)
{
for (int r = 0; r < NumberOfRows; r++) // initialize the data for each row
{
for (int s = 0; s < SeatsOnRow; s++)
ArrayOfSeats[r][s] = 'A' + s; // put 'A' 'B' 'C' etc in each row
}
}
void DisplayArrayOfSeats(char **ArrayOfSeats, int NumberOfRows, int NumberOfSeats)
{
for (int r = 0; r < NumberOfRows; r++) // for each row
{
cout.width(2);
cout << r+1 << ' '; // Display row numbers starting from 1
for (int s = 0; s < NumberOfSeats; s++)
cout << ArrayOfSeats[r][s] << ' '; // Display info for each seat
cout << endl; // new line after each row
}
}
void MemoryCleanup(char **ArrayOfSeats, int NumberOfRows, int NumberOfSeats)
{
for (int r = 0; r < NumberOfRows; r++)
delete [] ArrayOfSeats[r]; // delete each row of seats individually
delete [] ArrayOfSeats; // delete the row array
}
My question is how to get the
Output: display the # of rows and seats, display a message if all seats are taken,
and display a dash character '-' when the seat identifier is replaced inside the " do Loop " ?
Explanation / Answer
//hope this bit of code will help you
class ResevationSystem
{
static void Main()
{
int seatsFirst, seatsEconomy, reserve, i = 0, j = 6;
//This come sunder the seating chart
bool[] seats = { false, false, false, false, false,false, false, false, false, false };
Console.WriteLine("Welcome to the Reservation System.");
while (true)
{
Console.WriteLine("There are " + checkFirstClass(out seatsFirst, seats) + " first class seats and " + checkEconomy(out seatsEconomy, seats) + " economy seats.");
Console.WriteLine("Please enter 1 to reserve a first class seat or enter 2 to reserve an economy class seat or 0 to exit");
//here we will take the input form the person/user
reserve = Convert.ToInt32(Console.ReadLine());
if (reserve == 1)
{
if (i > 5 || i == 5)
{
//here u can add a dash symbol or anything which you want to display to the user
Console.WriteLine("There are no first class seats available. Would you like to move on to economy class seat? Type 2 for yes and 0 to exit.");
Here the program will go back to first depends on the usr request it will perfom
reserve = Convert.ToInt32(Console.ReadLine());
}
else reserveFirstSeat(ref seats, ref i);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.