Expand|Select|Wrap|Line Numbers
- #include<string.h>
- #include<iomanip>
- #include<iostream>
- #include<vector>
- #include<list>
- using namespace std;
- // Movie Class
- class Movie{
- private:
- int movieNum;
- char * Title;
- public:
- Movie();
- Movie(char * inTitle);
- void setMovieNum();
- void setTitle(char *inTitle);
- int getMovieNo();
- char* getMovieTitle();
- };
- // getters and setters
- Movie::Movie(){
- setMovieNum();
- char setTitle1[]="Untitled";
- setTitle(setTitle1);
- }
- Movie::Movie(char *inTitle){
- setMovieNum();
- setTitle(inTitle);
- }
- void Movie::setMovieNum(){
- static int MovieCount =0;
- MovieCount++;
- movieNum = MovieCount;
- }
- void Movie::setTitle(char *inTitle){
- Title = inTitle;
- }
- int Movie::getMovieNo(){
- return movieNum;
- }
- char* Movie::getMovieTitle(){
- return Title ;
- }
- // Passenger Class
- class Passenger{
- private:
- int bookingRefNo;
- char name[50];
- int numAdult;
- int numChildren;
- int numFlights;
- double totalPrice;
- public:
- Passenger();
- //Getters and Setters
- void setBookingRef();
- void setName(char inName[50]);
- void setNumAdult(int noAdult);
- void setNumChildren(int noChild);
- void setNumFlight(int noFlight);
- void setTotalPrice(double inTotalPrice);
- int getBookingRef();
- char * getName();
- int getNumAdult();
- int getNumChildren();
- int getNumFlight();
- double getTotalPrice();
- };
- //setter methods
- Passenger::Passenger(){
- setBookingRef();
- }
- void Passenger::setBookingRef(){
- static int count=500;
- count++;
- bookingRefNo=count;
- }
- void Passenger::setName(char inName[50]){
- strcpy(name,inName);
- }
- void Passenger::setNumAdult(int noAdult){
- numAdult = noAdult;
- }
- void Passenger::setNumChildren(int noChild){
- numChildren = noChild;
- }
- void Passenger::setNumFlight(int noFlight){
- numFlights = noFlight;
- }
- void Passenger::setTotalPrice(double inTotalPrice){
- totalPrice = inTotalPrice;
- }
- //getter methods
- int Passenger::getBookingRef(){
- return bookingRefNo;
- }
- char* Passenger::getName(){
- return name;
- }
- int Passenger::getNumAdult(){
- return numAdult;
- }
- int Passenger::getNumChildren(){
- return numChildren;
- }
- int Passenger::getNumFlight(){
- return numFlights;
- }
- double Passenger::getTotalPrice(){
- return totalPrice;
- }
- // Fligh Class
- class Flight{
- private:
- int flightNo;
- char orgin[50];
- char destination[50];
- char date[50];
- char deparR[50];
- double price;
- int childPerc;
- vector<Movie> movieList;
- public:
- Flight();
- Flight(char InOrgin[50], char InDesi[50], char InDate[50], char InDeparr[50], double inPrice, int ChildPerc);
- void SetflightNo();
- void SetOrgin(char InOrgin[50]);
- void SetDesti(char InDesti[50]);
- void SetDate(char InDate[50]);
- void SetDeparr(char InDeparr[50]);
- void SetPrice(double InPrice);
- void SetChildPerc(int InChildPerc);
- int GetflightNo();
- char* GetOrgin();
- char* GetDesti();
- char* GetDate();
- char* GetDeparr();
- double GetPrice();
- int GetChildPerc();
- void addMovie(Movie objMov);
- };
- Flight::Flight(){
- SetflightNo();
- char SetOrgin1[]="null";
- SetOrgin(SetOrgin1);
- char SetDesti1[]="null";
- SetDesti(SetDesti1);
- char SetDeparr1[]="null";
- SetDeparr(SetDeparr1);
- SetPrice(0.0);
- SetChildPerc(0);
- }
- Flight::Flight(char *InOrgin, char *InDesi, char *InDate, char *InDeparr, double inPrice, int InChildPerc){
- SetflightNo();
- SetOrgin(InOrgin);
- SetDesti(InDesi);
- SetDeparr(InDeparr);
- SetPrice(inPrice);
- SetChildPerc(InChildPerc);
- }
- //setter methods
- void Flight::SetflightNo(){
- static int flightCount=100;
- flightCount++;
- flightNo = flightCount;
- }
- void Flight:: SetOrgin(char InOrgin[50]){
- strcpy(orgin,InOrgin);
- }
- void Flight::SetDesti(char InDesti[50]){
- strcpy(destination,InDesti);
- }
- void Flight::SetDate(char InDate[50]){
- strcpy(date,InDate);
- }
- void Flight::SetDeparr(char InDeparr[50]){
- strcpy(deparR,InDeparr);
- }
- void Flight::SetPrice(double InPrice){
- price = InPrice;
- }
- void Flight::SetChildPerc(int InChildPerc){
- childPerc = InChildPerc;
- }
- //getter methods
- int Flight::GetflightNo(){
- return flightNo;
- }
- char* Flight:: GetOrgin(){
- return orgin;
- }
- char* Flight::GetDesti(){
- return destination;
- }
- char* Flight::GetDate(){
- return date;
- }
- char* Flight::GetDeparr(){
- return deparR;
- }
- double Flight::GetPrice(){
- return price;
- }
- int Flight::GetChildPerc(){
- return childPerc;
- }
- // add movie for a flight
- void Flight::addMovie(Movie objMov){
- movieList.push_back(objMov);
- }
- //Business Flight Class
- class BusinessFlight : public Flight{
- private:
- double rate;
- public:
- BusinessFlight();
- BusinessFlight(char *InOrgin, char *InDesi, char *InDate, char *InDeparr, double inPrice, int ChildPerc, double inRate);
- void SetRate(double InRate);
- double GetRate();
- Passenger Book(Passenger obj);
- };
- // getters and setters
- BusinessFlight::BusinessFlight():Flight(){
- SetRate(0.0);
- }
- BusinessFlight::BusinessFlight(char *InOrgin, char *InDesi, char *InDate, char *InDeparr, double inPrice, int ChildPerc, double
- inRate):Flight(InOrgin,InDesi,InDate,InDeparr,inPrice,ChildPerc)
- {
- SetRate(inRate);
- }
- // add Passenger for a business class
- Passenger BusinessFlight::Book(Passenger obj){
- double adultPrice;
- double childPrice;
- double totalPrice;
- adultPrice = obj.getNumAdult() * GetPrice() * GetRate();
- childPrice = obj.getNumChildren() * (double) GetChildPerc()/100 * GetRate();
- totalPrice = adultPrice + childPrice;
- obj.setTotalPrice(totalPrice);
- obj.setNumFlight(GetflightNo());
- return obj;
- }
- //setter methods
- void BusinessFlight::SetRate(double InRate){
- rate = InRate;
- }
- //getter methods
- double BusinessFlight::GetRate(){
- return rate;
- }
- //EconomyFlight Class
- class EconomyFlight : public Flight{
- private:
- public:
- EconomyFlight();
- EconomyFlight(char *InOrgin, char *InDesi, char *InDate, char *InDeparr, double inPrice, int ChildPerc);
- Passenger Book(Passenger obj);
- };
- EconomyFlight::EconomyFlight(){
- }
- // add passenger for an Economy class
- Passenger EconomyFlight::Book(Passenger obj){
- double adultPrice;
- double childPrice;
- double totalPrice;
- adultPrice = obj.getNumAdult() * GetPrice();
- childPrice = obj.getNumChildren() * (double) GetChildPerc()/100;
- totalPrice = adultPrice + childPrice;
- obj.setTotalPrice(totalPrice);
- obj.setNumFlight((int)GetflightNo());
- return obj;
- }
- EconomyFlight::EconomyFlight(char *InOrgin, char *InDesi, char *InDate, char *InDeparr, double inPrice, int ChildPerc):Flight
- (InOrgin,InDesi,InDate,InDeparr,inPrice,ChildPerc){
- }
- //Travel Agent Class
- class TravelAgent{
- private:
- char *name;
- list<Passenger> ListPassenger; // Travel agent class has a collection of travellers and and collection of flight
- list<BusinessFlight> ListBusiness;
- list<EconomyFlight> ListEconomy;
- public:
- void setName(char *InName);
- char* getName();
- void addEconomy(EconomyFlight objEcono);
- void addBusiness(BusinessFlight objBusiness);
- void addPassenger(Passenger objPassenger);
- void FlightList();
- void PassengerList();
- void DeleteFlight(int FlightNo);
- void UpdateFlight(int FlightNo);
- void UpdatePassenger(Passenger objPassenger);
- void DeletePassneger(int Pid);
- void BookFlight(int PID , int FID);
- };
- void TravelAgent::addEconomy(EconomyFlight objEcono){ // Add Economy Flight
- ListEconomy.push_back(objEcono);
- }
- void TravelAgent::addBusiness(BusinessFlight objBusiness){ // Add Business
- ListBusiness.push_front(objBusiness);
- }
- void TravelAgent::addPassenger(Passenger objPassenger){
- ListPassenger.push_back(objPassenger);
- }
- //setter methods
- void TravelAgent::setName(char *InName){
- name= InName;
- }
- //getter methods
- char* TravelAgent::getName(){
- return name;
- }
- void TravelAgent::FlightList(){ // List All flight Method
- cout<<"ID"<<setw(10)<<"Orgin"<<setw(20)<<"Destination"<<setw(10)<<"Date"<<setw(10)<<"Price\n";
- list<BusinessFlight>::iterator dis;
- for(dis=ListBusiness.begin(); dis!=ListBusiness.end();dis++){
- BusinessFlight b = *dis;
- cout<<b.GetflightNo()<<setw(10)<<b.GetOrgin()<<setw(20)<<b.GetDesti()<<setw(10)<<b.GetDate()<<setw(10)<<b.GetPrice()
- <<"\n";
- }
- list<EconomyFlight>::iterator itrEcon;
- for(itrEcon=ListEconomy.begin();itrEcon!=ListEconomy.end();itrEcon++){
- EconomyFlight e = *itrEcon;
- cout<<e.GetflightNo()<<setw(10)<<e.GetOrgin()<<setw(20)<<e.GetDesti()<<setw(10)<<e.GetDate()<<setw(10)<<e.GetPrice()
- <<"\n";
- }
- }
- void TravelAgent::PassengerList(){ // Method to list all Passengers
- cout<<"Booking id"<<setw(10)<<"Name"<<setw(20)<<"No Adult"<<setw(10)<<"No of Child"<<setw(10)<<"Price\tFlightID\n";
- list<Passenger>::iterator itrPasn;
- for(itrPasn=ListPassenger.begin(); itrPasn!=ListPassenger.end();itrPasn++){
- Passenger p = *itrPasn;
- cout<<p.getBookingRef()<<setw(10)<<p.getName()<<setw(20)<<p.getNumAdult()<<setw(10)<<p.getNumChildren()<<setw
- (10)<<p.getTotalPrice()<<"\t"<<p.getNumFlight()<<"\n";
- }
- }
- void TravelAgent::DeleteFlight(int FlightNo){ // Method to delete a flight
- list<BusinessFlight>::iterator dis;
- list<BusinessFlight>::iterator currentpos;
- int flag =0;
- for(dis=ListBusiness.begin(); dis!=ListBusiness.end();dis++){
- BusinessFlight b = *dis;
- int myFli = b.GetflightNo();
- if(FlightNo == myFli ){
- currentpos = dis;
- flag = 1;
- }
- }
- list<EconomyFlight>::iterator itrEcon;
- list<EconomyFlight>::iterator EconCurrent;
- for(itrEcon=ListEconomy.begin(); itrEcon!=ListEconomy.end();itrEcon++){
- EconomyFlight e = *itrEcon;
- int myFli = e.GetflightNo();
- if(FlightNo == myFli ){
- EconCurrent = itrEcon;
- flag = 2;
- }
- }
- if (flag==1){
- char ch;
- cout << "Do you want Delete Flight " << FlightNo << " :";
- cin >> ch;
- if(ch=='y'||ch=='Y'){
- ListBusiness.erase(currentpos);
- cout <<"Deleted......." <<endl;
- }
- }else{
- cout << "Could not found !!!!!"<<endl;
- }
- if (flag==2){
- char ch;
- cout << "Do you want Delete Flight " << FlightNo << " :";
- cin >> ch;
- if(ch=='y'||ch=='Y'){
- ListEconomy.erase(EconCurrent);
- cout <<"Deleted......." <<endl;
- }
- }else{
- cout << "Could not found !!!!!"<<endl;
- }
- }
- void TravelAgent::DeletePassneger(int PID){ // method to delete a passenger
- list<Passenger>::iterator itrPas;
- list<Passenger>::iterator currentpos;
- int flag =0;
- for(itrPas=ListPassenger.begin(); itrPas!=ListPassenger.end();itrPas++){
- Passenger p = *itrPas;
- int myFli = p.getBookingRef();
- if(PID == myFli ){
- currentpos = itrPas;
- flag = 1;
- }
- }
- if (flag==1){
- char ch;
- cout << "Do you want Delete Passenger " << PID << " :";
- cin >> ch;
- if(ch=='y'||ch=='Y'){
- ListPassenger.erase(currentpos);
- cout <<"Deleted......." <<endl;
- }
- }else{
- cout << "Could not found !!!!!"<<endl;
- }
- }
- void TravelAgent::BookFlight(int PID , int FID){ // Method to book a flight
- list<Passenger>::iterator itrPas;
- Passenger PC ;
- int flag =0;
- for(itrPas=ListPassenger.begin(); itrPas!=ListPassenger.end();itrPas++){
- Passenger p = *itrPas;
- int myFli = p.getBookingRef();
- if(PID == myFli ){
- PC = *itrPas;
- flag = 1;
- }
- }
- list<BusinessFlight>::iterator dis;
- BusinessFlight BC;
- for(dis=ListBusiness.begin(); dis!=ListBusiness.end();dis++){
- BusinessFlight b = *dis;
- int myFli = b.GetflightNo();
- if(FID == myFli ){
- BC = *dis;
- flag = 1;
- }
- }
- list<EconomyFlight>::iterator itrEcon;
- EconomyFlight EC;
- for(itrEcon=ListEconomy.begin(); itrEcon!=ListEconomy.end();itrEcon++){
- EconomyFlight e = *itrEcon;
- int myFli = e.GetflightNo();
- if(FID == myFli ){
- EC = *itrEcon;
- flag = 2;
- }
- }
- if (flag==1){
- for(itrPas=ListPassenger.begin(); itrPas!=ListPassenger.end();itrPas++){
- Passenger p = *itrPas;
- int myFli = p.getBookingRef();
- if(PID == myFli ){
- *itrPas = BC.Book(PC);
- }
- }
- }
- if (flag==2){
- for(itrPas=ListPassenger.begin(); itrPas!=ListPassenger.end();itrPas++){
- Passenger p = *itrPas;
- int myFli = p.getBookingRef();
- if(PID == myFli ){
- *itrPas = EC.Book(PC);
- }
- }
- }
- }
- // Method to update Flight Information
- void TravelAgent::UpdateFlight(int FlightNo){
- list<BusinessFlight>::iterator dis;
- list<BusinessFlight>::iterator currentpos;
- for(dis=ListBusiness.begin(); dis!=ListBusiness.end();dis++){
- BusinessFlight b = *dis;
- int myFli = b.GetflightNo();
- if(FlightNo == myFli ){
- currentpos = dis;
- // update the attributes of flights
- }
- }
- }
- // Method to update Passenger Information
- void TravelAgent::UpdatePassenger(Passenger objPassenger){
- }
- //Travel Console
- class TravelConsole{
- private:
- BusinessFlight *objBusiness;
- EconomyFlight *objEconomy;
- Flight* objFlght;
- Movie *objMovie;
- TravelAgent objAgent;
- public:
- void CreateBusinessFlight();
- void CreateEconomyFlight();
- void CreateMovie();
- void ListFlight();
- void CreatePassenger();
- void DeleteFlight();
- void DeletePassenger();
- void Booking();
- TravelAgent getTravelAgent();
- };
- //
- TravelAgent TravelConsole::getTravelAgent(){
- return objAgent;
- }
- // Create Business Flight
- void TravelConsole::CreateBusinessFlight(){ // flight no to appear automatically
- char orgin[75];
- char destination[60];
- char date[60];
- char deparr[60];
- double price;
- int childPercentage;
- double rate;
- cout<<"Business Flight Detail"<<endl;
- cout <<"-------------------------------------"<<endl;
- cout << "Enter the Flight Origin :"<<endl;
- cin >> orgin;
- cout << "Enter the Flight Destination :"<<endl;
- cin >> destination;
- cout << "Enter Flight Date (in the format : 00/00/000) :"<<endl;
- cin >> date;
- cout << "Enter the Depar and Arrival Time (dep 1:00 , arr 3:00):";
- cin >> deparr;
- cout << "Enter the Price ($) :" <<endl;
- cin >> price;
- cout << "Enter the Child Percentage(%) :"<<endl;
- cin >> childPercentage;
- cout << "Enter the Rate :"<<endl;
- cin >> rate;
- BusinessFlight obiBussin;
- obiBussin.SetOrgin(orgin);
- obiBussin.SetDesti(destination);
- obiBussin.SetDate(date);
- obiBussin.SetDeparr(deparr);
- obiBussin.SetPrice(price);
- obiBussin.SetChildPerc(childPercentage);
- obiBussin.SetRate(rate);
- objAgent.addBusiness(obiBussin);
- char ch;
- char no='y';
- cout <<"Do you want add Movie to this Flight (Y/N) :";
- cin >>ch;
- if(ch=='y'||ch=='Y'){
- while(no!='n'){
- CreateMovie();
- cout <<"Movied added" <<endl;
- cout <<"Do you add another Movie (Y/N) :";
- cin >> no;
- };
- }
- }
- // Create Economy Flight
- void TravelConsole::CreateEconomyFlight(){
- int flightNo;
- char orgin[30];
- char destination[30];
- char date[30];
- char deparr[50];
- double price;
- int childPercentage;
- flightNo=0;
- flightNo++;
- cout<<"Economy Flight Detail"<<endl; // flight no to appear automatically
- cout <<"-------------------------------------"<<endl;
- cout << "Enter the Flight Origin :"<<endl;
- cin >> orgin;
- cout << "Enter the Flight Destination :"<<endl;
- cin >> destination;
- cout << "Enter Flight Date (in the format : 00/00/000) :"<<endl;
- cin >> date;
- cout << "Enter the Depar and Arrival Time (dep 1:00 , arr 3:00) :"<<endl;
- cin >> deparr;
- cout << "Enter the Price($) :" <<endl;
- cin >> price;
- cout << "Enter the Child Percentage(%) :"<<endl;
- cin >> childPercentage;
- EconomyFlight economyFlight;
- economyFlight.SetOrgin(orgin);
- economyFlight.SetDesti(destination);
- economyFlight.SetDate(date);
- economyFlight.SetDeparr(deparr);
- economyFlight.SetPrice(price);
- economyFlight.SetChildPerc(childPercentage);
- objAgent.addEconomy(economyFlight);
- char ch;
- cout <<"Do you want add Movie to this Flight (Y/N) :";
- cin >>ch;
- if(ch=='y'||ch=='Y'){
- CreateMovie();
- cout <<"Movied added" <<endl;
- }
- }
- // Add a Passenger
- void TravelConsole::CreatePassenger(){
- int bookingRef;
- char name[50];
- int numAdult;
- int numChild;
- int numFlight;
- double totalPrice;
- cout<<"Create Person"<<endl;
- cout <<"-------------------------------------"<<endl;
- cout << "Enter the Name:";
- cin >> name;
- cout << "Enter Number of Adult :";
- cin >> numAdult;
- cout << "Enter Number of Children:";
- cin >> numChild;
- Passenger objPasn;
- objPasn.setName(name);
- objPasn.setNumAdult(numAdult);
- objPasn.setNumChildren(numChild);
- objPasn.setNumFlight(0);
- objPasn.setTotalPrice(0.0);
- objAgent.addPassenger(objPasn);
- }
- // Add a movie
- void TravelConsole::CreateMovie(){
- char title [40];
- cout<<"Create Flight"<<endl;
- cout <<"-------------------------------------"<<endl;
- cout << "Enter Movie Name :";
- cin >> title;
- objMovie = new Movie(title);
- }
- // Delete a Flight
- void TravelConsole::DeleteFlight(){
- int FID;
- cout << "Please Enter the Flight No :";
- cin >> FID;
- objAgent.DeleteFlight(FID);
- }
- // Delete a Passenger
- void TravelConsole::DeletePassenger(){
- int PID;
- cout << "Please Enter the Passenger ID:";
- cin >> PID;
- objAgent.DeletePassneger(PID);
- }
- void TravelConsole::Booking(){
- int PID;
- int FID;
- objAgent.PassengerList();
- cout << "Select A Passenger :";
- cin >> PID;
- objAgent.FlightList();
- cout << "Select A Select a Flight:";
- cin >> FID;
- objAgent.BookFlight(PID,FID);
- }
- // MAIN MENU
- int main(){
- TravelConsole Journey;
- int menu;
- do{
- cout << "----------------------" <<endl;
- cout << " MAIN MENU " << endl;
- cout << "----------------------" <<endl;
- cout<<endl;
- cout<<endl;
- cout <<"1. Add Business Flight " <<endl;
- cout <<"2. Add Economy Flight " <<endl;
- cout <<"3. Delete Flight " << endl;
- cout <<"4. Flight List " << endl;
- cout <<"5. Create Passenger " <<endl;
- cout <<"6. Passenger list " <<endl;
- cout <<"7. Delete Passenger " << endl;
- cout <<"8. Booking " << endl;
- cout<<" 9. Update Flight Information"<<endl; // -----------------------> update flight
- cout<<"10. Update Passenger Information"<<endl; // -------------------------> update passenger
- cout <<"9. Exit " << endl;
- cout <<"" << endl;
- cout <<"Please Select a Choice: " <<flush;
- cin >>menu;
- switch(menu){
- case 1: {
- Journey.CreateBusinessFlight();
- break;
- }
- case 2: {
- Journey.CreateEconomyFlight();
- break;
- }
- case 3:{
- Journey.DeleteFlight();
- break;
- }
- case 4:{
- Journey.getTravelAgent().FlightList();
- break;
- }
- case 5:{
- Journey.getTravelAgent().PassengerList();
- break;
- }
- case 6:{
- Journey.CreatePassenger();
- break;
- }
- case 7:{
- Journey.DeletePassenger();
- break;
- }
- case 8:{
- Journey.Booking();
- break;
- }
- case 9:{
- return 0;
- break;
- }
- }
- }while(menu!=10);
- getchar();
- system("pause");
- return 0;
- }
above is a the code for my program TravelConsole
It contains function for adding flights , deleting flight and etc. ------------------------------------------
Additionally I need to implement and edit function..An edit function to allow users to change details of any object.
-Display an itinerary for a passenger. To do this, a list of flight numbers (that the passenger is booked on) will need to be stored with the passenger information. Flights should be displayed in chronological order.
-When booking flights, if there is a date conflict with an existing flight, prompt the user to change the date on one of the flights.
Any help is appreciated!!