Question

Consider the Passenger data structure we discussed during the last class. Instead of using struct, we will use object-oriented class. Create a hierarchy of 3 classes to support Party, Person and Passenger, where each inherits from its parent. The attributes that define a Party are: Party Type Code (P person, O Address (one larga string) Phone Number (one string organization) The attributes that define a Person are: -Date of Birth First Name -Last Name The attributes that define a Passenger are: - Ticket Number - Frequent Flyer Number (valid alphanumeric or N/A) - Ticket Price Flight Number -Seat Location - Flight Date -Status (T ticketed, H = on hold, C. cancel The following functions are to be implemented: (1) Purchase a ticket. This will create a passenger as an inheritance of both person and party. (2) Change a passengers seat location. Assume that all seats are available. (3) Cancel the ticket Provide a user interface via Cout and Cin to obtain the information. Print a confirmation when the transaction is complete.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

tickets.cpp

#include <iostream>

using namespace std;

//Party class
class Party{
public:
char p_code;
string addr;
string p_no;
};

//Person class with attributes
class Person{
public:
string dob;
string fname;
string lname;
};

//Passenger class , inherited Person and party class properties
class Passenger : public Person, public Party{
int ticket_no;
string ffn="N/A";
int ticket_price;
int flight_no;
int seat_loc;
string flight_date;
char status='H';
  
  
public:
void purchar_ticket();
void change_seat();
void cancel_ticket();
void print();
};

//purchase ticket functions
void Passenger ::purchar_ticket(){
  
//get input from user and store
cout<<"\nEnter the Party code 'P' =person, 'O' = organization:";
cin>> p_code;
  
//if party code is O
if(p_code== 'O'){
cout<<"\nEnter the organization address: ";
cin>> addr;
cout <<"\nEnter the phone number: ";
cin>> p_no;
}
//if party code is P
if(p_code=='P'){
cout<<"\nEnter your date of birth: ";
cin>>dob;
cout<<"\nEnter your First name: ";
cin>>fname;
cout<<"\nEnter your last name: ";
cin>>lname;

}
  
//get other details
cout<<"\nEnter the flight number: ";
cin>>flight_no;
cout<<"\nEnter your flight date : ";
cin>>flight_date;
cout<<"\nEnter the seat location: ";
cin>>seat_loc;
  
// set the other values
ticket_no=1001;
status='T';
ticket_price =10000;
  
cout<<"\n\n Ticket has been booked successfully!!!\n\n";

//print the ticket:
print();
}

//change seat function
void Passenger ::change_seat(){

//get the new seat number from user
cout << "\n Enter the seat number";
cin>>seat_loc;

cout<<"\n\n Seat number has been changed successfully !!!\n\n";
print();

}

//cancel ticket function
void Passenger ::cancel_ticket(){
status= 'C';
  
cout<<"\n\n Ticket has been canceled successfully!!!\n\n";
print();
}

//print the ticket
void Passenger ::print(){
if(p_code=='P'){
cout<<"\n\n\nTicket_no FirstName LastName FrequentFlyerNo Ticket Price FlightNo SeatLocation FlightDate Status\n\n";
cout<<ticket_no<<" "<<fname<<" "<<lname<<" "<<ffn<<" "<<ticket_price<<" "<<flight_no<<" "<<seat_loc<<" "<<flight_date<<" "<<status;

}
if(p_code=='O'){
cout<<"\n\n\nTicket_no Address PhoneNo FrequentFlyerNo Ticket Price FlightNo SeatLocation FlightDate Status\n\n";
cout<<ticket_no<<" "<<addr<<" "<<p_no<<" "<<ffn<<" "<<ticket_price<<" "<<flight_no<<" "<<seat_loc<<" "<<flight_date<<" "<<status;

}


}

int main()
{

char s_ch,c_ch;
Passenger p;
cout<<"\nPurchase Ticket:\n";
p.purchar_ticket();
cout<<"\n\n Do you want to change the seat location ('y' for Yes or 'n' for No): ";
cin>>s_ch;
if(s_ch=='y'){

p.change_seat();
}
cout<<"\n\n Do you want to cancel the ticket ('y' for Yes or 'n' for No): ";
cin>>c_ch;
if(c_ch=='y'){

p.cancel_ticket();
}


return 0;
}

output:

D:Acppiticket\bin DebugIticket.exe Purchase Ticket: Enter the Party code P pers 0organization :P Enter your date of birth:

//for any clarification or modification ofc ode please do comments.

Add a comment
Know the answer?
Add Answer to:
Consider the Passenger data structure we discussed during the last class. Instead of using "struct", we...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header ...

    C++ project we need to create a class for Book and Warehouse using Book.h and Warehouse.h header files given. Then make a main program using Book and Warehouse to read data from book.dat and have functions to list and find book by isbn Objectives: Class Association and operator overloading This project is a continuation from Project 1. The program should accept the same input data file and support the same list and find operations. You will change the implementation of...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation...

    code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT