#include
<iostream> // Allows program to perform input and output
using
std::cout; // program uses cout
using
std::cin; // program uses cin
using
std::ios;
# include
<string>
using
std::string;
# include
<fstream>
using
std::ifstream;
using
std::ofstream;
class
Passenger
{
public :
void getPassenger()
{
cout << "\n\n\tEnter your name : ";
cin >> passengerName;
cout << "\tDeparture City : ";
cin >> departureCity;
cout << "\tDestination City : ";
cin >> destinationCity;
cout << "\tDate of Travel : ";
cin >> travelDate;
cout << "\tTime of Travel : ";
cin >> travelTime;
cout << "\tNumber of tickets: ";
cin >> numberOfTickets;
} // end function getPassenger
string passengerName;
string departureCity;
string destinationCity;
string travelDate;
string travelTime;
int numberOfTickets;
}; // end structure Passenger
class
Bus
{
friend class Passenger;
public :
Bus()
{
seats = 0;
departureCity = "";
destinationCity = "";
travelDate = "";
travelTime = "";
} // end constructor
Bus( string depCity, string desCity, string tDate, string tTime )
{
seats = 0;
departureCity = depCity;
destinationCity = desCity;
travelDate = tDate;
travelTime = tTime;
} // end overloaded contructor
string getDepartureCity()
{
return departureCity;
} // end function getDepartureCity
string getDestinationCity()
{
return destinationCity;
} // end function getDestinationCity
bool reserve( Passenger p )
{
if ( ( p.departureCity.compare( this->departureCity ) == 0 ) &&
( p.destinationCity.compare( this->destinationCity ) == 0 ) &&
( p.travelDate.compare( this->travelDate ) == 0 ) &&
( p.travelTime.compare( this->travelTime ) == 0 ) )
{
if ( p.numberOfTickets <= ( 30 - seats ) )
{
cout << "\n\n\tYou ticket numbers are from " << seats;
seats += p.numberOfTickets;
cout << " to " << seats;
return true;
}
else
cout << "\n\n\t" << p.numberOfTickets
<< " were not available in the bus.";
}
else
cout << "\n\n\tThis was not the bus you were looking for.";
return false;
}
private:
int seats;
string departureCity;
string destinationCity;
string travelDate;
string travelTime;
}; // end class Bus
int
main() // function main begins program execution
{
ifstream readFile;
Bus myBus[ 3 ];
Passenger pp;
// let the user know about the program
cout << "\n\n\t\t\tDaewoo Reservation System ";
// Open the input file for input.
readFile.open( "daewoo.txt", ios::in);
// Display error when the file was not opened
if( !readFile.is_open())
{
cout << "Unable to open the input file.\n\n\t";
system( "pause" );
return 1;
} // end if
char choice;
do {
cout << "\n\n\tMake Reservation : R";
cout << "\n\tModify reservation : M ";
cout << "\n\tCancel reservation : C";
cout << "\n\tSearch reservation : S ";
cout << "\n\n\tExit : E";
cin >> choice;
switch( choice )
{
case 'R' :
case 'r' : pp.getPassenger();
for ( int i = 0; i < 3; i++ )
{
if ( myBus[ i ].reserve( pp ) )
break;
}
break;
case 'M' :
case 'm' : //reserve();
break;
case 'C' :
case 'c' : //cancel();
break;
case 'S' :
case 's' : //search();
break;
case 'E' :
case 'e' : choice = 'e';
break;
} // end switch
} while ( choice != 'q' ); // end do-while
// let the screen pause for the user to see the output
cout << "\n\n\t";
system( "pause" );
return 0; // indicates program executed successfully
} // end of function, main