Study Groups By Subject code Wise (Click Below on your university link & Join Your Subject Group)

[ + VU Study Groups Subject Code Wise ]  [ + COMSATS Virtual Campus Study Groups Subject Code Wise ]

Looking For Something at vustudents.ning.com?Search Here

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

Views: 3773

Replies to This Discussion

Please Discuss here about this assignment.Thanks

Tariq bhai solution plzzzzzzzzzzzzzzzzzzzzzzzz

jazak ALLAH azawajal

wasalam

tariq bhai please share idea solution.

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

not correct  error in run time

upload the ccp file

Here you go Smile Smile but please change it,

Thank u Tariq bhai thank u so much...

Jazak ALLAH azawajal

wasalam

thanxxxxxx Tariq bhai.....

assignment solution

Attachments:

its not complete id my dear

Run time error dono he same han

RSS

Main Forum Discussions By Categories Wise

Latest Activity In Forum

Newest Discussions In Forum

Most Popular Discussion

Latest Activity

Member of The Month

1. +cαρяιcσяη яυℓεs+

Rawalpindi, Pakistan

Picture of The Day

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

Site Info

About Us

48000+ Members

VUSTUDENTS Toolbar

Become a Team Member

Moderators Group

Safety Guidelines for New

Site FAQ & Rules

Safety Matters

Online Safety

Terms of Service

Disclaimer

+ Report an Issue

Advertise with Us

Rules For Blog Post

Prohibited Content On Site

Report a violation

Management: Admins,Moderators

Awards Badges List

Public Us On Google

Like Our Facebook Page

© 2014   Created by + M.Tariq Malik.

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