Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.

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.

Views: 4029

Replies to This Discussion

plz submit correct assignment Solution 

bhai this is only idea now u have to make correct assignment

One more idea solution

CS201 Assignment No 4 Solution

Attachments:

One more idea solution of CS201 Assignment No 4 

See the attached ZIP Folder please

Attachments:

#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;
}

RSS

Looking For Something? Search Below

VIP Member Badge & Others

How to Get This Badge at Your Profile DP

------------------------------------

Management: Admins ::: Moderators

Other Awards Badges List Moderators Group

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service