We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>
+ Link For Assignments, GDBs & Online Quizzes Solution |
+ Link For Past Papers, Solved MCQs, Short Notes & More |
Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion
How to Add New Discussion in Study Group ? Step By Step Guide Click Here.
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files, no reward will be given in any case.
Objectives:
The objective of this assignment is to provide hands on experience of:
Guidelines:
|
|||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Problem Statement: Airline Fare System Write a program for air fare System which will calculate fare on already reserved ticket.
Detailed Description:
In the program, you are required to make a class with name 'airfare' and following are the data members of class airfare.
ñ Seat type ñ Price ñ Tax ñ Airline charges
In the main () function, create a constructor of class to initialize the class data members. Class must have a destructor. Create following user defined function as discussed below along with class constructors and destructor:
GetData(), this function will take the input for seat type variable from the user and will set the ticket price according to the input taken from user. The function GetData() will prompt user to enter required information for seat type.
Seat Type: User can select one of the Seat type:
1. First Class Seat 2. Business Class Seat 3. Economy Class Seat
The function GetData() will also read the data from file named data.txt ( created in assignment no 3 ) to read the destination and then assigns the price for the given destination.
Price: Price will be calculated on the basis of following information:
1- Fare type 2- Destination (Desire destination information will be read from the file “data.txt” )
The price will be assigned according to the table given below:
Airline charges: All airlines will charge 15% of ticket price extra to the all fare types along with the tax.
Class should have a user-defined function named CalculateTax() to calculate the tax according to seat type and ticket price.
Tax calculation will be done as below:
If seat type is First class then tax will be 30% of ticket price If seat type is Business class then tax will be 20% of ticket price If seat type if Economy class then tax will be 10% of ticket price
Calculateprice(), this member function will calculate price of already reserved ticket and will display total fare on the screen. Price calculation will add above calculated tax, airline charges to the actual ticket price according to following information.
Fare = Airline Charges + Tax + Ticket Price
In the function WriteData(), you are required to create a new text file name “fare.txt” in same folder/directory where you have saved your .cpp file. Open this file by using file handling functions and then write all air fare information in that file in following format.
------------------------------------------------------------------------ Name | Address| Date | Destination | Flight. No | Seat. No | Fare ------------------------------------------------------------------------. . . . . . . ------------------------------------------------------------------------
Required information of Name, Address, Date, Destination, Flight No, Seat No, should be taken from assignment no 3 output file.
Points To Remember:
Following points should be kept in mind and handled accordingly, otherwise marks will be deducted.
ñ Reading and writing from text file, must be done with standard file handling functions provided in handouts. ñ All data members must be declared and initialized with appropriate data type. ñ Exceptional cases must be kept in mind and handled accordingly while taking input from user. ñ User must be prompted if there is any error while:
◦ Creating a file. ◦ Opening a file for reading/ writing.
|
Tags:
+ How to Follow the New Added Discussions at Your Mail Address?
+ How to Join Subject Study Groups & Get Helping Material? + How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators? + VU Students Reserves The Right to Delete Your Profile, If?.
+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)
+ Click Here to Search (Looking For something at vustudents.ning.com?) + Click Here To Join (Our facebook study Group)#include <iostream>
#include <stdio.h>
#include <sstream> // Stream building
#include <string> // String Manipulation
#include <fstream> // read/ write file
#include <windows.h> //for Sleep function
#include <time.h> //to get current system time -> Departure time
using namespace std;
class schedule{
string choice, tripp, DoD, DoR, city1, city2, DestinationCity, OriginCity, DTime, ATime;
int lapse, flight;
bool trip; // just declared all the required stuff
public:
schedule(); // constructor of class schedule
void GetData(); // member function
void Allocate(); // member function
void WriteData(); // member function
};
schedule::schedule(){
trip = true; //setting trip to true which can be set to false later by the user through menu
lapse = 2; // Default 2 hours gap between departure and arrival time
};
void schedule::GetData(){
system("CLS"); // clear the garbage
cout "Welcome to PIA\n"; // greet the customer
cout "Please Select... \n";
menu1:
cout "1- Make a Booking 2- Exit\nYour Choice: ";
getline(cin, choice);
if(choice=="1"){ // ok so the customer wana use software
cout "Are you planning a Round Trip?\nEnter 0 for No or any other value if you mean it.\nYour Choice. ";
getline(cin,tripp); // doesn't the customer want a round trip? we already declared trip to true above.
if(tripp=="0")
{
trip=false; //ok if he doesn't want, let set the trip to false
}
cout"Please Provide Details:\n"; // lets move ahead and gather details
menu2:
cout"City of Origin:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city1);
if(city1=="1")
{
OriginCity="Lahore";
}
else if(city1=="2")
{
OriginCity="Karachi";
}else if(city1=="3")
{
OriginCity="Islamabad";
}else if(city1=="4")
{
OriginCity="Peshawar";
}else if(city1=="5")
{
OriginCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
menu3:
cout"\nDestination City:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city2);
if(city2==city1)
{
cout "\nhmmm! Same Inbound and Outbound City. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
else if(city2=="1")
{
DestinationCity="Lahore";
}
else if(city2=="2")
{
DestinationCity="Karachi";
}else if(city2=="3")
{
DestinationCity="Islamabad";
}else if(city2=="4")
{
DestinationCity="Peshawar";
}else if(city2=="5")
{
DestinationCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu3;
}
menu4:
cout"Date of Departure (DD/MM/YY): ";
getline(cin,DoD);
if(trip) // OK, if its a round trip, let's also ask customer about the date of return.
{
cout"Date of Return (DD/MM/YY): ";
getline(cin,DoR);
if(DoR==DoD)
{
cout "\nhmmm! Same Travel Dates. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu4;
}
}
}
else if(choice=="2"){
cout "\nThank you for using PIA."; // Let's thank the customer and exit! after a wait of 3000 ms.
Sleep(3000);
exit(1);
}
else{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu1;
}
};
void schedule::Allocate(){
string Cur_Time;
int hours, minutes, seconds, temp_minutes,ATime_Hours, ATime_Minutes;
stringstream temp_ATime,temp_DTime;
char timebuff[9];
flight = rand()%201;
Cur_Time = _strtime(timebuff); // get current system time <time.h>
sscanf(Cur_Time.c_str(), "%d:%d:%d", &hours, &minutes, &seconds); //seperate hours and minutes.
temp_minutes = (hours*60)+minutes+(lapse*60); // make total minutes adding the 2 hours lapse as well
ATime_Hours = temp_minutes/60; //make hours from minutes back.
ATime_Minutes = temp_minutes%60; // get extra minutes after making hours
temp_DTime hours ":" minutes; // build stream containing temp departure time
DTime = temp_DTime.str(); // build string containing departure time
temp_ATime ATime_Hours ":" ATime_Minutes;// build stream containing temp arrival time
ATime = temp_ATime.str(); // build string containing arrival time
};
void schedule::WriteData(){
ofstream record("schedule.txt", ios::out | ios::binary);
if(!record)
{
cout "Cannot write to file.\n"; // raise exception, can use catch & throw if was asked in assignment
return;
}
else //lets finish this and write every thing to schedule.txt
{
record "Flight No: " flight endl;
record "Origin: " OriginCity endl;
record "Destination: " DestinationCity endl;
record "Date of Departure: " DoD endl;
record "Date of Return: " DoR endl;
record "Departure Time: " DTime endl;
record "Arrival Time: " ATime endl;
record.close();
cout "\n\nYour reservation has been successfully completed.\n\nPlease wait while we take you back...";
}
};
void main ()
{
Boot:
schedule new_schedule; //new object of class schedule
new_schedule.GetData(); // Prompt costumer
new_schedule.Allocate(); //Generate Flight Number, Departure and Arrival Time
new_schedule.WriteData(); // Write the data to schedule.txt
new_schedule.~schedule(); // destroy the object
Sleep(3000); //take some rest before starting again
goto Boot; //No! a long day ahead again.
}
CS201 assignment solution of 5th
#include <iostream>
#include <stdio.h>
#include <sstream> // Stream building
#include <string> // String Manipulation
#include <fstream> // read/ write file
#include <windows.h> //for Sleep function
#include <time.h> //to get current system time -> Departure time
using namespace std;
class schedule{
string choice, tripp, DoD, DoR, city1, city2, DestinationCity, OriginCity, DTime, ATime;
int lapse, flight;
bool trip; // just declared all the required stuff
public:
schedule(); // constructor of class schedule
void GetData(); // member function
void Allocate(); // member function
void WriteData(); // member function
};
schedule::schedule(){
trip = true; //setting trip to true which can be set to false later by the user through menu
lapse = 2; // Default 2 hours gap between departure and arrival time
};
void schedule::GetData(){
system("CLS"); // clear the garbage
cout "Welcome to PIA\n"; // greet the customer
cout "Please Select... \n";
menu1:
cout "1- Make a Booking 2- Exit\nYour Choice: ";
getline(cin, choice);
if(choice=="1"){ // ok so the customer wana use software
cout "Are you planning a Round Trip?\nEnter 0 for No or any other value if you mean it.\nYour Choice. ";
getline(cin,tripp); // doesn't the customer want a round trip? we already declared trip to true above.
if(tripp=="0")
{
trip=false; //ok if he doesn't want, let set the trip to false
}
cout"Please Provide Details:\n"; // lets move ahead and gather details
menu2:
cout"City of Origin:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city1);
if(city1=="1")
{
OriginCity="Lahore";
}
else if(city1=="2")
{
OriginCity="Karachi";
}else if(city1=="3")
{
OriginCity="Islamabad";
}else if(city1=="4")
{
OriginCity="Peshawar";
}else if(city1=="5")
{
OriginCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
menu3:
cout"\nDestination City:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city2);
if(city2==city1)
{
cout "\nhmmm! Same Inbound and Outbound City. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
else if(city2=="1")
{
DestinationCity="Lahore";
}
else if(city2=="2")
{
DestinationCity="Karachi";
}else if(city2=="3")
{
DestinationCity="Islamabad";
}else if(city2=="4")
{
DestinationCity="Peshawar";
}else if(city2=="5")
{
DestinationCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu3;
}
menu4:
cout"Date of Departure (DD/MM/YY): ";
getline(cin,DoD);
if(trip) // OK, if its a round trip, let's also ask customer about the date of return.
{
cout"Date of Return (DD/MM/YY): ";
getline(cin,DoR);
if(DoR==DoD)
{
cout "\nhmmm! Same Travel Dates. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu4;
}
}
}
else if(choice=="2"){
cout "\nThank you for using PIA."; // Let's thank the customer and exit! after a wait of 3000 ms.
Sleep(3000);
exit(1);
}
else{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu1;
}
};
void schedule::Allocate(){
string Cur_Time;
int hours, minutes, seconds, temp_minutes,ATime_Hours, ATime_Minutes;
stringstream temp_ATime,temp_DTime;
char timebuff[9];
flight = rand()%201;
Cur_Time = _strtime(timebuff); // get current system time <time.h>
sscanf(Cur_Time.c_str(), "%d:%d:%d", &hours, &minutes, &seconds); //seperate hours and minutes.
temp_minutes = (hours*60)+minutes+(lapse*60); // make total minutes adding the 2 hours lapse as well
ATime_Hours = temp_minutes/60; //make hours from minutes back.
ATime_Minutes = temp_minutes%60; // get extra minutes after making hours
temp_DTime hours ":" minutes; // build stream containing temp departure time
DTime = temp_DTime.str(); // build string containing departure time
temp_ATime ATime_Hours ":" ATime_Minutes;// build stream containing temp arrival time
ATime = temp_ATime.str(); // build string containing arrival time
};
void schedule::WriteData(){
ofstream record("schedule.txt", ios::out | ios::binary);
if(!record)
{
cout "Cannot write to file.\n"; // raise exception, can use catch & throw if was asked in assignment
return;
}
else //lets finish this and write every thing to schedule.txt
{
record "Flight No: " flight endl;
record "Origin: " OriginCity endl;
record "Destination: " DestinationCity endl;
record "Date of Departure: " DoD endl;
record "Date of Return: " DoR endl;
record "Departure Time: " DTime endl;
record "Arrival Time: " ATime endl;
record.close();
cout "\n\nYour reservation has been successfully completed.\n\nPlease wait while we take you back...";
}
};
void main ()
{
Boot:
schedule new_schedule; //new object of class schedule
new_schedule.GetData(); // Prompt costumer
new_schedule.Allocate(); //Generate Flight Number, Departure and Arrival Time
new_schedule.WriteData(); // Write the data to schedule.txt
new_schedule.~schedule(); // destroy the object
Sleep(3000); //take some rest before starting again
goto Boot; //No! a long day ahead again.
}
CS201_5th_Assignment_Solution_Fall_2011
#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace std;
string karachi="Karachi",lahore="Lahore",peshawar="Peshawar";
class Airfare
{
private:
char seatType;
int price;
float tax;
double airlinecharg;
double fare;
string destination, name, date, address, flightNo, seatNo;
public:
enum Type
{
economy,
business,
first
};
Type type;
void getData();
void readData();
void setDestination(string i){destination=i;};
double calculatePrice();
float CalculateTax();
void calFare();
void writeDatafile();
void writeDatascreen();
Airfare(){
seatType=' ';
price=tax=airlinecharg=fare=0.0;
destination=name=date=address=flightNo=seatNo="default";};
};
void Airfare::getData()
{
int i;
do
{
cout"Please select the Seat Type:"endl;
cout" 1 for Economy Class"endl;
cout" 2 for Business Class"endl;
cout" 3 for First Class"endl;
cin>>i;
}
while(i>3 || i<1);
type = Type(i);
}
void Airfare::readData()
{
string line;
ifstream myfile ("data.txt");
if (myfile.is_open())
{
getline (myfile,line);
name=line;
getline (myfile,line);
address=line;
getline (myfile,line);
date=line;
getline (myfile,line);
destination=line;
getline (myfile,line);
flightNo=line;
getline (myfile,line);
seatNo=line;
myfile.close();
}
else cout "Unable to open file";
}
double Airfare::calculatePrice()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+3000)*0.15;
return tax+3000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+5000)*0.15;
return tax+5000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+4000)*0.15;
return tax+4000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+6000)*0.15;
return tax+6000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+2500)*0.15;
return tax+2500+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+4500)*0.15;
return tax+4500+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
}
float Airfare::CalculateTax()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
tax=4000*0.10;
break;
case 2://business class
tax=6000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
tax=3000*0.10;
break;
case 2://business class
tax=3000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
tax=2500*0.10;
break;
case 2://business class
tax=4500*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
fare=calculatePrice();
}
void Airfare::writeDatafile()
{
ofstream myfile ("fare.txt");
if (myfile.is_open())
{
myfile"_________________________________________________________________________"endl;
myfile"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
myfile"-------------------------------------------------------------------------"endl;
myfile"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfile"-------------------------------------------------------------------------"endl;
myfile.close();
}
else cout "Unable to open file";
}
void Airfare::writeDatascreen()
{
cout"_________________________________________________________________________"endl;
cout"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
cout"-------------------------------------------------------------------------"endl;
cout"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
cout"-------------------------------------------------------------------------"endl;
}
void Airfare::calFare()
{
fare=calculatePrice();
}
main()
{
Airfare a;
a.getData();
a.readData();
a.CalculateTax();
a.calculatePrice();
a.calFare();
a.writeDatafile();
a.writeDatascreen();
system("pause");
}
plz guys u not a send all progam
u alwasy send this pargarm file in the zip
warna sir copy assigment isly to khalte hain yahan code jo post hota ha.
lol
What an idea, miss..!
They teachers know very well about cheating skills of students. So whether somebody posts the solution directly or in the format of a file, our mentors are aware of it already.
#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace std;
string karachi="Karachi",lahore="Lahore",peshawar="Peshawar";
class Airfare
{
private:
char seatType;
int price;
float tax;
double airlinecharg;
double fare;
string destination, name, date, address, flightNo, seatNo;
public:
enum Type
{
economy,
business,
first
};
Type type;
void getData();
void readData();
void setDestination(string i){destination=i;};
double calculatePrice();
float CalculateTax();
void calFare();
void writeDatafile();
void writeDatascreen();
Airfare(){
seatType=' ';
price=tax=airlinecharg=fare=0.0;
destination=name=date=address=flightNo=seatNo="default";};
};
void Airfare::getData()
{
int i;
do
{
cout"Please select the Seat Type:"endl;
cout" 1 for Economy Class"endl;
cout" 2 for Business Class"endl;
cout" 3 for First Class"endl;
cin>>i;
}
while(i>3 || i<1);
type = Type(i);
}
void Airfare::readData()
{
string line;
ifstream myfile ("data.txt");
if (myfile.is_open())
{
getline (myfile,line);
name=line;
getline (myfile,line);
address=line;
getline (myfile,line);
date=line;
getline (myfile,line);
destination=line;
getline (myfile,line);
flightNo=line;
getline (myfile,line);
seatNo=line;
myfile.close();
}
else cout "Unable to open file";
}
double Airfare::calculatePrice()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+3000)*0.15;
return tax+3000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+5000)*0.15;
return tax+5000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+4000)*0.15;
return tax+4000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+6000)*0.15;
return tax+6000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+2500)*0.15;
return tax+2500+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+4500)*0.15;
return tax+4500+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
}
float Airfare::CalculateTax()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
tax=4000*0.10;
break;
case 2://business class
tax=6000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
tax=3000*0.10;
break;
case 2://business class
tax=3000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
tax=2500*0.10;
break;
case 2://business class
tax=4500*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
fare=calculatePrice();
}
void Airfare::writeDatafile()
{
ofstream myfile ("fare.txt");
if (myfile.is_open())
{
myfile"_________________________________________________________________________"endl;
myfile"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
myfile"-------------------------------------------------------------------------"endl;
myfile"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfile"-------------------------------------------------------------------------"endl;
myfile.close();
}
else cout "Unable to open file";
}
void Airfare::writeDatascreen()
{
cout"_________________________________________________________________________"endl;
cout"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
cout"-------------------------------------------------------------------------"endl;
cout"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
cout"-------------------------------------------------------------------------"endl;
}
void Airfare::calFare()
{
fare=calculatePrice();
}
main()
{
Airfare a;
a.getData();
a.readData();
a.CalculateTax();
a.calculatePrice();
a.calFare();
a.writeDatafile();
a.writeDatascreen();
system("pause");
}
yeh lo frnds,,,,,this is for all of you,,,,
plz check it,,solution is here,,
CS201 assignment solution of 5th
#include <iostream>
#include <stdio.h>
#include <sstream> // Stream building
#include <string> // String Manipulation
#include <fstream> // read/ write file
#include <windows.h> //for Sleep function
#include <time.h> //to get current system time -> Departure time
using namespace std;
class schedule{
string choice, tripp, DoD, DoR, city1, city2, DestinationCity, OriginCity, DTime, ATime;
int lapse, flight;
bool trip; // just declared all the required stuff
public:
schedule(); // constructor of class schedule
void GetData(); // member function
void Allocate(); // member function
void WriteData(); // member function
};
schedule::schedule(){
trip = true; //setting trip to true which can be set to false later by the user through menu
lapse = 2; // Default 2 hours gap between departure and arrival time
};
void schedule::GetData(){
system(“CLS”); // clear the garbage
cout ”Welcome to PIA\n”; // greet the customer
cout ”Please Select… \n”;
menu1:
cout ”1- Make a Booking 2- Exit\nYour Choice: “;
getline(cin, choice);
if(choice==”1″){ // ok so the customer wana use software
cout “Are you planning a Round Trip?\nEnter 0 for No or any other value if you mean it.\nYour Choice. “;
getline(cin,tripp); // doesn’t the customer want a round trip? we already declared trip to true above.
if(tripp==”0″)
{
trip=false; //ok if he doesn’t want, let set the trip to false
}
cout”Please Provide Details:\n”; // lets move ahead and gather details
menu2:
cout”City of Origin:\nPlease Choose Between\n”;
cout”1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta”;
cout”\nYour choice: “;
getline(cin,city1);
if(city1==”1″)
{
OriginCity=”Lahore”;
}
else if(city1==”2″)
{
OriginCity=”Karachi”;
}else if(city1==”3″)
{
OriginCity=”Islamabad”;
}else if(city1==”4″)
{
OriginCity=”Peshawar”;
}else if(city1==”5″)
{
OriginCity=”Quetta”;
}
else
{
cout ”\nhmmm! Invalid Choice. Please try again.\n”; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
menu3:
cout”\nDestination City:\nPlease Choose Between\n”;
cout”1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta”;
cout”\nYour choice: “;
getline(cin,city2);
if(city2==city1)
{
cout ”\nhmmm! Same Inbound and Outbound City. Please try again.\n”; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
else if(city2==”1″)
{
DestinationCity=”Lahore”;
}
else if(city2==”2″)
{
DestinationCity=”Karachi”;
}else if(city2==”3″)
{
DestinationCity=”Islamabad”;
}else if(city2==”4″)
{
DestinationCity=”Peshawar”;
}else if(city2==”5″)
{
DestinationCity=”Quetta”;
}
else
{
cout ”\nhmmm! Invalid Choice. Please try again.\n”; // raise exception, can use catch & throw if was asked in assignment
goto menu3;
}
menu4:
cout”Date of Departure (DD/MM/YY): “;
getline(cin,DoD);
if(trip) // OK, if its a round trip, let’s also ask customer about the date of return.
{
cout”Date of Return (DD/MM/YY): “;
getline(cin,DoR);
if(DoR==DoD)
{
cout ”\nhmmm! Same Travel Dates. Please try again.\n”; // raise exception, can use catch & throw if was asked in assignment
goto menu4;
}
}
}
else if(choice==”2″){
cout “\nThank you for using PIA.”; // Let’s thank the customer and exit! after a wait of 3000 ms.
Sleep(3000);
exit(1);
}
else{
cout ”\nhmmm! Invalid Choice. Please try again.\n”; // raise exception, can use catch & throw if was asked in assignment
goto menu1;
}
};
void schedule::Allocate(){
string Cur_Time;
int hours, minutes, seconds, temp_minutes,ATime_Hours, ATime_Minutes;
stringstream temp_ATime,temp_DTime;
char timebuff[9];
flight = rand()%201;
Cur_Time = _strtime(timebuff); // get current system time <time.h>
sscanf(Cur_Time.c_str(), “%d:%d:%d”, &hours, &minutes, &seconds); //seperate hours and minutes.
temp_minutes = (hours*60)+minutes+(lapse*60); // make total minutes adding the 2 hours lapse as well
ATime_Hours = temp_minutes/60; //make hours from minutes back.
ATime_Minutes = temp_minutes%60; // get extra minutes after making hours
temp_DTime hours ”:” minutes; // build stream containing temp departure time
DTime = temp_DTime.str(); // build string containing departure time
temp_ATime ATime_Hours ”:” ATime_Minutes;// build stream containing temp arrival time
ATime = temp_ATime.str(); // build string containing arrival time
};
void schedule::WriteData(){
ofstream record(“schedule.txt”, ios::out | ios::binary);
if(!record)
{
cout “Cannot write to file.\n”; // raise exception, can use catch & throw if was asked in assignment
return;
}
else //lets finish this and write every thing to schedule.txt
{
record ”Flight No: “ flight endl;
record ”Origin: “ OriginCity endl;
record ”Destination: “ DestinationCity endl;
record ”Date of Departure: “ DoD endl;
record ”Date of Return: “ DoR endl;
record ”Departure Time: “ DTime endl;
record ”Arrival Time: “ ATime endl;
record.close();
cout ”\n\nYour reservation has been successfully completed.\n\nPlease wait while we take you back…”;
}
};
void main ()
{
Boot:
schedule new_schedule; //new object of class schedule
new_schedule.GetData(); // Prompt costumer
new_schedule.Allocate(); //Generate Flight Number, Departure and Arrival Time
new_schedule.WriteData(); // Write the data to schedule.txt
new_schedule.~schedule(); // destroy the object
Sleep(3000); //take some rest before starting again
goto Boot; //No! a long day ahead again.
}
#include <iostream.h>
#include <fstream.h>
#include <string.h>
using namespace ::std;
string karachi="Karachi",lahore="Lahore",peshawar="Peshaw ar";
class Airfare
{
private:
char seatType;
int price;
float tax;
double airlinecharg;
double fare;
string destination, name, date, address, flightNo, seatNo;
public:
enum Type
{
economy,
business,
first
};
Type type;
void getData();
void readData();
void setDestination(string i){destination=i;};
double calculatePrice();
float CalculateTax();
void calFare();
void writeDatafile();
void writeDatascreen();
Airfare(){
seatType=' ';
price=tax=airlinecharg=fare=0.0;
destination=name=date=address=flightNo=seatNo="def ault";};
};
void Airfare::getData()
{
int i;
do
{
cout"Please select the Seat Type:"endl;
cout" 1 for Economy Class"endl;
cout" 2 for Business Class"endl;
cout" 3 for First Class"endl;
cin>>i;
}
while(i>3 || i<1);
type = Type(i);
}
void Airfare::readData()
{
string line;
ifstream myfile ("data.txt");
if (myfile.is_open())
{
getline (myfile,line);
name=line;
getline (myfile,line);
address=line;
getline (myfile,line);
date=line;
getline (myfile,line);
destination=line;
getline (myfile,line);
flightNo=line;
getline (myfile,line);
seatNo=line;
myfile.close();
}
else cout "Unable to open file";
}
double Airfare::calculatePrice()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+3000)*0.15;
return tax+3000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+5000)*0.15;
return tax+5000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+4000)*0.15;
return tax+4000+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+6000)*0.15;
return tax+6000+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
airlinecharg=(tax+2500)*0.15;
return tax+2500+airlinecharg;
break;
case 2://business class
airlinecharg=(tax+4500)*0.15;
return tax+4500+airlinecharg;
break;
case 3://first class
airlinecharg=(tax+7000)*0.15;
return tax+7000+airlinecharg;
break;
};
}
}
float Airfare::CalculateTax()
{
if(destination == karachi )
{
switch (type)
{
case 1://economy class
tax=4000*0.10;
break;
case 2://business class
tax=6000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == lahore )
{
switch (type)
{
case 1://economy class
tax=3000*0.10;
break;
case 2://business class
tax=3000*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
if(destination == peshawar )
{
switch (type)
{
case 1://economy class
tax=2500*0.10;
break;
case 2://business class
tax=4500*0.20;
break;
case 3://first class
tax=7000*0.30;
break;
};
}
fare=calculatePrice();
}
void Airfare::writeDatafile()
{
ofstream myfile ("fare.txt");
if (myfile.is_open())
{
myfile"_________________________________________ ____________________________"endl;
myfile"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
myfile"--------------------------------------------------------------------"endl;
myfile"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfileendl;
myfile"-------------------------------------------------------------------------"endl;
myfile.close();
}
else cout "Unable to open file";
}
void Airfare::writeDatascreen()
{
cout"___________________________________________ __________________________"endl;
cout"| Name | Address | Date | Destination | Flight No.| Seat No.| Fare |"endl;
cout"---------------------------------------------------------------------"endl;
cout"| "name" | "address" | "date" | "destination" | "flightNo" | "seatNo" | "fare" | "endl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
coutendl;
cout"-------------------------------------------------------------------------"endl;
}
void Airfare::calFare()
{
fare=calculatePrice();
}
main()
{
Airfare a;
a.getData();
a.readData();
a.CalculateTax();
a.calculatePrice();
a.calFare();
a.writeDatafile();
a.writeDatascreen();
system("pause");
}
#include <iostream>
#include <stdio.h>
#include <sstream> // Stream building
#include <string> // String Manipulation
#include <fstream> // read/ write file
#include <windows.h> //for Sleep function
#include <time.h> //to get current system time -> Departure time
using namespace std;
class schedule{
string choice, tripp, DoD, DoR, city1, city2, DestinationCity, OriginCity, DTime, ATime;
int lapse, flight;
bool trip; // just declared all the required stuff
public:
schedule(); // constructor of class schedule
void GetData(); // member function
void Allocate(); // member function
void WriteData(); // member function
};
schedule::schedule(){
trip = true; //setting trip to true which can be set to false later by the user through menu
lapse = 2; // Default 2 hours gap between departure and arrival time
};
void schedule::GetData(){
system("CLS"); // clear the garbage
cout "Welcome to PIA\n"; // greet the customer
cout "Please Select... \n";
menu1:
cout "1- Make a Booking 2- Exit\nYour Choice: ";
getline(cin, choice);
if(choice=="1"){ // ok so the customer wana use software
cout "Are you planning a Round Trip?\nEnter 0 for No or any other value if you mean it.\nYour Choice. ";
getline(cin,tripp); // doesn't the customer want a round trip? we already declared trip to true above.
if(tripp=="0")
{
trip=false; //ok if he doesn't want, let set the trip to false
}
cout"Please Provide Details:\n"; // lets move ahead and gather details
menu2:
cout"City of Origin:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city1);
if(city1=="1")
{
OriginCity="Lahore";
}
else if(city1=="2")
{
OriginCity="Karachi";
}else if(city1=="3")
{
OriginCity="Islamabad";
}else if(city1=="4")
{
OriginCity="Peshawar";
}else if(city1=="5")
{
OriginCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
menu3:
cout"\nDestination City:\nPlease Choose Between\n";
cout"1- Lahore 2- Karachi 3- Islamabad 4- Peshawar 5- Quetta";
cout"\nYour choice: ";
getline(cin,city2);
if(city2==city1)
{
cout "\nhmmm! Same Inbound and Outbound City. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu2;
}
else if(city2=="1")
{
DestinationCity="Lahore";
}
else if(city2=="2")
{
DestinationCity="Karachi";
}else if(city2=="3")
{
DestinationCity="Islamabad";
}else if(city2=="4")
{
DestinationCity="Peshawar";
}else if(city2=="5")
{
DestinationCity="Quetta";
}
else
{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu3;
}
menu4:
cout"Date of Departure (DD/MM/YY): ";
getline(cin,DoD);
if(trip) // OK, if its a round trip, let's also ask customer about the date of return.
{
cout"Date of Return (DD/MM/YY): ";
getline(cin,DoR);
if(DoR==DoD)
{
cout "\nhmmm! Same Travel Dates. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu4;
}
}
}
else if(choice=="2"){
cout "\nThank you for using PIA."; // Let's thank the customer and exit! after a wait of 3000 ms.
Sleep(3000);
exit(1);
}
else{
cout "\nhmmm! Invalid Choice. Please try again.\n"; // raise exception, can use catch & throw if was asked in assignment
goto menu1;
}
};
void schedule::Allocate(){
string Cur_Time;
int hours, minutes, seconds, temp_minutes,ATime_Hours, ATime_Minutes;
stringstream temp_ATime,temp_DTime;
char timebuff[9];
flight = rand()%201;
Cur_Time = _strtime(timebuff); // get current system time <time.h>
sscanf(Cur_Time.c_str(), "%d:%d:%d", &hours, &minutes, &seconds); //seperate hours and minutes.
temp_minutes = (hours*60)+minutes+(lapse*60); // make total minutes adding the 2 hours lapse as well
ATime_Hours = temp_minutes/60; //make hours from minutes back.
ATime_Minutes = temp_minutes%60; // get extra minutes after making hours
temp_DTime hours ":" minutes; // build stream containing temp departure time
DTime = temp_DTime.str(); // build string containing departure time
temp_ATime ATime_Hours ":" ATime_Minutes;// build stream containing temp arrival time
ATime = temp_ATime.str(); // build string containing arrival time
};
void schedule::WriteData(){
ofstream record("schedule.txt", ios::out | ios::binary);
if(!record)
{
cout "Cannot write to file.\n"; // raise exception, can use catch & throw if was asked in assignment
return;
}
else //lets finish this and write every thing to schedule.txt
{
record "Flight No: " flight endl;
record "Origin: " OriginCity endl;
record "Destination: " DestinationCity endl;
record "Date of Departure: " DoD endl;
record "Date of Return: " DoR endl;
record "Departure Time: " DTime endl;
record "Arrival Time: " ATime endl;
record.close();
cout "\n\nYour reservation has been successfully completed.\n\nPlease wait while we take you back...";
}
};
void main ()
{
Boot:
schedule new_schedule; //new object of class schedule
new_schedule.GetData(); // Prompt costumer
new_schedule.Allocate(); //Generate Flight Number, Departure and Arrival Time
new_schedule.WriteData(); // Write the data to schedule.txt
new_schedule.~schedule(); // destroy the object
Sleep(3000); //take some rest before starting again
goto Boot; //No! a long day ahead again.
}
© 2019 Created by + M.Tariq Malik.
Powered by
Promote Us | Report an Issue | Privacy Policy | Terms of Service
VU Students reserves the right to delete profile, which does not show any Activity at site nor has not activity more than 01 month.
We are user-generated contents site. All product, videos, pictures & others contents on vustudents.ning.com don't seem to be beneath our Copyrights & belong to their respected owners & freely available on public domains. We believe in Our Policy & do according to them. If Any content is offensive in your Copyrights then please email at m.tariqmalik@gmail.com or Contact us at contact Page with copyright detail & We will happy to remove it immediately.
Management: Admins ::: Moderators
Awards Badges List | Moderators Group
All Members | Featured Members | Top Reputation Members | Angels Members | Intellectual Members | Criteria for Selection
Become a Team Member | Safety Guidelines for New | Site FAQ & Rules | Safety Matters | Online Safety | Rules For Blog Post