Sponsored Links


Results 1 to 6 of 6

Thread: CS201 Introduction to ProgrammingAssignment No. 03 Semester Fall 23 December 2011

  1. #1
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578

    18 CS201 Introduction to ProgrammingAssignment No. 03 Semester Fall 23 December 2011

    Sponsored Links1


    Problem Statement: Flight Reservation System

    Write a program for Flight Reservation System which reserves the tickets for passengers of an Air Line according to their requirements.

    Detailed Description:

    In the program, you are required to make a structure with name 'Reservation' and following are the data members of structure.

     Passenger Name
     Passenger Address
     Date of flight
     Destination to travel
     Flight No
     Seat No

    In the main() function, create of variable of type Reservation. The variable of type Reservation should be created dynamically using memory allocation function. After that, create following user defined function as discussed below:

    GetData(), this function will set the values of above created structure variable according to the inputs taken from user. It will prompt user to enter required information for the, Passenger Name, Passenger Address, Destination, Date of flight. User will be provided three options for the destination that is: Karachi, Lahore and Peshawar.

    Assigning Flight No and Seat No:

    The user will chose one of three destinations and program will assign an appropriate Flight No for the passenger. The Flight No will be assigned as below:

    Destination Flight No.
    Karachi 201
    Peshawar 233
    Lahore 241

    After Assigning Flight No, the Seat No. will be assigned randomly which can be any number from 0 to 200.

    After assigning the values for the above created variable of Reservation structure, the structure will be passed to another user defined function WriteData() for writing it to the file.


    In the function WriteData(), you are required to create a new text file name “data.txt” in same folder/directory where you have saved your .cpp file. Open this file by using file handling functions and then write all Reservation information in that file.

    At the end, read all the data from file by creating a function named ReadData() and display the file contents on the screen.


    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.
    Attached Files Attached Files

  2. #2
    Junior Member
    Join Date
    Dec 2011
    Posts
    2
    is ka solution kab tak aye ga ?

  3. #3
    Administrator
    Join Date
    Oct 2011
    Posts
    468
    jab ban jay ga tab ah jay ga. don't worry.
    03009520262
    Rabeel Website

  4. #4
    jab date guzer jay gi..

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    7
    plz solution bhej dyn main ny slove krny ki koshish but i can't do.

  6. #6
    Administrator Vuhelper's Avatar
    Join Date
    Apr 2011
    Posts
    9,578
    Code:
    <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <fstream.h>
    using namespace std;
    int random(int i)
    {
    return rand()%i; }
    struct Reservation
    {
    string Passenger_Name;
    string Passenger_Address;
    string Date_of_Flight;
    string Destination_to_travel;
    int Flight_No;
    int Seat_No; };
    void GetData(Reservation[],int);
    void WriteData(Reservation[], int);
    void ReadData(Reservation[], int);
    main()
    {
    Reservation *res;
    
    Quote:#include
    
    int i;
    cout<<"How many reservation you want: ";
    cin>>i;
    res = new Reservation[i];
    GetData(res, i);
    system("pause"); }
    void GetData(Reservation st[], int nn)
    {
    string n;
    char ch;
    int l;
    for(int j=1;j<=nn;j++)
    {
    cout<<"Enter Passenger Name for Passenger "<<j<<" : ";
    cin>>n;
    st[j-1].Passenger_Name=n;
    cout<<"Enter Passenger Address for Passenger "<<j<<" : ";
    cin>>n;
    st[j-1].Passenger_Address=n;
    cout<<"Enter Date of Flight for Passenger "<<j<<" : ";
    cin>>n;
    st[j-1].Date_of_Flight=n;
    cout<<"Enter Destination_to_travel for
    Passenger "<<j<<" : ";
    cout<<"Please Select from given"<<endl;
    cout<<"k for karachi"<<endl;
    cout<<"p for peshawar"<<endl;
    cout<<"L for lahore"<<endl;
    cin>>ch;
    if( ch == 'p')
    {
    
    st[j-1].Destination_to_travel="Peshawar";
    st[j-1].Flight_No=233;
    st[j-1].Seat_No=random(200); }
    if( ch == 'k')
    {
    st[j-1].Destination_to_travel="Karachi";
    st[j-1].Flight_No=201;
    st[j-1].Seat_No=random(200); }
    if( ch == 'l')
    {
    st[j-1].Destination_to_travel="Lahore";
    st[j-1].Flight_No=241;
    st[j-1].Seat_No=random(200); }
    else if( !(ch == 'p' || ch == 'k' || ch == 'l'))
    {
    cout<<"Please select from list:"<<endl; } }
    WriteData(st, nn); }
    void WriteData(Reservation abc[], int nn)
    {
    ofstream myfile ("abc.txt");
    if (myfile.is_open())
    {
    for(int j=1;j<=nn;j++)
    {
    myfile <<abc[j-1].Passenger_Name<<endl;
    myfile <<abc[j-1].Passenger_Address<<endl;
    myfile <<abc[j-1].Date_of_Flight<<endl;
    myfile <<abc[j-1].Destination_to_travel<<endl;
    myfile <<abc[j-1].Flight_No<<endl;
    myfile <<abc[j-1].Seat_No<<endl; }
    myfile.close(); }
    
    else cout << "Unable to open file";
    ReadData(abc, nn); }
    void ReadData(Reservation[], int)
    {
    string line;
    ifstream myfile ("abc.txt");
    if (myfile.is_open())
    {
    while ( myfile.good() )
    {
    getline (myfile,line);
    cout << line << endl; }
    myfile.close(); }
    else cout << "Unable to open file";
    
    }


    Sponsored Links

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-31-2013, 03:44 PM
  2. CS201 Introduction to Programming Assignment No.3 Fall Semester 2013
    By Vuhelper in forum Assignments & Solutions
    Replies: 0
    Last Post: 01-12-2013, 04:08 PM
  3. Replies: 0
    Last Post: 11-12-2012, 02:00 PM
  4. CS201 Introduction to Programming Quiz No.1 Fall Semester 2012
    By Vuhelper in forum MCQ's & Quiz Discussion
    Replies: 0
    Last Post: 11-08-2012, 01:56 PM
  5. Replies: 0
    Last Post: 10-31-2012, 11:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft