Monday, January 16, 2012

(VU-Study-Corner) CS402 solution 4 assignment

//Hinna
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Schedule
{
public:
enum Place
{
Lahore =0 ,
Karachi,
Islamabad,
Peshawar,
Quetta
};
private:
bool trip;
string departureDate;
string returnDate;
Place destination; //(Going to)
Place origin; //(Leaving from)
int flightNo;
int depatureTime; //only hour (not full time like 12:56)
int arrivalTime;

public:
Schedule() //default constructor
{
trip = false;
departureDate = "";
returnDate = "";
destination = Lahore;
origin = Lahore;
flightNo = 0;
depatureTime = 0;
arrivalTime = 0;
};

~Schedule() //destructor
{
cout<<"Destructor ..."<<endl;
};

//get/set properties
bool getTrip() {return trip;};
string getDepartureDate(){return departureDate;};
string getReturnDate(){return returnDate;};
Place getDestination(){return destination;};
Place getOrigin(){return origin;};
int getFlightNo(){return flightNo;};
int getDepatureTime(){return depatureTime;};
int getArrivalTime(){return arrivalTime;};

void setTrip(bool val) {trip = val;};
void setDepartureDate(string date){departureDate = date;};
void setReturnDate(string date){returnDate = date;};
void setDestination(Place val){destination = val;};
void setOrigin(Place val){origin = val;};
void setFlightNo(int val){flightNo = val;};
void setDepatureTime(int aTime){depatureTime = aTime;};
void setArrivalTime(int aTime){arrivalTime = aTime;};

// method for get input
void getInputData()
{
int i;

cout<<"\n======================================="<<endl;
cout<<"Enter flight information :"<<endl;
cout<<"Trip type (0: Oneway Trip | 1: Round Trip): ";
cin>>trip;

cout<<"Date of departure: ";
cin>>departureDate;


returnDate = "";
if(trip)//round trip
{
cout<<"Date of return: ";
cin>>returnDate;
}

do
{
cout<<"Destination (0: Lahore, 1: Karachi, 2: Islamabad, 3: Peshawar, 4: Quetta): ";
cin>>i;
}
while (i<0 || i >4);
destination = Place(i);
do
{
cout<<"Origin (0: Lahore, 1: Karachi, 2: Islamabad, 3: Peshawar, 4: Quetta): ";
cin>>i;
}
while (i<0 || i >4);
origin = Place(i);

/* initialize random seed: */
srand ( time(NULL) );
flightNo = rand() % 201;

depatureTime = rand() % 24;
arrivalTime = rand() % 24;
if(abs(arrivalTime-depatureTime)<2) arrivalTime = (arrivalTime + 2)%24;
};

// method for write to disk
void writeData()
{
static char *places[] = {
"Lahore", "Karachi", "Islamabad", "Peshawar", "Quetta"
};

ofstream myfile ("schedule.txt");
if (myfile.is_open())
{
myfile << "Flight No: "<<flightNo<<endl;
myfile << "Origin: "<<places[origin]<<endl;
myfile << "Destination: "<<places[destination]<<endl;
myfile << "Date of Departure: "<<departureDate<<endl;
if(trip)
{
myfile << "Date of Return: "<<returnDate<<endl;
}
else
{
myfile << "Date of Return: N/A"<<endl;
}
myfile << "Departure Time: "<<depatureTime<<":00"<<endl;
myfile << "Arrival Time: "<<arrivalTime<<":00"<<endl;
myfile.close();
}
else cout << "Unable to open file";
};
};

int main()
{
Schedule *mysdl = new Schedule();
mysdl->getInputData();
mysdl->writeData();

system("pause");
return 0;
}
dont copy past..............

--
Join us at facebook: https://www.facebook.com/VU.Study.Corner
 
Group Link: http://groups.google.com/group/VU-Study-Corner?hl=en
 
Group Rules: http://groups.google.com/group/VU-Study-Corner/web/group-rules
 
Unsubscribe: VU-Study-Corner+unsubscribe@googlegroups.com
 
Adult contents, Spamming, Immoral & Rudish talk, Cell number, Websites & Groups links specially in paper days are strictly prohibited and banned in group.

No comments:

Post a Comment