Question

The Course Project can be started in Week 7 and is due by 11:59 pm CT Saturday of Week 8. It must follow standard code formatting and have a comment block at the top of the code file with a detailed description of what the program does. Functions must have a comment block with a detailed description of what it does. Pseudocode must be provided in the comment block at the top of the file. This program will allow the user to keep track of airline reservations. The program should display the seating chart for the airplane. It will use an * to indicate a seat is taken and the # to indicate the seat is available. The program will also display a menu which provides the user with several options. There will be two types of seats in the airplane: first class and coach, each of which will have a different cost. The program must make use of files, arrays and functions. The airplane will have 5 rows in the first class section with 4 seats in each row, 2 on each side of the aisle and 10 rows in the coach section with 3 seats on each side of the aisle. The prices for all the first class seats will be the same. The first 5 rows of coach will be more expensive than the last 5 rows. The prices for the seats will be stored in a file called SeatPrices.txt . The program should read these values from the file and store the values in an array of doubles. This is an example of the seating chart: 12 34 Row 1 ## ## Row 2 ## ## Row 3 ## ## Row 4 ## ## Row 5 ## ## 123 456 Row 6 ### ### Row 7 ### ### Etc. The menu will provide choices to reserve a seat(s) and display the total number of seats sold (indicating first class and coach), the total number of seats empty in a row, the total number of seats empty in the plane (indicating first class and coach), and the total amount of sales (in dollars). Validation: The seat requested by the user is a valid row and seat number. The program should also make sure the seat is not already taken. SeatPrices.txt (values in SalesPrices.txt are 324.23, 200.00, 150.23

Week 7 and is due by 11:59 pm CT Saturday of Week 8. It must follow standard code formatting and have a comment block at the

10:12 A 183% first class seats will be the same. The first 5 rows of coach will be more expensive than the last 5 rows. The p

seats sold (indicating first class and coach), the total number of seats empty in a row, the total number of seats empty in t

324.23 200.00 150.23

C++

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

Note: Please save the input SeatPrices.txt file and main.cpp in the same folder. Otherwise, it raises errors.

Program Screenshots: //include required header files #include<iostream> #include<string> #include<stdlib.h> #include<math.h>

cout << Enter 4 to display the total no.of seats empty in the plane. < endl; cout << Enter 5 to display the sales. << end

else if (choice == 6) break; // Implement the method to initialze the seats is empty void initialise_seats) int i, j; for (i

// Implement method to reserve the seat //depend on the user input void reserve_seats () //declare local variables int row, s

if (coach_class[row - 1] [seat - 1] == ) cout << This seat is already taken, try another << endl; else coach_class[row -

for (i = 0; i < 10; i++) for (j = 0; j < 3; j++) if (coach_class[i][j] == *) cout << * << ; total++; //sold seat cout

cout << Total no. of empty seats in row << row « : « total << endl; lse cout << Enter row << endl; cin >> row; if (ro//Display empty void displayempty() //declare local variables int total_seats = 0; int i, j; cout << \nFirst class << endl;

for (i = 0; i<10; i++) cout << ROW « i +1 < ; for (j = 0; j < 3; j++) if (coach_class[i][j] == *) { cout << coach_cla

//Implement the method to compute sales void compute_total_sales() //create file objet to read text file FILE *fp = fopen(Se

for (i = 0; i < 5; i++) for (j = 0; j < 3; j++) if (coach_class[i][j] == *) total += price2;//coach1 seat for (i = 0; i < 5

SampleOutput:

Enter 1 to reserve seat. Enter 2 to display total number of seats sold. Enter 3 to display total number of empty seats in a rEnter 1 to reserve seat. Enter 2 to display total number of seats sold. Enter 3 to display total number of empty seats in a rTotal no. of empty seats in the plane: 48 Enter 1 to reserve seat. Enter 2 to display total number of seats sold. Enter 3 to

Code to be Copied:

//include required header files
#include<iostream>
#include<string>
#include<stdlib.h>
#include<math.h>
using namespace std;
//declare character arrays
char first_class[5][4];
char coach_class[10][3];

//function protypes
void initialise_seats();
void reserve_seats();
void displaysoldseats();
void displayemptyrowseats();
void displayempty();
void compute_total_sales();

//main method
int main()
{
//declare local variable
int choice;
//call the method to intialize the seats is empty
initialise_seats();
//use while loop to read the loop
//until user wants to break from the program.
while (true)
{
  //print the menu
  cout <<"Enter 1 to reserve seat." << endl;
  cout << "Enter 2 to display total number of seats sold." << endl;
  cout << "Enter 3 to display total number of empty seats in a row."
   << endl;
  cout << "Enter 4 to display the total no.of seats empty in the plane."
<< endl;
  cout << "Enter 5 to display the sales." << endl;
  cout << "Enter 6 to break." << endl;
  cout << "\nPlease enter the choice: ";
  cin >> choice;
  
  //If the input choice is 1
  //call the method to reserve the seat
  if (choice == 1)
  {
   reserve_seats();
  }

  //If the input choice is 2
  //call the method to display sold seats
  else if (choice == 2)
  {
   displaysoldseats();
  }

  //If the input choice is 2
  //call the method to display sold seats
  else if (choice == 3)
  {
   displayemptyrowseats();
  }


  //If the input choice is 2
  //call the method to display sold seats
  else if (choice == 4)
  {
   displayempty();
  }
  else if (choice == 5)
  {
   compute_total_sales();
  }
  else if (choice == 6)
  {
   break;
  }
}
}

//Implement the method to initialze the seats is empty
void initialise_seats()
{
int i, j;
for (i = 0; i < 5; i++)
{
  for (j = 0; j < 4; j++)
  {
   first_class[i][j] = '#';
  }
}
for (i = 0; i < 10; i++)
{
  for (j = 0; j < 3; j++)
  {
   coach_class[i][j] = '#';
  }
}
}

//Implement method to reserve the seat
//depend on the user input
void reserve_seats()
{
//declare local variables
int row, seat;
string type;
cout << "Section Type: \nfirst \ncoach\nPlease enter input: ";
cin >> type;
if (type == "first")
{
  cout << "Enter row and seat no: " ;
  cin >> row >> seat;
  if (row < 1 || row >5 || seat < 1 || seat >4)//validate input
  {
   cout << "Invalid seat location" << endl;
  }
  if (first_class[row - 1][seat - 1] == '*')
  {
   cout << "This seat is already taken, try another" << endl;
  }
  else
  {
   first_class[row - 1][seat - 1] = '*';//reserve
  }
}
else
{
  cout << "Enter row and seat no" << endl;
  cin >> row >> seat;
  if (row < 1 || row >10 || seat < 1 || seat >3)
  {
   cout << "Invalid seat location" << endl;
  }
  if (coach_class[row - 1][seat - 1] == '*')
  {
   cout << "This seat is already taken, try another" << endl;
  }
  else
  {
   coach_class[row - 1][seat - 1] = '*';//reserve
  }
}
}

//Implement method to display how many sold seats
void displaysoldseats()
{
int i, j;
int total = 0;
for (i = 0; i < 5; i++)
{
  for (j = 0; j < 4; j++)
  {
   if (first_class[i][j] == '*')
   {
    cout << "*" << " ";
    total++;
   }
   
  }
}
for (i = 0; i < 10; i++)
{
  for (j = 0; j < 3; j++)
  {
   if (coach_class[i][j] == '*')
   {
    cout << "*" << " ";
    total++;//sold seat
   }
  }
}
cout << "Total no. of seats sold: " << total << endl;
}

//Implement method to display empty seats
void displayemptyrowseats()
{
cout << "Which one do you want to know, first or coach?" << endl;
string section; cin >> section; int i, j; int row;
if (section == "first")
{
  cout << "Enter row" << endl; cin >> row;
  if (row < 1 || row > 5)//sold seat
  {
   cout << "Invalid row, please try again" << endl;
  }
  else
  {
   int total = 0;
   for (i = 0; i < 4; i++)
   {
    if (first_class[row - 1][i] == '#')
     total++;//empty seat
   }
   cout << "Total no. of empty seats in row " << row << ": " << total << endl;
  }
}
else
{
  cout << "Enter row" << endl; cin >> row;
  if (row < 1 || row > 10)
  {
   cout << "Invalid row, please try again" << endl;
  }
  else
  {
   int total = 0;
   for (i = 0; i < 3; i++)
   {
    if (coach_class[row - 1][i] == '#') total++;//empty seat
   }
   cout << "\nTotal no. of empty seats in row " << row << ": " << total << endl;
  }
}
}

//Display empty
void displayempty()
{
//declare local variables
int total_seats = 0;
int i, j;
cout << "\nFirst_class" << endl;
for (i = 0; i < 5; i++)
{
  cout << "Row " << i+1<<" ";
  for (j = 0; j < 4; j++)
  {
   if (first_class[i][j] == '#')
   {
    cout << first_class[i][j] << " ";
    total_seats++;//empty seat
   }
   else
   {
    cout << "*" << " ";
   }
   
    
  }
  cout << endl;
}
cout << "\nCoach_class" << endl;
for (i = 0; i < 10; i++)
{
  cout << "Row " << i + 1 << " ";
  for (j = 0; j < 3; j++)
  {
   if (coach_class[i][j] == '#')
   {
    cout << coach_class[i][j] << " ";
    total_seats++;
   }
   else
   {
    cout << "*" << " ";
   }
  
  }
  cout << endl;
}
cout << "\nTotal no. of empty seats in the plane: " << total_seats << endl;
}

//Implement the method to compute sales
void compute_total_sales()
{
//create file objet to read text file
FILE *fp = fopen("SeatPrices.txt", "r");
char prices[3][255];
int i = 0, j;
//read the file and store in the array
while (fgets(prices[i], 255, (FILE*)fp))
{
  i++;
}
//declare the prices
double price1, price2, price3;
//convert string value to double values
price1 = atof(prices[0]);//atof converts char[] to double
price2 = atof(prices[1]);
price3 = atof(prices[2]);
double total = 0;
for (i = 0; i < 5; i++)
{
  for (j = 0; j < 4; j++)
  {
   if (first_class[i][j] == '*')
    total += price1;//first class seat
  }
}
for (i = 0; i < 5; i++)
{
  for (j = 0; j < 3; j++)
  {
   if (coach_class[i][j] == '*')
    total += price2;//coach1 seat
  }
}
for (i = 0; i < 5; i++)
{
  for (j = 0; j < 3; j++)
  {
   if (coach_class[i][j] == '*')
    total += price3;//coach2 seat
  }
}
//print the Total sales
cout << "\nTotal sales: " << total << endl;
}

Add a comment
Know the answer?
Add Answer to:
The Course Project can be started in Week 7 and is due by 11:59 pm CT...
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
  • For c++ Write a program that can be used to assign seats for a commercial airplane....

    For c++ 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 class, and rows 8 rows through 13 are economy class. Your program must prompt the user to enter the following information: Ticket type (first class, business class, or economy class) Desired seat a. b. Output the seating plan in the...

  • In C++. Write a program that can be used to assign seats for a commercial airplane...

    In C++. Write a program that can be used to assign seats for a commercial airplane and print out the ticket total. The airplane has 13 rows, with row 7 being the Emergency Exit row. Each row has 7 seats, there are two seats on each side of the plane and three seats in the middle with aisles on both sides. Rows 1 and 2 are considered first class with tickets for this specific  flight being $872.00 round trip. Rows 3...

  • 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...

  • P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:...

    P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 20 20 30 30...

  • The language is C++ for visual studio express 2013 for windows create a TicketManager class and...

    The language is C++ for visual studio express 2013 for windows create a TicketManager class and a program that uses the class to sell tickets for a performance at a theater. Here are all the specs. This is an intense program, please follow all instructions carefully. -I am only creating the client program that uses the class and all it's functions -The client program is a menu-driven program that provides the user with box office options for a theater and...

  • Write pseudocode for a program where the seating map for a particular performance at a theater...

    Write pseudocode for a program where the seating map for a particular performance at a theater contains 70 rows of 100 seats each. Using an array where applicable, develop the pseudeocode for a program that allows a user to continuously enter each household size and then a) Allows a user to continuously enter a row number and seat number until they enter an appropriate sentinel value for the row number in order to stop entering input. Each time the user...

  • MAKE SURE YOU TEST THE PROGRAM FISRT. DON'T PUT THE CODE WITHOUT TESTING. MAKE SURE ALL...

    MAKE SURE YOU TEST THE PROGRAM FISRT. DON'T PUT THE CODE WITHOUT TESTING. MAKE SURE ALL THE STEPS ARE FOLLOWED IN CORRECT MANNER ONLY USE VISUAL STUDIO C# CONSOLE APPLICATION Use File IO (NO JAVA CODING) Create a C# Console program that will demonstrate the use of File IO, Arrays, and Classes. This assignment has a number of requirements. Carefully read the document and note all the requirements. Also keep in mind that many of the requirements for this assignment...

  • I have to write a C program to assign seats on each flight of the airline’s...

    I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...

  • 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...

  • A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is...

    A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is mapped, row-wise, to a 1D-array of size 28: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Implement a well-structured C program to enable a user to make and cancel seat reservations for the bus. The program uses a text-file seats.txt to store the reservation...

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
Active Questions
ADVERTISEMENT