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

North Country Train company runs a daily train service between Albany and Chicag

ID: 3907445 • Letter: N

Question

North Country Train company runs a daily train service between Albany and Chicago. The train has 80 seats. Price per seat (one-way) is $49.99. Each day the following program is executed:

The daily program performs the following:
- prints a greeting to the user (the person in charge of selling the tickets for the day)
- asks person in charge of selling the tickets for number of tickets the customer would like to purchase
- Checks if there are remaining seats.
- If so, generates a unique 5 digit code per ticket sold and write the codes to a text file, one code per line (you should name this file ticket.txt)
- The program should output the total price of the ticket(s) sold and the code(s) for each ticket purchased.
- After completing a transaction (purchase), the program should ask if the person in charge of selling the tickets would like to continue ticket sales or quit (if you use a text input, make sure to accept both lower and upper case). The program will run until the person in charge of selling the tickets asks to quit or until all 80 tickets are sold.

Explanation / Answer

#include<iostream>
#include<string>
#include<stdlib.h>
#include<time.h>
#include<fstream>

using namespace std;

int main(){

   cout << "------Welcome to Ticket Counter------- ";
   double sum = 0;
   srand(time(NULL));
   ofstream fout("ticket.txt");
   int count = 0;
   while(true){
     cout << "Number of tickets:";
     int n;
     cin >> n;
     if (count == 80)
        break;
     if ((count + n) <= 80){
        count = count + n;
        int code = rand() % 1000 + 10000;
        sum = sum + n*49.99;
        fout << code << endl;
     }
     else {
         cout << "Seats not available ";
         cout << "Available Seats:" << (80 - count) << endl;
     }
    
    
     cout << "Selling more tickets(y/n)? :";
     string ch;
     cin >> ch;
     if (ch == "n" || ch == "N")
         break;
   }
   cout << "Total Purchase: $" << sum << endl;
   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