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

Re: ::: vuaskari.com ::: CS408 - FINAL TERM SUBJECTIVE WITH REFERENCE SOLVED BY UMAIR SAULAT

GREAT WORK On Wed, Feb 20, 2013 at 11:30 PM, Umair Saulat < saulat.umair@gmail.com > wrote: CS408- Human Computer Interaction Solved Subjective Fall Semester 2012   QNo.1    it has been observed that most computer users use menu option for input instead of keyboard accelerator. What is the reason behind it? (2 Marks) Answer:- 1.        Menu options are easier to find. 2.        You don't have to memories the keys for menu option but for key board accelerators you have to memories them REF:: Handouts Page No. 127   QNo.2    Define active intervention.  (2 Marks) Answer:- Active intervention with the participant and actively probes the participant understands of whatever is being tested. REF:: Handouts Page No. 276 QNo.3    what is Ubiquitous Computing? (2 Marks) Answer:- The most profound technologies are those that disappear. They weave themselves into the fabric of everyday life until they are indi

Updating our Google Account inactivity policy

Every day Google works hard to keep you and your private information safe and secure by preventing unauthorized access to your Google Account with our built-in security protections. And keeping you safe means having strong privacy practices across our products that minimize how long we store your personal files and any data associated with them. We want to protect your private information and prevent any unauthorized access to your account even if you're no longer using our services. Therefore, we are updating the inactivity period for a Google Account to two years across all our products and services. This change starts rolling out today and will apply to any Google Account that's been inactive, meaning it has not been signed into or used within a two-year period. An inactive account and any content in it will be eligible for deletion from December 1, 2023. What this means for you: These changes do not impact you unless you h

Learn more about our updated Terms of Service

stargthb@gmail.com On January 5, 2022, we're making some changes to our Terms of Service. These changes won't affect the way you use Google services, but they'll make it easier for you to understand what to expect from Google — and what we expect from you — as you use our services. You can review the new terms here . At a glance, here's what this update means for you: More clarity on what you can expect from Google and what we expect from you : We're providing more examples to describe the mutually respectful conduct that we expect from all our users. Improved readability : While our terms remain a legal document, we've done our best to make them easier to understand, including reorganizing some topics so that they're easier to find. If you use Family Link to manage a Google Account for someone else, please take some time to talk to them about these changes. Thank you for using Google!