Skip to main content

::: vuaskari.com :::

// declaration for header files
#include<iostream>
#include<fstream>
#include<conio.h>
#include<string>

// declaration of structure Reservation
struct Reservation
{
// declaration for structure members

char PassName[20]; // character array to store passenger name
char PassAdd[30]; // character array to strong passenger address
char TravelDate[15]; // character array to store passenger travel date
char Destination[10]; // array to store destination to travel

int SeatNo; // variable for storing seat number
int FlightNo; // variable for storing flight number
};

Reservation GetData(); // function declaration for taking the reservation input from user
void WriteData(Reservation *); // function declaration for writing the reservation information in file
void ReadData(); // function declaration for reading the data from the file

Reservation *rs; // declaring a pointer to structure Reservation
fstream myFile; // file handler for file input/ output operations

main()
{
// variable to taking the choice from the user
int choice;

// dynamic memory allocation for structure pointer rs
rs = (struct Reservation *)malloc(sizeof(struct Reservation));

// checking if memory was allocated or not
if (rs == NULL)
{
cout << "Unable to allocat space in the memory";
return 1;
}

// initializing the structure with default values
strcpy(rs->PassName," ");
strcpy(rs->PassAdd," ");
strcpy(rs->TravelDate," ");
strcpy(rs->Destination," ");
rs->SeatNo = 0;
rs->FlightNo = 0;

bool quit = false;

cout << "\n\t<Flight Reservation System>"<<endl;

// menu for flight reservation system
do
{
cout << endl << endl;

cout << " Main Menu" << endl << endl;
cout << " 1 - Reserve a Seat" << endl
<< " 2 - Display the Records" << endl
<< " 3 - Quit the Program" << endl << endl;

cout << " Enter your choice: ";
cin >> choice;

cin.ignore(1000, '\n');

// swtich statement for taking the choice for the main menu
switch (choice)
{

case 1:
srand(time(NULL)); // resetting the value in the function rand()
GetData(); // function call for function GetData to take the input from the user
WriteData(rs); // function call for writing reservation info in the file
break;

case 2:
ReadData(); // function for reading the data from the file
quit = true;
break;

case 3:
quit = true; // if choice of the user is 3, then the program will quit
break;

default:
cout << endl << endl;
cout << " Invalid Choice. Try Again." << endl << endl;

}

} while (!quit);

free (rs); // freeing the memory allocated for structure rs

system("pause");

}

// function definition for taking the input from the user

Reservation GetData()
{
cout << "\n\n\t~~~Seat Reservation Menu~~~"<<endl;
cout << "\n <Please enter passenger details>"<<endl<<endl;

cout<<" Passenger Name:\t";
cin.getline(rs->PassName, 20, '\n'); // taking the passanger name from user

cout << endl;

cout << " Pessenger Address:\t";
cin.getline(rs->PassAdd, 30, '\n'); // taking the passanger address from user

cout << endl;

cout << " Date to travel (dd-mm-yyyy):\t";
cin.getline(rs->TravelDate, 15, '\n'); // taking passanger travel date from user

cout << endl;

// choices for destination to travel
cout << " Destination to travel (Choose one of the below given)" << endl << endl;
cout <<" Press 1 for Karachi" <<
endl <<" Press 2 for Peshawar" <<
endl <<" Press 3 for Lahore" << endl << endl;

// variable to take the choice from the user
int des;

cout << " Passenger Destination:\t\t";
cin >> des;

if ( des == 1 )
{
// assigning destination as Karachi to structure member Destination
strcpy(rs -> Destination, "Karachi");

// alloting flight no to the passanger
rs -> FlightNo = 201;

// randomly assigning seat number to the passanger using function rand()
rs -> SeatNo = rand() % 200 + 1;
}

else if ( des == 2 )
{
// assigning destination as Peshawar to structure member Destination
strcpy(rs -> Destination, "Peshawar") ;

// alloting flight no to the passanger
rs -> FlightNo = 233;

// randomly assigning seat number to the passanger using function rand()
rs -> SeatNo = rand() % 200 + 1;
}

else if ( des == 3 )
{
// assigning destination as Lahore to structure member Destination
strcpy(rs -> Destination, "Lahore") ;

// alloting flight no to the passanger
rs -> FlightNo = 241;

// randomly assigning seat number to the passanger using function rand()
rs -> SeatNo = rand() % 200 + 1;
}

else
{
// if user enters any invalid choice then destination is set as unknown
strcpy(rs -> Destination, "Unknown") ;
rs -> FlightNo = 0;
rs -> SeatNo = 0;
}

cout << endl;

// return rs;

}

// function for writing the data into the file

void WriteData(Reservation *r)
{
// creating/opening file named data.txt in the output/append mode
myFile.open("data.txt", ios::out | ios::app );

// moving to the end of the file to perform write operation
myFile.seekp(0L, ios::end);

// checking if file exists or not
if(!myFile)
{
cout << " File does not exist.." << endl;
exit(1); // if file does not exist, then the program quits
}

// writing the reservation info in the file one by one
myFile << "------------------------------------------------------" << endl
<< "Name: " << r->PassName << endl
<< "Address: " << r->PassAdd << endl
<< "Date: " << r->TravelDate << endl
<< "Destination: " << r->Destination << endl
<< "Flight No: " << r->FlightNo <<endl
<< "Seat: " << r->SeatNo << endl
<< "------------------------------------------------------" << endl;

cout << "\n Seat reserved successfully!" << endl;

myFile.close(); // closing the file after write operation is done
}

// function definition for reading the data from the file

void ReadData()
{
// opening the file named data.txt in input mode

myFile.open("data.txt", ios::in);

// moving the file pointer to the beginning of the
myFile.seekg(0L, ios::beg);

// checking if file is opened or not
if(!myFile)
{
cout << "\n\n Error opening file or file does not exist.."<<endl;
cout << " Program is terminating....."<<endl;
getch();
exit(1);
}

// this else part of if statement is executed if file is successfully opened
else
{

const int MAX_CHAR_TO_READ = 100; // maximum character to read in one line
char completeLineText[MAX_CHAR_TO_READ]; // to be used in getline function

cout << "\n\n Seat Reservation record(s) are under" << endl << endl;

// Reading the complete file line by line and printing on screen
while (!myFile.eof())
{
myFile.getline(completeLineText, MAX_CHAR_TO_READ); // reading the data from the file
cout << completeLineText << endl; // writing the data to the output stream
}
}

cout << " Thank you for using the program...\n\n";

myFile.close(); // closing the file

}
can anyone tell me why this is not compile i removed .h extension from
header file and when im going to compile it gives an error screen shot
of that error is attached
--


**lavender**

--
We say, "Be one as Pakistani Nation and grow up for Pakistan's Future". Wish you all the best. Join www.vuaskari.com,
To post to this group, send email to vuaskari_com@googlegroups.com
Visit these groups:
This (Main) Group:http://groups.google.com/group/vuaskari_com?hl=en?hl=en
MIT/MCS
Group: http://groups.google.com/group/vu_askarimit?hl=en?hl=en
HRM Group: http://groups.google.com/group/askari_hrm?hl=en?hl=en
Banking Group: http://groups.google.com/group/askari_banking?hl=en?hl=en
Management: https://groups.google.com/group/vuaskari_mgt?hl=en
Marketing: https://groups.google.com/group/vuaskari_mkt?hl=en
MIS Group: http://groups.google.com/group/askari_mis?hl=en

Comments

Popular posts from this blog

[vu-students] Urdu Love Letters ............ ahahahahahhahahah

  The One & Only .......... IRFAN. Italy. http://groups.yahoo.com/group/p_se_poetry   -- You received this message because you are subscribed to the Google Groups "VU Students" group. To post to this group, send email to vu-students@googlegroups.com To unsubscribe from this group, send email to vu-students+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/vu-students?hl=en_PK?hl=en

Re: ::: vuaskari.com ::: Fwd: Cancer treatment- Shocking news.

plz send me the soloution of Assignment MGT-603 and MKT-624 plzzzzzzzzz today last day i need urgent 2011/4/23 ∂υα ωαqαя < dua4566@gmail.com > ---------- Forwarded message ---------- From: Virtual Brain < mc090400181@gmail.com > Date: Sat, Apr 23, 2011 at 10:30 AM Subject: Cancer treatment- Shocking news. AS  one of my friend tell me all this PLEASE FORWARD THIS MAIL.  Dear All, One of my cousin got   lung cancer   few months back. That was really shocking to all his family members. Cancer diagnosed was of stage three. Immediately treatment was started from Pakistan most of the art hospital for cancer i.e. Shoukat Khanum Hospital in Lahore. But there were little chances to reverse the disease as it's already reached to stage 3. Than one day somebody told us about a person in Distt Nowshera who is treating cancer by herbs. We went there and he gave us some   herbal medicines   for ten days. It was really amazing when we saw an improvement in the condition of my...

Re: ::: vuaskari.com ::: MCS Students Group

please send me solution of mth 202 quiz 1 On Sun, May 11, 2014 at 8:51 PM, Muhammad Asif < itsvividmirror@gmail.com > wrote: cs 604 605 607 610 catring stock On Thu, May 8, 2014 at 4:32 PM, Malik Aslam < malik693012@gmail.com > wrote: I am also student of MCS.  On Wed, May 7, 2014 at 3:50 PM, Zadee Ali < abdullah.313.27@gmail.com > wrote: i have also these subjects. On Tue, May 6, 2014 at 1:26 PM, Shahzad Ali < saim2.vti@gmail.com > wrote: i am mcs student 3rd semester On Tue, Apr 29, 2014 at 12:02 PM, Jasmine Khan < jasmine.khan3939@gmail.com > wrote: I can help. On Apr 29, 2014 9:36 AM, "Nadeem Abbas (BP/Acc)" < nadeem.abbas@haleebfoods.com > wrote: > > Is there any or more students of the following subjects of MCS and want to do combine study and help each others? > >   > > CS304-OOP > > CS401-Assembly > > CS607-AI > > CS614-Data W/H > > ...