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

::: vuaskari.com ::: cs301

share cs301 midterm papers. -- 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 --- You received this message because you are subscribed to the Google Groups ":::www.vuaskari.com :::" group. To unsubscribe from this group and stop receiving emails from it, send an email to vuaskari_com+unsubscribe@googlegroups.com. ...

::: vuaskari.com ::: Fin622 All Mid Term Papers in just one file ....

just isi se tyari kr lo INSHA ALLAH 80% se above marks aye gay in MCQs....................... its gift for all VU finance students by me........ -- 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