#include<iostream>
#include<conio.h>
#include<fstream>
#include<stdlib.h>
#include<iomanip>
using namespace std;
class flightDetails
{
double flamt;
char flnum[100], flname[100], flfrom[200], usdestin[200], fltime[100];
int columnID;
char opt;
public:
void fldisplay();
void flgetdata();
};
flightDetails f;
void flightDetails::fldisplay()
{
fstream file2;
file2.open("flightDetails1234.txt",ios::in | ios::out | ios::binary);
if(!file2)
{
cout << "\n File Not Found!!!!";
file2.close();
return;
}
cout << "\n------------------------------------------------------------------------------------------" << endl;
cout << "\n| columnID | "<< "| Flight No |"<< "| From |"<< "| To |"<< "| Flight Time |"<< "| Amount |" << endl;
file2.seekg(0,ios::beg);
while (file2.read((char *)&f, sizeof(f)))
{
cout<< " | " <<columnID << " | " << flnum << " | " << flfrom << " | " << usdestin << " | " << fltime << " | " << flamt << " | " << endl;
cout<< "----------------------------------------------------------------------------------------------------------------------------------------------" << endl;
}
file2.close();
}
void flightDetails::flgetdata()
{
fstream file; //will be able to read and write into the file
int flag = 0;
columnID=1;
file.open("flightDetails1234.txt", ios::in | ios::app | ios::binary);
file.seekp(0, ios::end);
cout << "\n Enter Flight Number: ";
cin>>flnum;
cout << "\n Enter Flight Name: ";
cin>>flname;
cout << "\n Enter Flight From: ";
cin>>flfrom;
cout << "\n Enter Flight destination: ";
cin>>usdestin;
cout<< "\n Enter Flight Time (in HH:MM format): ";
cin>>fltime;
cout << "\n Enter Flight amout: ";
cin >> flamt;
cout << "\n Enter Flight Availability: (A (Available) / N (Not Available)): ";
cin >> opt;
if (opt == 'A' || opt == 'a')
{
if(file)
{
file.seekp(0,ios::end);
file.write((char *)&f,sizeof(f));
//file<<columnID<<setw(10)<<flnum<<setw(20)<<flname<<setw(20)<<left<<flfrom<<left<<usdestin<<left<<setw(20)<<fltime<<left<<setw(20)<<flamt<<endl;
flag = 1;
cout << " Successfully Added into the file...."<<endl;
}
else
{
cout << "Unable to Open / Write into the File." << endl;
}
if (flag == 1)
{
columnID += 1;
}
}
else
cout << "The Flight Is Not Available" << endl;
file.close();
fldisplay();
}
int main(void)
{
cout << "\nWelcom to Airlines Reservation System";
cout << "\n---------------------------------------------------";
f.flgetdata();
system("pause");
return 0;
}
No comments:
Post a Comment