CAN ANYONE HELP ME WITH THIS PROBLEM? PLEASE WRITE IN C++, each problem need 3 f
ID: 3664972 • Letter: C
Question
CAN ANYONE HELP ME WITH THIS PROBLEM? PLEASE WRITE IN C++, each problem need 3 files. a header, a main, and function.
And also write comments to tell me what is what. Thank you very much.
Q3. (20 marks) Create a class called Flight that represents flight information of an airline company. The flight has the following attributes:
-Flight Number (e.g., AC300)
-Departure Time (Object of Class Time of Q1)
-Departure Date (Object of Class Date of Q2)
-Departure City (e.g., Montreal)
-Destination City (e.g., New York)
The class should have the following member functions,
- One or multiple constructors
- A copy constructor
- A function that prints out information about a flight
- Accessing functions
- A destructor
Create a driver to test the class. Submit the files: flight.h , flight.cpp, flighttest.cpp.
Q4. (20 marks) Create a class called Passenger that represents information of the passengers of the airline company. A passenger has the following attributes:
- Passenger Passport Number (e.g., AF300DE4)
- First Name (e.g., Eric)
- Last Name (e.g., Smith)
- Address Street (e.g., 105 Sherbrook Street)
- Telephone Number (e.g., 514
- 765
- 7676)
The class should have the following member functions:
- One or multiple constructors
- A copy constructor
- A function that prints out information about a passenger
- Accessing functions
- A destructor
Create a driver to test the class. Submit the files: passenger.h, passenger.cpp, passengertest.cpp.
Q5. (30 marks) We want to be able to book passengers on flights. Which modifications to the Passenger and Flight classes you need to make? Implement the changes. Submit the new classes and source code because each question has its own mark.
Use code comments to your program in the source code to explain your solutions.
Explanation / Answer
I have bigger scenario than this. Iam posting it here. Iam unable to post entire cpp files code. Please let me know which scenarios you need so that i can add.
#include <iostream>
#include <string>
#include "airline.h"
#include "utility/client/validity.h"
using namespace std;
void divider();
void welcomeMessage();
void divider()
{
cout << "--------------------------------------------------------------------------- ";
}
void welcomeMessage() // Welcome message
{
cout << "CS 3528: Data Structures and Algorithms "
<< "Fall 2015 "
<< "Program4/Final Group Project "
<< "(Bemidji State University) "
<< "Author: Yohannes Seifu "
<< " Teik (Silvester) ";
}
int main()
{
// classes objects
Airline airline;
Fleet fleet;
PassengerSCH passengers;
FlightSchedule schedule;
Validity validity;
int choice;
divider();
welcomeMessage();
divider();
cout << "--------------------------------------WELCOME---------------------------- ";
// User option to pick from
cout<< "1) add new plane" << endl;
cout<< "2) add new passenger to a Flight" << endl;
cout<< "3) add new passenger to a list" << endl;
cout<< "4) add new flight" << endl;
cout<< "5) transferPassengers " << endl;
cout<< "6) Display passengers " << endl;
cout<< "7) Display upcoming flights " << endl;
cout<< "8) Exit " << endl;
cout << "* Select one of your desirable option" << endl;
cout << "* Enter either from 1 to 8 " << endl;
divider();
cout << " >> ";
cin >> choice; // User input for the selection choice
if(validity.choiceValid(choice) == false)
{
cout << "You have entered an invalid choice! Please try again! ";
}
if(validity.choiceValid(choice) == true)
{
if (choice == 1) // If the user picked to add new plane
{
divider();
int column;
int numberOfFirstClassRows;
int numberOfEconomyClassRows;
int numberOfEconomyPlusRows;
cout << "You have selected to add new plane! ";
cout << "Please enter the number of column! >>";
cin >> column;
if(cin)
{
//If format is correct , do nothing
}
else
{
divider();
cout << "Wrong input column format! Please try again! "; // if format is wrong, prompt error message
exit(0);
}
cout << "Please enter the number of rows for first class >>";
cin >> numberOfFirstClassRows;
if(cin)
{
//If format is correct , do nothing
}
else
{
divider();
cout << "Wrong input number of rows for first class format! Please try again! ";
exit(0);
}
cout << "Please enter the number of rows for economy class >>";
cin >> numberOfEconomyClassRows;
if(cin)
{
//If format is correct , do nothing
}
else
{
divider();
cout << "Wrong input number of rows for economy class format! Please try again! ";
exit(0);
}
cout << "Please enter the number of rows for economy plus class >>";
cin >> numberOfEconomyPlusRows;
if(cin)
{
//If format is correct , do nothing
}
else
{
divider();
cout << "Wrong input number of rows for economy plus format! Please try again! ";
exit(0);
}
divider();
cout << "You have entered the following inputs for your new plane: ";
cout << "column = " << column << " ";
cout << "first class rows = " << numberOfFirstClassRows << " ";
cout << "economy class rows = " << numberOfEconomyClassRows << " ";
cout << "econom plus rows = " << numberOfEconomyPlusRows << " ";
airline.addNewPlane(column,numberOfFirstClassRows,numberOfEconomyClassRows,numberOfEconomyPlusRows);//Creates the new plane with their specific number of seats
cout << "Your new plane has been created! ";
}
if (choice == 2)// If the user picked to add new passenger into flight
{
bool checkInput;
checkInput = true;
int flightNumber;
int passengerId;
string firstName;
string lastName;
string seatNumber;
cout << "You have selected to add new passenger to a flight ! ";
cout << "Please enter the flight number to add the new passenger in >>";
cin >> flightNumber; //Receive user input for flight number
if(cin){
//If format is correct , do nothing
}
else{
divider();
cout << "You have entered an invalid flight number format! Please try again! ";
exit(0);
}
cout << "Please enter the passenger ID to add in new flight >>";
cin >> passengerId; // Receive user input for passenger id
if(cin){
//If format is correct , do nothing
}
else{
divider();
cout << "You have entered an invalid flight number format! Please try again! ";
exit(0);
}
cout << "Please enter the seat number (For example: 4A) >>";
cin >> seatNumber;// Receive the user input for seat number
cout << "Please enter the passenger first name without spaces in between >>";
cin >> firstName; // Receive user input for first name
if(cin){
//If format is correct , do nothing
}
else{
divider();
cout << "You have entered an invalid first name format! Please try again! ";
exit(0);
}
if (validity.stringValid(firstName) == false) // checks if user entered the correct name format .
{
divider();
cout << "You have entered an invalid first name format! Please try again! ";
exit(0);
}
else
{
cout << "Please enter the passenger last name without spaces in between >>";
cin >> lastName;
if(cin){
//If correct, do nothing
}
else
{
cout << "You have entered an invalid last name format! Please try again! ";
exit(0);
}
if(validity.stringValid(lastName) == false )// checks if user entered the correct name format .
{
cout << "You have entered an invalid last name format! Please try again! ";
}
}
if(validity.stringValid(firstName) == true && validity.stringValid(lastName) == true)// If format conditions are met
{
divider();
//Prints out the user input
cout << " You have entered the following inputs to add your new passenger to a flight ! ";
cout << "flight Number = " << flightNumber << " ";
cout << "passengerId = " << passengerId << " ";
cout << "first name = " << firstName << " ";
cout << "last name = " << lastName << " ";
cout << "seat number =" << seatNumber << " ";
airline.addNewPassengerToFlight(flightNumber,passengerId,firstName,lastName, seatNumber);
}
else
{
cout << "You have entered some incorrect format! Please try again!";
}
}
}
if(choice == 3) // if the user pick to add passenger to a list
{
string firstName;
string lastName;
cout << " You have selected to add passenger to a list! ";
cout << " Please enter the passenger first name >>";
cin >> firstName; // Receive user input for first name
validity.stringValid(firstName); // validates the user input first name
cout << " Please enter the passenger last name >>"; // validates the user input last name
cin >> lastName;
validity.stringValid(lastName);
if(validity.stringValid(firstName) == true && validity.stringValid(lastName) == true)
{
divider();
cout << " You have entered the following inputs to add a new passenger to a list ! ";
cout << "first name : " << firstName << " ";
cout << "last name: " << lastName << " ";
airline.addNewPassengerToList(firstName, lastName); // adds the user input for new passenger into the list
}
else
{
cout << "You have entered an invalid input or wrong format! Please try again!";
}
}
if (choice == 4 ) // if the user select to add new flight
{
string origin;
string destination;
string departureDate;
string departureTime;
string returnDate;
string returnTime;
string stringMonth;
string stringDay;
string stringMinute;
string stringHour;
string stringReturnHour;
string stringReturnMinute;
string stringReturnMonth;
string stringReturnDay;
int planeId;
int month;
int day;
int year;
int returnMonth;
int returnDay;
int returnYear;
int returnHour;
int returnMinute;
int hour;
int minute;
cout << " You have selected to add new flight ! ";
cout << "Please enter the plane id to add the new flight ! >>";
cin >> planeId;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format for plane id! Please try again! ";
exit(0);
}
cout << "Please enter the origin >>";
cin >> origin;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format! for origin Please try again! ";
exit(0);
}
cout << "Please enter the destination >>";
cin >> destination;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format for destination! Please try again! ";
exit(0);
}
cout << "Please enter the departure month (0-12) >>";
cin >> month;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format for departure month! Please try again! ";
exit(0);
}
cout << "Please enter the departure day (1-30) >>";
cin >> day;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format for departure day! Please try again! ";
exit(0);
}
cout << "Please enter the departure year (xxxx) >>";
cin >> year;
if(cin){
//If user input correct, do nothing
}
else
{
divider();
cout << "Wrong input format for departure year! Please try again! ";
exit(0);
}
validity.dateValid(month,day,year); // validates the user input for date, month and year.
if(validity.dateValid(month,day,year) == false) // checks the condition of user input and convert the month and year format to appropriate format
{
if (month < 10 && day < 10)
{
stringMonth = "0" + to_string(month);
stringDay = "0" + to_string(day);
departureDate = stringMonth + "/" + stringDay + "/" + to_string(year); // if month and day is less than 10, then add a 0 in front
}
else if( month < 10 && day > 10)
{
stringMonth = "0" + to_string(month);
departureDate = stringMonth + "/" + to_string(day) + "/" + to_string(year); // if month is less than 10, add a 0 infront
}
else if (month > 10 && day < 10)
{
stringDay = "0" + to_string(day);
departureDate = to_string(month) + "/" + stringDay + "/" + to_string(year);// if day is less than 10, add a 0 infront
}
else if (month > 9 && day > 9) // if month and day is more than 9
{
departureDate = to_string(month) + "/" + to_string(day) + "/"+ to_string(year);
}
cout << "Please enter the departure hour (0-23) >>";
cin >> hour;
cout << "Please enter the departure minute (0-59) >>";
cin >> minute;
validity.timeValid(hour, minute); // validates the hour and time in 24 hour format and 60 minute format
if(validity.timeValid(hour,minute) == false)
{
if (hour < 10 && minute > 9)
{
stringHour = "0" + to_string(hour);
departureTime = stringHour + ":" + to_string(minute); // if hour is less than 10, add a 0 infront
}
else if (hour > 9 && minute < 10)
{
stringMinute = "0" + to_string(minute);
departureTime = to_string(hour) + ":" + stringMinute; // if minute is less than 10, add a 0 infront
}
else if (hour < 10 && minute < 10) // if hour and mintue is less than 10, add a 0 infront for both of them
{
stringHour = "0" + to_string(hour);
stringMinute = "0" + to_string(minute);
departureTime = stringHour + ":" + stringMinute;
}
else if (hour > 9 && minute > 9) // if hour and minute is more than 9, just assign them to departureTime string.
{
departureTime = to_string(hour) + ":" + to_string(minute);
}
cout << "Please enter the return month (1-12) >>";
cin >> returnMonth;
cout << "Please enter the return day (1-30) >>";
cin >> returnDay;
cout << "Please enter the return year (xxxx > 2015) >>";
cin >> returnYear;
validity.returnDateValid(month,day,year,returnMonth,returnDay,returnYear);// validates the return month,day and year
if (validity.returnDateValid(month,day,year,returnMonth,returnDay,returnYear) == false)
{
if (returnMonth > 9 && returnDay > 9)
{
returnDate = to_string(returnMonth) + "/" + to_string(returnDay) + "/" + to_string(returnYear);
}
else if (returnMonth < 10 && returnDay < 10)
{
stringReturnMonth = "0" + to_string(returnMonth);
stringReturnDay = "0" + to_string(returnDay);
returnDate = stringReturnMonth + "/" + stringReturnDay + "/"+ to_string(returnYear);
}
else if (returnMonth < 10 && returnDay > 9)
{
stringReturnMonth = "0" + to_string(returnMonth);
returnDate = stringReturnMonth + "/" + to_string(returnDay) + to_string(returnYear);
}
else if (returnMonth > 9 && returnDay < 10)
{
stringReturnDay = "0" + to_string(returnDay);
returnDate = to_string(returnMonth) + "/" + stringReturnDay + "/" + to_string(returnYear);
}
cout << "Please enter the return hour (0-24) >>";
cin >> returnHour ;
cout << "Please enter the return minute (0-59) >>";
cin >> returnMinute;
validity.timeValid(returnHour,returnMinute); //validates the time format (24 hour and 60 minute)
validity.returnTimeValid(hour,minute,returnHour,returnMinute); //validates the return time format with departure time.
if( validity.returnTimeValid(hour,minute,returnHour,returnMinute) == true )// if validation is true, convert them to their appropriate format
{
if(returnHour > 9 && returnMinute > 9) // if return hour and return minute is more than 9, just assign it to return time
{
returnTime = to_string(returnHour) + ":" + to_string(returnMinute);
}
else if(returnHour < 10 && returnMinute < 10) // if return hour and return minute is less than 10, add a zero in front
{
stringReturnMinute = "0" + to_string(returnMinute);
stringReturnHour = "0" + to_string(returnHour);
returnTime = stringReturnHour + ":"+ stringReturnMinute;
}
else if (returnHour < 10 && returnMinute > 9) // if return hour is less than 10, add a 0 in front.
{
stringReturnHour = "0" + to_string(returnHour);
returnTime = stringReturnHour + ":" + to_string(returnMinute);
}
else if (returnHour > 9 && returnMinute < 10) //if return minute is less than 10, add a 0 in front
{
stringReturnMinute = "0" + to_string(returnMinute);
returnTime = to_string(returnHour) + ":" + stringReturnMinute;
}
cout << " You have entered the following inputs to add new flight ! ";// prints the user input
cout << "Plane id = " <<planeId << endl;
cout << "Origin = " << origin << endl;
cout << "Destination = " << destination<< endl;
cout << "Departure date = " << departureDate << endl;
cout << "Departure Time = " << departureTime << endl;
cout << "Return date = " <<returnDate << endl;
cout << "Return time = " << returnTime << endl;
//Adds the user input into the addNewFlight method to add a new flight.
airline.addNewFlight(planeId, origin, destination, departureDate, departureTime,returnDate,returnTime);
}
}
}
}
}
if(choice ==5) // if user select to transfer passengers!
{
int flightNumber;
int currentPlaneId;
int newPlaneId;
divider();
cout << " You have selected to transfer passengers! ";
cout << "Enter the flight number >>";
cin >> flightNumber;
if (cin)
{
// if correct, do anothing
}
else
{
cout << "You have entered the wrong flight number input format! Please try again! ";
exit(0);
}
cout << "Enter the current plane id you wish to transfer! >>";
cin >> currentPlaneId;
if (cin)
{
// if correct, do anothing
}
else
{
cout << "You have entered the wrong plane id input format! Please try again! ";
exit(0);
}
cout << "Enter the new plane id you wish to transfer! >>";
cin >> newPlaneId;
if (cin)
{
// if correct, do anothing
}
else
{
cout << "You have entered the wrong plane id number input format! Please try again! ";
exit(0);
}
cout << " You have entered the following inputs to transfer passengers! ";
cout << " flight number = " << flightNumber << endl;
cout << " current plane id = " << currentPlaneId << endl;
cout << " new plane id = " << newPlaneId << endl;
airline.transferPassengers(flightNumber,currentPlaneId,newPlaneId); // validates the transfered passengers
}
if (choice == 6) // if user select to display the passengers on that flight
{
int flightNumber;
cout << " You have selected to display the passengers ! ";
cout << " Enter the flight number to view the passengers >>";
cin >> flightNumber;
cout << " You have selected to view flight " << flightNumber << " passengers " ;
airline.displayPassengers(flightNumber);
divider();
}
if(choice == 7) // if the user select to view the upcoming flights
{
cout << " You have selected to view the upcoming flights!! ";
airline.displayUpcomingFlights();
}
if(choice == 8)// if the user select to exit the program
{
divider();
cout << " You have selected to exit the program!! THANK YOU FOR USING! ";
divider();
exit(0);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.