#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
using namespace std;
int random(int i)
{
return rand()%i;
}
struct Time
{
int hour,mins;
};
class Schedule{
private:
bool Trip;
string Date_of_departure;
string Date_of_return;
string Destination;
string Origin;
int Flight_No;
Time Departure_time;
Time Arrival_time;
public:
Schedule();
~Schedule();
void ReadData();
void WriteData();
void GetData();
};
Schedule::Schedule()
{
Trip=0;
Date_of_departure = "Not Entered";
Date_of_return = "Not Entered";
Destination = "Not Entered";
Origin = "Not Entered";
Flight_No = 00;
Departure_time.hour = 00;
Departure_time.mins = 01;
Arrival_time.hour=00;
Arrival_time.mins=00;
}
Schedule::~Schedule()
{
}
main()
{
Schedule s;
s.GetData();
system("pause");
}
void Schedule::WriteData()
{
ofstream myfile ("schedule.txt");
if (myfile.is_open())
{
myfile <<"Flight No : "<<Flight_No<<endl;
myfile <<"Origin : "<<Origin<<endl;
myfile <<"Destination : "<<Destination<<endl;
myfile <<"Date of departure : "<<this->Date_of_departure<<endl;
myfile <<"Date of return : "<<this->Date_of_return<<endl;
myfile <<"Departure time : "<<this->Departure_time.hour<<" : "<<Departure_time.mins<<endl;
myfile <<"Arrival time : "<<this->Arrival_time.hour<<" : "<<Arrival_time.mins<<endl;
myfile.close();
}
else cout << "Unable to open file";
ReadData();
}
void Schedule::ReadData()
{
string line;
ifstream myfile ("schedule.txt");
cout<<"\n\n\n";
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
}
void Schedule::GetData()
{
string n;
char ch;
int l;
cout<<"Please enter \"t for true\" and \"f for falls\""<<" : ";
cin>>ch;
if(ch == 't')
{
Trip=true;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Date of return "<<" : ";
cin>>Date_of_return;
cout<<"Enter Destination_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
else if(ch == 'f')
{
Trip=0;
cout<<"Enter Date of departure "<<" : ";
cin>>Date_of_departure;
cout<<"Enter Destination to travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Destination="Peshawar";
Flight_No=random(200);
}
if( ch == 'k')
{
Destination="Karachi";
Flight_No=random(200);
}
if( ch == 'l')
{
Destination="Lahore";
Flight_No=random(200);
}
if( ch == 'i')
{
Destination="Islamabad";
Flight_No=random(200);
}
if( ch == 'q')
{
Destination="Quetta";
Flight_No=random(200);
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
cout<<"Enter Origin_to_travel for Passenger "<<" : ";
cout<<"Please Select from given"<<endl;
cout<<"k for karachi"<<endl;
cout<<"p for peshawar"<<endl;
cout<<"L for lahore"<<endl;
cout<<"i for Islamabad"<<endl;
cout<<"q for Quetta"<<endl;
cin>>ch;
if( ch == 'p')
{
Origin="Peshawar";
}
if( ch == 'k')
{
Origin="Karachi";
}
if( ch == 'l')
{
Origin="Lahore";
}
if( ch == 'i')
{
Origin="Islamabad";
}
if( ch == 'q')
{
Origin="Quetta";
}
else if( !(ch == 'p' || ch == 'k' || ch == 'l' || ch == 'i' || ch == 'q'))
{
cout<<"Please select from list:"<<endl;
}
Departure_time.hour=random(12);
Departure_time.mins=random(60);
if(Departure_time.hour+2 <=12)
{
Arrival_time.hour=Departure_time.hour+2;
Arrival_time.mins=Departure_time.mins;
}
else
{
Arrival_time.hour=(Departure_time.hour+2)%12;
Arrival_time.mins=Departure_time.mins;
}
}
WriteData();
}
No comments:
Post a Comment