free geoip

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Soltution of CS201 5th assignment
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support
#1
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:Confusedchedule(){
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.
}
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SEO in Simple Words: How a VU Student Can Write a Clearer Assignment or Blog Post admin 0 30 11-01-2026, 05:11 AM
Last Post: admin
  Cs403 Assignment 3 Helping material May 8,2010 viki 1 5,254 04-28-2020, 03:19 PM
Last Post: ClaireBeauc
  cs301 assignment no 3 Solution 20 January 2016 Vuhelper 0 11,121 01-20-2016, 03:32 PM
Last Post: Vuhelper
  CS201 Assignment vo 3 Solution 20th January 2016 Vuhelper 2 2,640 01-20-2016, 03:28 PM
Last Post: Vuhelper
  CS101 Assignment no 3 Solution 20th January 2016 Vuhelper 0 2,318 01-20-2016, 03:25 PM
Last Post: Vuhelper
  SOC101 INTRODUCTION TO SOCIOLOGY assignment no 3 Solution 20 January 2016 Vuhelper 0 1,905 01-20-2016, 03:19 PM
Last Post: Vuhelper
  CS402 Assignment No 4 Solution & Discussion Xpert 0 2,139 08-01-2015, 02:33 AM
Last Post: Xpert
  cs101 Assignment No. 1 Solution 21 may spring 2015 semester Xpert 0 2,946 05-21-2015, 12:41 AM
Last Post: Xpert
  Assignment solution eng 301 due date 20 may 2015 rumesa khan 3 4,571 05-20-2015, 01:34 AM
Last Post: Xpert
  PHY301 Circuit Theory Assignment No. 1 idea Solution spring may 2015 semester Xpert 0 1,600 05-15-2015, 03:52 AM
Last Post: Xpert

Forum Jump:


Users browsing this thread: 1 Guest(s)
VU Help • House Banner VU Help Virtual University Students - Assignments, Solved Papers, GDB & Exam Help Student Help Forum • Collaborative • Free Support