Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- #include <conio.h>
- #include <Windows.h>
- #include <fstream>
- using namespace std;
- class FlyWATFA //Parent class for all our classes used, class is for airline
- {
- private: //used private so variable names/types are not manipulable
- int numberOfPlanes;
- int capacity;
- string startingLocation;
- public: //public to pass to children and main
- FlyWATFA() //default constructor
- {
- numberOfPlanes = 10; //for the purpose of our program this is 10, but can be changed
- capacity = 100; //for the purpose of our program this is 100, but can be changed
- startingLocation = "Dubai, United Arab Emirates"; //all flights start in Dubai
- }
- int getNumberOfPlanes() //returns number of plains when called
- {
- return numberOfPlanes;
- }
- int getCapacity() //returns capacity when called
- {
- return capacity;
- }
- string getStartingLocation() //returns starting location when called
- {
- return startingLocation;
- }
- };
- class Flight : public FlyWATFA //derived of FlyWATFA class, class is for general flight information
- {
- private: //private datafields, used for general flight info
- string destination;
- string flightNumber;
- string flightTime;
- public:
- Flight() //default constructor, all attributes set to not available initially
- {
- destination = "N/A";
- flightNumber = "N/A";
- flightTime = "N/A";
- }
- Flight(string destination, string flightNumber, string flightTime) //constructor for passing arguments
- {
- this->destination = destination; //seting attributes within the class to the passed attributes using pointer.
- this->flightNumber = flightNumber;
- this->flightTime = flightTime;
- }
- string getDestination() //return attribute when called
- {
- return destination;
- }
- void setDestination(string destination) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->destination = destination;
- }
- string getFlightNumber() //return attribute when called
- {
- return flightNumber;
- }
- void setFlightNumber(string flightNumber) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->flightNumber = flightNumber;
- }
- string getFlightTime() //return attribute when called
- {
- return flightTime;
- }
- void setFlightTime(string flightTime) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->flightTime = flightTime;
- }
- string departureT() //function to decide flight time
- {
- int option;
- bool isRepeat = false; //used for repeating loop if user input invalid
- cout << "These are the flight timings - " << endl;
- cout << "1. 09:30 A.M." << endl;
- cout << "2. 03:00 P.M." << endl;
- cout << endl;
- cout << "Enter when you wish to depart: ";
- do {
- cin >> option;
- cout << endl;
- switch (option) //using switch cases to choose time options
- {
- case 1: return "09:30 A.M.";
- case 2: return "03:00 P.M.";
- default:
- cout << "Invalid option. Please Enter a valid number: "; //user validation
- isRepeat = true; //sets repeat to true
- }
- } while (isRepeat == true); //repeats do while loop if condition is met
- }
- string cities() //function for destinations
- {
- int userChoice;
- bool isRepeat = false; //used for user validation, initially set to false
- //displays choice of destinations for user
- cout << "1. New York, United States of America" << endl;
- cout << "2. London, England" << endl;
- cout << "3. Tokyo, Japan" << endl;
- cout << "4. Amsterdam, Netherlands" << endl;
- cout << "5. Madrid, Spain" << endl;
- cout << "6. Rio de Janeiro, Brazil" << endl;
- cout << "7. Milan, Italy" << endl;
- cout << "8. Medellin, Colombia" << endl;
- cout << "9. Toronto, Canada" << endl;
- cout << "10. Manila, Philippines" << endl;
- cout << endl;
- cout << "Enter the number of the destination: ";
- do { //using do while loop for user input validation
- cin >> userChoice;
- cout << endl;
- switch (userChoice) //using swtich for each destination option
- {
- case 1: setFlightNumber("FW001"); //if user chooses this option, sets flight number attribute to what is passed
- return "New York, United States of America"; //returns this desitnation chosen
- case 2: setFlightNumber("FW002");
- return "London, England";
- case 3: setFlightNumber("FW003");
- return "Tokyo, Japan";
- case 4: setFlightNumber("FW004");
- return "Amsterdam, Netherlands";
- case 5: setFlightNumber("FW005");
- return "Madrid, Spain";
- case 6: setFlightNumber("FW006");
- return "Rio de Janeiro, Brazil";
- case 7: setFlightNumber("FW007");
- return "Milan, Italy";
- case 8: setFlightNumber("FW008");
- return "Medellin, Colombia";
- case 9: setFlightNumber("FW009");
- return "Toronto, Canada";
- case 10: setFlightNumber("FW010");
- return "Manila, Philippines";
- default:
- cout << "Invalid option. Please Enter a valid number: "; //default case for invalid option if user doesnt enter correct choice
- isRepeat = true;
- }
- } while (isRepeat == true); //repeats if true
- }
- };
- class Passenger : public Flight //derives from flight class, which derives from flyWatfa
- {
- private: //set to private so the names and datatypes can't be changed
- string name;
- int age;
- string passportNumber;
- string address;
- public: //Public so can be manipulated
- Passenger() //default constructor, attriutes initially set to 0 or not available
- {
- name = "N/A";
- age = 0;
- passportNumber = "N/A";
- address = "N/A";
- }
- string getName() //return attribute when called
- {
- return name;
- }
- void setName(string name) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->name = name;
- }
- int getAge() //return attribute when called
- {
- return age;
- }
- void setAge(int age) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->age = age;
- }
- string getPassportNumber() //return attribute when called
- {
- return passportNumber;
- }
- void setPassportNumber(string passportNumber) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->passportNumber = passportNumber;
- }
- string getAddress() //return attribute when called
- {
- return address;
- }
- void setAddress(string address) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->address = address;
- }
- };
- class Seats : public Passenger
- {
- private:
- string seat;
- int num_firstClass;
- int num_busClass;
- int num_economy;
- int seatNumber;
- public:
- Seats()
- {
- seat = "N/A";
- num_firstClass = 20;
- num_busClass = 10;
- num_economy = 70;
- seatNumber = 0;
- }
- Seats(string seat)
- {
- this->seat = seat;
- }
- string getSeat() //return attribute when called
- {
- return seat;
- }
- void setSeat(string seat) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->seat = seat;
- }
- int getFirstClass() //return attribute when called
- {
- return num_firstClass;
- }
- int getBusClass() //return attribute when called
- {
- return num_busClass;
- }
- int getEconomyClass() //return attribute when called
- {
- return num_economy;
- }
- int getSeatNumber() //return attribute when called
- {
- return seatNumber;
- }
- void setSeatNumber(int seatNumber) //sets the destination by passing argument and using pointer to set related attribute within class to it
- {
- this->seatNumber = seatNumber;
- }
- string seatClass() //function for choosing seating class
- {
- srand(time(NULL)); //seed for random function, based off time
- int userChoice; //user choice variable
- int num_Of_Available_FC_Seats = 20; //number of available seats in first class
- int num_Of_Available_BC_Seats = 10; //number of available seats in buiness class
- int num_Of_Available_EC_Seats = 70; //number of available seats in economy class
- int seatNo; //seat number
- bool isRepeat = false;
- cout << "1. First Class($8000)" << endl;
- cout << "2. Business Class($3000)" << endl;
- cout << "3. Economy Class($1500)" << endl;
- cout << endl;
- cout << "Enter which type of seating you wish to reserve: ";
- do {
- cin >> userChoice;
- cout << endl;
- switch (userChoice)
- {
- case 1:
- seatNo = rand() % (20 + 1 - 1) + 1; //used to randomly choose a seat number for passenger
- setSeatNumber(seatNo); //calls set function passing the randomly generated value
- return "First Class";
- case 2:
- seatNo = rand() % (30 + 1 - 21) + 21; //used to randomly choose a seat number for passenger
- setSeatNumber(seatNo); //calls set function passing the randomly generated value
- return "Business Class";
- case 3:
- seatNo = rand() % (100 + 1 - 31) + 31; //used to randomly choose a seat number for passenger
- setSeatNumber(seatNo); //calls set function passing the randomly generated value
- return "Economy Class";
- default:
- cout << "Invalid option. Please Enter a valid number: ";
- isRepeat = true;
- }
- } while (isRepeat == true);
- }
- };
- class Fees : public Seats //derived from seats and above
- {
- private:
- double airlineFee;
- double mealFee;
- public:
- Fees() //default constructor
- {
- airlineFee = 0;
- mealFee = 0;
- }
- Fees(double airlineFee, double mealFee) //constructor passing values
- {
- this->airlineFee = airlineFee;
- this->mealFee = mealFee;
- }
- double getAirlineFee() //return attribute
- {
- return airlineFee;
- }
- void setAirlineFee(double airlineFee) //set attribute
- {
- this->airlineFee = airlineFee;
- }
- double getMealFee() // return attribute
- {
- return mealFee;
- }
- void setMealFee(double mealFee) //set attribute
- {
- this->mealFee = mealFee;
- }
- double classFee() //function to return class fees
- {
- if (getSeat() == "First Class") //if the seating choice function is first class
- {
- setAirlineFee(8000); //sets the fee to this
- return 8000; //returns the value
- }
- else if (getSeat() == "Business Class")
- {
- setAirlineFee(3000);
- return 3000;
- }
- else if (getSeat() == "Economy Class")
- {
- setAirlineFee(1500);
- return 1500;
- }
- }
- double meals() //meals function
- {
- char choice;
- bool repeat;
- cin >> choice;
- do {
- if (toupper(choice) == 'Y')
- {
- repeat = false;
- setMealFee(20);
- return 20;
- }
- else if (toupper(choice) == 'N')
- {
- repeat = false;
- setMealFee(0);
- return 0;
- }
- else
- {
- repeat = true;
- cout << "Please input a valid option: ";
- cin >> choice;
- }
- } while (repeat == true);
- }
- double totalFees()
- {
- return classFee() + getMealFee();
- }
- };
- class Ticket : public Fees
- {
- public:
- void displayTicket(int t)
- {
- cout << setw(44) << "Here is your itinerary: " << endl << endl;
- cout << setw(45) << "AIRLINE TICKET " << endl;
- cout << "|Ticket No." << t << endl;
- cout << "|_________________________________________________________________________" << endl;
- cout << "|Airline :" << "FlyWATFA" << " " << endl;
- cout << "|_________________________________________________________________________" << endl;
- cout << "|Passenger Information : " << endl;
- cout << "|Name : " << getName() << " " << endl;
- cout << "|Age: " << getAge() << " " << endl;
- cout << "|Address : " << getAddress() << " " << endl;
- cout << "|_________________________________________________________________________" << endl;
- cout << "|Flight Information : " << endl;
- cout << "|Flight No :" << getFlightNumber() << " " << endl;
- cout << "|Seat No :" << getSeatNumber() << " " << endl;
- cout << "|Class:" << getSeat() << " " << endl;
- cout << "| Meal Fees: $ " << getMealFee() << endl;
- cout << "| Airline Fee: $ " << classFee() << endl;
- cout << "| Total Fee: $ " << totalFees() << endl;
- cout << "|_________________________________________________________________________" << endl;
- cout << "|Depart From: " << getStartingLocation() << " at: " << getFlightTime() << " " << endl;
- cout << "|Arrive At: " << getDestination() << " " << endl;
- cout << "|_________________________________________________________________________" << endl << endl << endl;
- }
- void printTicket(int t)
- {
- string fileName = "flight_itinerary_" + to_string(t) + ".txt";
- ofstream outFile;
- outFile.open(fileName);
- outFile << setw(45) << "AIRLINE TICKET " << endl <<
- "|Ticket No." << t << endl <<
- "|_________________________________________________________________________" << endl <<
- "|Airline :" << "FlyWATFA" << " " << endl <<
- "|_________________________________________________________________________" << endl <<
- "|Passenger Information : " << endl <<
- "|Name : " << getName() << " " << endl <<
- "|Age: " << getAge() << " " << endl <<
- "|Address : " << getAddress() << " " << endl <<
- "|_________________________________________________________________________" << endl <<
- "|Flight Information : " << endl <<
- "|Flight No :" << getFlightNumber() << " " << endl <<
- "|Seat No :" << getSeatNumber() << " " << endl <<
- "|Class:" << getSeat() << " " << endl <<
- "| Meal Fees: $ " << getMealFee() << endl <<
- "| Airline Fee:$ " << classFee() << endl <<
- "| Total Fee: $ " << totalFees() << endl <<
- "|_________________________________________________________________________" << endl <<
- "|Depart From: " << getStartingLocation() << " at: " << getFlightTime() << endl <<
- "|Arrive At: " << getDestination() << " " << endl <<
- "|_________________________________________________________________________" << endl;
- outFile.close();
- }
- };
- void displayHeader() //function to display header
- {
- cout << setw(60) << ("**************************************") << endl;
- cout << setw(60) << ("** **") << endl;
- cout << setw(60) << ("** WELCOME TO **") << endl;
- cout << setw(60) << ("** ~ FLYWATFA ~ **") << endl;
- cout << setw(60) << ("** **") << endl;
- cout << setw(60) << ("**************************************") << endl;
- cout << endl;
- }
- bool bookAnotherFlight()
- {
- char choice;
- cout << "Would you like to book another flight? (Press Y or N): ";
- do {
- cin >> choice;
- cin.ignore();
- if (toupper(choice) == 'Y')
- {
- return true;
- }
- else if (toupper(choice) == 'N')
- {
- cout << endl << endl << "THANK YOU FOR FLYING FLYWATFA. HAVE A NICE DAY!" << endl;
- return false;
- }
- else
- {
- cout << "Invalid option. Please enter Y or N only: ";
- }
- } while (toupper(choice) != 'Y' && toupper(choice) != 'N');
- }
- void mainFunc()
- {
- ofstream test("test.txt");
- test << "THIS IA a cggvsgxtest";
- //test.close();
- displayHeader();
- int i = 0;
- int ticketNumber = 0;
- Ticket p[100];
- string passengerName;
- int passengerAge;
- double mealF;
- string passengerPassportNumber, city, timeOfDeparture, seat, homeAddress;
- ofstream registerIDFile;
- ofstream registerPassWFile;
- ifstream registerIDFile_Read;
- ifstream registerPassWFile_Read;
- registerIDFile.open("Usernames.txt");
- registerPassWFile.open("Passwords.txt");
- char choice;
- char registerID[10], registerPassW[10];
- char loginID[10], loginPassW[10];
- int tries = 3;
- cout << "Do you wish to Register? Press (Y/N)." << endl;
- cin >> choice;
- if (choice == 'Y' || choice == 'y')
- {
- cout << "Please register a new username" << endl;
- cin >> registerID;
- registerIDFile << registerID;
- cout << "Please register a new password" << endl;
- cin >> registerPassW;
- registerPassWFile << registerPassW;
- cout << "Thank you for registering with FlyWATFA" << endl << endl;
- registerIDFile.close();
- registerPassWFile.close();
- registerIDFile_Read.open("Usernames.txt");
- registerPassWFile_Read.open("Passwords.txt");
- //if(choice == 'N' || choice == 'n')
- while (tries > 0)
- {
- cout << "Please Login - " << endl << endl;
- cout << "Enter your Username and Password to Login." << endl;
- cout << "Username: ";
- cin >> loginID;
- cout << "Password: ";
- cin >> loginPassW;
- cin.ignore();
- //if(!registerIDFile || !registerPassWFile)
- registerIDFile_Read >> registerID;
- registerPassWFile_Read >> registerPassW;
- if ((!strcmp(registerID, loginID)) && !strcmp(registerPassW, loginPassW))
- {
- tries--;
- cout << "The username or password you entered was invalid. Please try again" << endl;
- system("cls");
- if (tries <= 0)
- {
- cout << "There are no more log in attempts. Please try again after 1 minute." << endl;
- Sleep(1000);
- system("cls");
- tries = 3;
- }
- else
- {
- cout << "that was the correct login." << endl;
- do
- {
- cout << endl;
- cout << "Please enter your full name: ";
- getline(cin, passengerName);
- p[i].setName(passengerName);
- cout << "Please enter your age: ";
- cin >> passengerAge;
- cin.ignore();
- p[i].setAge(passengerAge);
- cout << "Please enter you home address: ";
- getline(cin, homeAddress);
- p[i].setAddress(homeAddress);
- cout << "Please enter your passport number: ";
- cin >> passengerPassportNumber;
- cin.ignore();
- p[i].setPassportNumber(passengerPassportNumber);
- cout << "Please choose your desired destination - " << endl << endl;
- city = p[i].cities();
- p[i].setDestination(city);
- cout << "This flight departs in the morning and in the evening. At what time would you like to depart?" << endl;
- timeOfDeparture = p[i].departureT();
- p[i].setFlightTime(timeOfDeparture);
- cout << "Please choose you desired seating class " << endl;
- seat = p[i].seatClass();
- p[i].setSeat(seat);
- cout << "Would you like an inflight meal? (Y/N): ";
- mealF = p[i].meals();
- p[i].setMealFee(mealF);
- ticketNumber++;
- p[i].displayTicket(ticketNumber);
- p[i].printTicket(ticketNumber);
- i++;
- } while (bookAnotherFlight() == true);
- }
- }
- }
- }
- registerIDFile.close();
- registerPassWFile.close();
- registerIDFile_Read.close();
- registerPassWFile_Read.close();
- }
- /*
- do
- {
- cout << "Please enter your full name: ";
- getline(cin, passengerName);
- p[i].setName(passengerName);
- cout << "Please enter your age: ";
- cin >> passengerAge;
- cin.ignore();
- p[i].setAge(passengerAge);
- cout << "Please enter you home address: ";
- getline(cin, homeAddress);
- p[i].setAddress(homeAddress);
- cout << "Please enter your passport number: ";
- cin >> passengerPassportNumber;
- cin.ignore();
- p[i].setPassportNumber(passengerPassportNumber);
- cout << "Please choose your desired destination - " << endl << endl;
- city = p[i].cities();
- p[i].setDestination(city);
- cout << "This flight departs in the morning and in the evening. At what time would you like to depart?" << endl;
- timeOfDeparture = p[i].departureT();
- p[i].setFlightTime(timeOfDeparture);
- cout << "Please choose you desired seating class " << endl;
- seat = p[i].seatClass();
- p[i].setSeat(seat);
- cout << "Would you like an inflight meal? (Y/N): ";
- mealF = p[i].meals();
- p[i].setMealFee(mealF);
- ticketNumber++;
- p[i].displayTicket(ticketNumber);
- p[i].printTicket(ticketNumber);
- i++;
- } while (bookAnotherFlight() == true);
- */
- int main()
- {
- mainFunc();
- _getch();
- return 0;
- }
- //comments
- //username password
- //header file
- /*
- void login()
- {
- ifstream usernamesFile;
- ifstream passwordsFile;
- usernamesFile.open("Usernames.txt");
- passwordsFile.open("Passwords.txt");
- char choice;
- char registerID[10], registerPassW[10];
- char loginID[10], loginPassW[10];
- int tries = 3;
- cout << "Do you wish to Register? Press (Y/N)." << endl;
- cin >> choice;
- if (choice == 'Y' || choice == 'y')
- {
- cout << "Enter a new username";
- cin >> registerID;
- usernamesFile >> registerID;
- cout << "Enter a new password";
- cin >> registerPassW;
- passwordsFile >> registerPassW;
- }
- //if(choice == 'N' || choice == 'n')
- while (tries)
- {
- cout << "Enter your Username";
- cin >> loginID;
- cout << endl;
- cout<<"Enter Your Password";
- cin >> loginPassW;
- if ((!strcmp(loginID, registerID)) ||!strcmp(loginPassW, registerPassW))
- {
- cout << "that was the correct login." << endl;
- }
- else
- {
- tries--;
- cout << "The username or password you entered was invalid. Please try again" << endl;
- system("cls");
- if (tries <= 0)
- {
- cout << "There are no more log in attempts. Please try again after 1 minute." << endl;
- system("cls");
- Sleep(10);
- tries = 3;
- }
- }
- }
- usernamesFile.close();
- passwordsFile.close();
- }
- /*
- void getLoginInfo()
- {
- {
- FILE *F = fopen(fileName, "r");
- if (F)// 1
- {
- int count = 0;
- while (!feof(F))
- {
- char rawLine[50];
- fscanf(F, "%s", rawLine);// 2
- if (!count++)// 3
- strcpy(id, rawLine);
- else
- strcpy(pass, rawLine);
- }
- }
- else printf("Cannot open this file");
- fclose(F);
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement