Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Programming Language to be used is C++ Last components that I am trying to figure out is how to use this program with user input,

Programming Language to be used is C++

Last components that I am trying to figure out is how to use this program with user input, being able to update constantly, read and write to a txt file and a graphical representation of the seating arrangement.

#include #include #include using namespace std; // Passenger class class Passenger { private: string name; string frequentFlyerNumber; public: Passenger (string n, string ff) { name = n; frequentFlyerNumber = ff; } string getName () { return name; } string getFrequentFlyerNumber () { return frequentFlyerNumber; } };

// Plane class class Plane { private: int availableSeats[5]; string frequentFlyerNumbers[4]; public: Plane () { for (int i = 0; i < 6; i++) { availableSeats[i] = 1; } } int *getAvailableSeats () { return availableSeats; } string *getFrequentFlyerNumbers () { return frequentFlyerNumbers; } void bookSeat (int seatNumber, string ffNumber) { availableSeats[seatNumber] = 0; frequentFlyerNumbers[seatNumber] = ffNumber; } };

// Reservation class class Reservation { private: int reservationNumber; int flightNumber; string date; int seatNumber; string frequentFlyerNumber; public: Reservation (int rn, int fn, string d, int sn, string ff) { reservationNumber = rn; flightNumber = fn; date = d; seatNumber = sn; frequentFlyerNumber = ff; } int getReservationNumber () { return reservationNumber; } int getFlightNumber () { return flightNumber; } string getDate () { return date; } int getSeatNumber () { return seatNumber; } string getFrequentFlyerNumber () { return frequentFlyerNumber; } };

// Flight class class Flight { private: string origin; string destination; int flightNumber; public: Flight (string o, string d, int fn) { origin = o; destination = d; flightNumber = fn; } string getOrigin () { return origin; } string getDestination () { return destination; } int getFlightNumber () { return flightNumber; } };

// Schedule class class Schedule { private: string date; string departureTime; string arrivalTime; string origin; string destination; int flightNumber; string status; public: Schedule (string d, string dt, string at, string ds, string o, int fn, string s) { date = d; departureTime = dt; arrivalTime = at; origin = o; destination = ds; flightNumber = fn; status = s; } string getDate () { return date; } string getDepartureTime () { return departureTime; } string getArrivalTime () { return arrivalTime; } string getOrigin () { return origin; } string getDestination () { return destination; } int getFlightNumber () { return flightNumber; } string getStatus () { return status; } void setStatus (string s) { status = s; } };

// Function to create a one-way or round-trip reservation void createReservation (Flight * flight, Schedule * schedule, Plane * plane, Passenger * passenger) { // Check if there are available seats if (!plane->getAvailableSeats ()[1]) { cout << "Sorry, no available seats!" << endl; return; } // Generate a random reservation number int reservationNumber = rand () % 100000000; // Find an available seat int seatNumber; for (int i = 1; i <= 5; i++) { if (plane->getAvailableSeats ()[i]) { seatNumber = i; break; } } // Create a new reservation Reservation *reservation = new Reservation (reservationNumber, flight->getFlightNumber (), schedule->getDate (), seatNumber, passenger->getFrequentFlyerNumber ()); // Book the seat plane->bookSeat (seatNumber, passenger->getFrequentFlyerNumber ()); // Print the reservation information cout << "Reservation created!" << endl; cout << "Reservation number: " << reservation-> getReservationNumber () << endl; cout << "Flight number: " << reservation->getFlightNumber () << endl; cout << "Date: " << reservation->getDate () << endl; cout << "Seat number: " << reservation->getSeatNumber () << endl; cout << "Frequent flyer number: " << reservation-> getFrequentFlyerNumber () << endl; }

// Function to cancel a reservation void cancelReservation (int reservationNumber, Plane * plane) { // Read the reservations from file ifstream fin; fin.open ("reservations.txt"); string line; while (getline (fin, line)) { // Split the line into tokens string tokens[7]; int tokenIndex = 0; string token = ""; for (int i = 0; i < line.length (); i++) { if (line[i] == ',') { tokens[tokenIndex] = token; tokenIndex++; token = ""; } else { token += line[i]; } } tokens[tokenIndex] = token; // Get the reservation number int rn = stoi (tokens[0]); // If the reservation number matches, cancel the reservation if (rn == reservationNumber) { int seatNumber = stoi (tokens[3]); plane->getAvailableSeats ()[seatNumber] = 1; plane->getFrequentFlyerNumbers ()[seatNumber] = ""; cout << "Reservation cancelled!" << endl; } } fin.close (); }

// Function to check flight status void checkFlightStatus (Flight * flight, Schedule * schedule) { cout << "Flight status:" << endl; cout << "Flight number: " << flight->getFlightNumber () << endl; cout << "Origin: " << flight->getOrigin () << endl; cout << "Destination: " << flight->getDestination () << endl; cout << "Date: " << schedule->getDate () << endl; cout << "Departure time: " << schedule->getDepartureTime () << endl; cout << "Arrival time: " << schedule->getArrivalTime () << endl; cout << "Status: " << schedule->getStatus () << endl; }

int main () { Flight *flight = new Flight ("KPNE", "KMIA", 1234); Schedule *schedule = new Schedule ("01/01/2020", "07:00", "09:00", "KPNE", "KMIA", 1234, "On Time"); Plane *plane = new Plane (); int c; cout << "Welcome to Legacy Aviation Terminal Please look carefully at our following menu options "; cout << "Are you new costumer or an existing costumer? (1 for new / 2 for existing): "; cin >> c; if (c==1) { int m; cout << "Welcome new costumer "; cout << "What would you like to do? "; cout << "1. Create a new reservation "; cout << "2. Check plane ticket prices and availability "; cout << "3. Cancel an exisiting reservation "; cout << "4. Check flight status "; cin >> m; switch (m) { case 1: int h; cout << "Is this a one way trip or a round trip (1 for one way trip / 2 for round trip): "; cin >> h; switch (h) { case 1: //string name; cout << "Creating new reservation for a one way trip "; cout << "What is your name? "; break; case 2: cout << "Creating a new reservation for a round trip "; break; } break; case 2: checkFlightStatus (flight, schedule); cout << "Tickets for a round trip are 300 "; cout <<"Tickets for a one way trip are 200 "; *getAvailableSeats (); break; case 3: cout << "Checking seating arrangments "; break; case 4: cout << "Checking flight status... "; break; } } if (c==2) { cout << "Welcome back! "; } else { cout << "Please enter a valid number "; } main();

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions