cs201 Assignment No. 04

Assignments ,Quiz, Solved GDB

Moderator: abdulsaboor

Post Reply
sameea
Visitor
Visitor
Posts: 30
Joined: Tue Oct 25, 2011 10:47 am

cs201 Assignment No. 04

Post by sameea »

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.
sameea
Visitor
Visitor
Posts: 30
Joined: Tue Oct 25, 2011 10:47 am

Re: cs201 Assignment No. 04

Post by sameea »

any one help plz......
User avatar
abdulsaboor
ADMIN
ADMIN
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan
Contact:

Re: cs201 Assignment No. 04

Post by abdulsaboor »

For security, publicity, owner ship issues, solution will be uploaded last day.
So no one can use it in their own names
keep looking. :o
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
User avatar
abdulsaboor
ADMIN
ADMIN
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan
Contact:

CS201 Assignment No. 04

Post by abdulsaboor »

AOA,
Please download and unzip the attached file which contains a compiled exe file for you to check it working, a screenshot to see it working, and main.cpp file which contains the source code.
I have used Visual C++ 6 so if you get any problem with other compilers or any other issue, do let me know, I will fix Insha Allah.
Attachments
screenshot.JPG
screenshot.JPG (45.9 KiB) Viewed 13734 times
Assign.zip
(153.76 KiB) Downloaded 787 times
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
sameea
Visitor
Visitor
Posts: 30
Joined: Tue Oct 25, 2011 10:47 am

Re: cs201 Assignment No. 04

Post by sameea »

thanks sir for help me

and i not see any one more send the this assignment or not .
:(
sara raja
Visitor
Visitor
Posts: 1
Joined: Mon Jan 16, 2012 6:15 pm

Re: cs201 Assignment No. 04

Post by sara raja »

ful in error
#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 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);
Come and Join Us at www.vustudents.ning.com 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";
};
};
Come and Join Us at www.vustudents.ning.comint main()
{
Schedule *mysdl = new Schedule();
mysdl->getInputData();
mysdl->writeData();

system("pause");
return 0;
}
sameea
Visitor
Visitor
Posts: 30
Joined: Tue Oct 25, 2011 10:47 am

Re: cs201 Assignment No. 04

Post by sameea »

but sara raja ya ap ki assiment ha to theek but class define theek se nahi kay dsdhasfdq werwe is assiment ma ok to first hi theek ha
sameea
Visitor
Visitor
Posts: 30
Joined: Tue Oct 25, 2011 10:47 am

Re: cs201 Assignment No. 04

Post by sameea »

class define ke bad pucblic ma function define karte hain or private ma variable jo ke ap ki assiment ma nahi ho raha to ap theek kar lo ok........
User avatar
abdulsaboor
ADMIN
ADMIN
Posts: 2004
Joined: Fri Sep 28, 2007 3:42 am
Location: vehari-punjab-pakistan
Contact:

Re: cs201 Assignment No. 04

Post by abdulsaboor »

Ms. Sara Raja, I am really impressed by your knowledge of C++, you have destroyed the whole structure :x also you are doing a lot of tiny basic C++ mistakes which don't correlate with your rest of code, Stolen code???
And Ms.Samea You need to clear your concept of Public, Private, Protected in C++.

Any way, in short can you just tell me what issues you have with the file Uploaded, just point out the errors, and If you are capable enough Please why don't you do it and share the solution with us all. That would be great. Haan! ;)
DR ABDUL SABOOR
PHD Scholar at Superior University Lahore- Pakistan
MS Business Administration (HRM)
BS Business Administration (Marketing)
Member Editorial Board Science Publishing Group USA
Member Editorial Board International Journal of Marketing Studies
Cell=0308-6837987

Pakistan
Post Reply