Virtual University of Pakistan
Leading Student's Social Network Worldwide!
Looking For Something at site?Search Here
Study Groups By Subject code Wise (Click Here & Join Your Subject Group)
[ Assignments Solution ] [ GDBs Solution ] [ Online Quiz ] [ Solved Papers ] [ Internship Reports ]
"Turn VU Students Platform into an Interactive Channel of Learing" Read More.
Assignment No. 04
Semester: Fall 2011
CS201: Introduction to Programming Total Marks: 20
Due Date:16/01/2012
Instructions:
Please read the following instructions carefully before submitting assignment. It should be clear that your assignment will not get any credit if:
The assignment is submitted after due date.
The submitted assignment does not open or file is corrupt.
Assignment is copied(partial or full) from any source (websites, forums, students, etc)
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:
Classes
Member Functions
Dynamic Memory allocation in C/C++
String Manipulation Functions
File Handling
Guidelines:
Code should be properly indented and well commented.
Follow C/C++ rules while writing variable names, function names etc
Use only dev-C++ for this assignment.
Use appropriate C/C++ structure i.e. if-else; switch statement etc to get inputs from user where required (Marks will be deducted if inappropriate structure will be used).
Problem Statement: Airline Schedule System
Write a program for Flight Schedule System which will check the flight schedule.
Detailed Description:
In the program, you are required to make a class with name 'Schedule' and following are the data members of class schedule.
Trip
Date of departure
Date of return
Destination(Going to)
Origin (Leaving from)
Flight No
Departure time
Arrival time
Initialize all these data members with their default values by creating constructor for the class. Object creation of class should be done dynamically using dynamic memory allocation functions. Also class schedule should have a destructor.
Along with constructor and destructor of class, it is mandatory to used getter and setter functions for all above stated data members to properly assign their values.
Detail description of all data members are given below.
Class data members description:
Trip:
Class variables; trip should be off type Boolean; value of the variable should be taken from the user, if user sets it to true, then user should enter the required information for following data members and this trip will become a Round Trip:
Date of departure
Date of return
Destination
Origin
And if user set the variable values to false, prompt user to enter the required information for one-way trip:
Date of departure
Destination
Origin
Date of departure/Date of return:
Date of departure and date of return can be any date, entered by the user.
Flight No:
Flight numbers will be assigned randomly which can be any number from 0 to 200.
Origins/Destinations:
The user can chose one of five destinations and origins:
Lahore
Karachi
Islamabad
Peshawar
Quetta
Departure Time and Arrival Time
Both these will be generated randomly and must have at least difference of two hours in-between departure time and arrival time.
When you are done with this, you are required to write a member function of class named WriteData().In the function WriteData(), you are required to create a new text file name “schedule.txt” in same folder/directory where you have saved your .cpp file. Open this file by using file handling functions and then write all Schedule information in that file in following format:
Flight No:
Origin:
Destination:
Date of Departure:
Date of Return:
Departure Time:
Arrival Time:
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: &, 4, Assignment, CS201, Date:16-01-2012, Discussion, Due, No, Solution

Permalink Reply by + M.Tariq Malik + on January 10, 2012 at 8:45pm Please Discuss here about this assignment.Thanks
Permalink Reply by Xo-Hussain on January 14, 2012 at 11:35am Tariq bhai solution plzzzzzzzzzzzzzzzzzzzzzzzz
jazak ALLAH azawajal
wasalam
Permalink Reply by yasir javaed on January 15, 2012 at 4:26pm tariq bhai please share idea solution.

Permalink Reply by + M.Tariq Malik + on January 15, 2012 at 9:11pm #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: "flightNoendl;
myfile "Origin: "places[origin]endl;
myfile "Destination: "places[destination]endl;
myfile "Date of Departure: "departureDateendl;
if(trip)
{
myfile "Date of Return: "returnDateendl;
}
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;
}

Permalink Reply by + M.Tariq Malik + on January 15, 2012 at 9:11pm Here you go
but please change it,
Permalink Reply by Xo-Hussain on January 15, 2012 at 9:14pm Thank u Tariq bhai thank u so much...
Jazak ALLAH azawajal
wasalam
Permalink Reply by Umeed on January 16, 2012 at 12:18pm assignment solution
Permalink Reply by M.Arslan Yaqoob on January 16, 2012 at 1:48pm its not complete id my dear
Permalink Reply by ++ CHISHTI ++ on January 16, 2012 at 1:50pm Run time error dono he same han
+ About Us
Created By: M.Tariq Malik
Designed By: Amel
Chief Admin: M.Tariq Malik
Management: Moderators
Like Our Facebook Page
© 2013 Created by + M.Tariq Malik +.
Promote Us | Report an Issue | Privacy Policy | Terms of Service
University Services: + VU Orientation + Students Handbook + Open Courseware + VULMS Login Here + VU Official Site + VU Email
+ Handouts/Books + VU Content Library + VU Book Shop + VU TV Channels + VU Contacts List + VU Radio + Campus Career Portal
+ VU Alumni + Vu-Bytes Magazine + VU Sports + HEC Digital Library + VU Lecture Videos + We Care