Академический Документы
Профессиональный Документы
Культура Документы
#include<iomanip.h>
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<ctype.h>
struct PASS
{
char pno[10],nm[15],flight[15],
airline[15],it[10];
float pr;
};
fstream pfile;
PASS prec;
void menu()
{
clrscr();
gotoxy(35,3);cout<<"Main Menu\n";
for(int x=0;x<80;x++)cout <<"=";
gotoxy(30,5);cout<<"N. To Create New File";
gotoxy(30,6);cout<<"A. To Append records ";
gotoxy(30,7);cout<<"M. To Modify Records";
gotoxy(30,8);cout<<"D. To Delete Records";
gotoxy(30,9);cout<<"P. To Print all records";
gotoxy(30,10);cout<<"S. To Process any Record";
gotoxy(30,11);cout<<"X. To Exit\n";
for(x=0;x<80;x++)cout <<"=";
gotoxy(32,13);cout<<"Enter choice : ";
}
void new_file()
clrscr();
gotoxy(35,4);cout<<"Data Entry\n";
for(int x=0;x<80;x++) cout<<"=";
gotoxy(25,7);cout<<"Enter passport number : ";
cin>>prec.pno;
gotoxy(25,8);cout<<"Enter Passenger Name : ";
cin>>prec.nm;
gotoxy(25,9);cout<<"Enter Flight Number : ";
cin>>prec.flight;
gotoxy(25,10);cout<<"Enter Airline Name : ";
cin>>prec.airline;
gotoxy(25,11);cout<<"Enter Name of Item : ";
cin>>prec.it;
gotoxy(25,12);cout<<"Enter Price of Item : ";
cin>>prec.pr;
pfile.write((char *)&prec,sizeof(prec));
for(x=0;x<80;x++) cout<<"=";
gotoxy(25,15);cout<<"Feed more records [y/n] : ";
cin>>ans;
}
while(toupper(ans) !='N');
pfile.close();
void append()
{
// appending record on the data file..............
pfile.open("Pass.dat",ios::app|ios::binary);
char ans;
do
{
clrscr();
gotoxy(35,4);cout<<"Data Entry\n";
for(int x=0;x<80;x++) cout<<"=";
gotoxy(25,7);cout<<"Enter passport number : ";
cin>>prec.pno;
gotoxy(25,8);cout<<"Enter Passenger Name : ";
cin>>prec.nm;
gotoxy(25,9);cout<<"Enter Flight Number : ";
cin>>prec.flight;
gotoxy(25,10);cout<<"Enter Airline Name : ";
cin>>prec.airline;
gotoxy(25,11);cout<<"Enter Name of Item : ";
cin>>prec.it;
gotoxy(25,12);cout<<"Enter Price of Item : ";
cin>>prec.pr;
pfile.write((char *)&prec,sizeof(prec));
for(x=0;x<80;x++) cout<<"=";
gotoxy(25,15);cout<<"Feed more records [y/n] : ";
cin>>ans;
}
while(toupper(ans) !='N');
pfile.close();
}
void modi()
{
int rec=0,x;
char ans;
pfile.open("Pass.dat",ios::in|ios::ate|ios::binary);
int n=pfile.tellg()/sizeof(prec);
pfile.close();
do
{
clrscr();
cout<<"\nTotal Number of Records in data file are : "<<n;
pfile.open("Pass.dat",ios::in|ios::ate|ios::out|ios::binary);
cout<<"\n\nEnter record number to update
: ";
cin>>rec;
if (rec<1 || rec>n)
{
cout<<"Record is invalid.........";
getch();
}
else
{
clrscr();
pfile.seekg((rec-1)*sizeof(prec));
pfile.read((char *)&prec,sizeof(prec));
gotoxy(35,5);cout<<"Updation Service\n";
for(x=0;x<80;x++) cout<<"=";
gotoxy(25,7);cout<<"Old Record";gotoxy(55,7);cout<<"New
Record\n";
for(x=0;x<80;x++) cout<<"=";
}
for(x=0;x<80;x++) cout<<"=";
gotoxy(22,20);
cout<<"Update any other record ? [y/n] : ";
cin>>ans;
pfile.close();
}
while( toupper(ans) != 'N');
void del()
{
int rec=0,x;
char ans,choice;
pfile.open("Pass.dat",ios::in|ios::ate|ios::binary);
int n=pfile.tellg()/sizeof(prec);
pfile.close();
do
{
clrscr();
cout<<"\nTotal Number of Records in data file are : "<<n;
pfile.open("Pass.dat",ios::in|ios::ate|ios::out|ios::binary);
cout<<"\n\nEnter record number to Delete
: ";
cin>>rec;
if (rec<1 || rec>n)
{
cout<<"Record is invalid.........";
getch();
}
else
{
pfile.seekg((rec-1)*sizeof(prec));
pfile.read((char *)&prec,sizeof(prec));
clrscr();
gotoxy(35,5);cout<<"Deletion Service\n";
for(x=0;x<80;x++) cout<<"=";
gotoxy(35,7);cout<<"Ordered Record\n";
for(x=0;x<80;x++) cout<<"=";
switch(choice)
{
case '1':
char tpno[10]="*";
strcat(tpno,prec.pno);
strcpy(prec.pno,tpno);
pfile.seekp((rec-1)*sizeof(prec),ios::beg);
pfile.write((char *)&prec,sizeof(prec));
pfile.close();
break;
case '2':
fstream tfile;
tfile.open("temp.dat",ios::out|ios::binary);
pfile.seekg(0);
int c=1;
while(pfile.read((char *)&prec,sizeof(prec)))
{
if( c!=rec)
{
cout<<"\nwriting temp file........";//getch();
tfile.write((char *)&prec,sizeof(prec));
}
c=c+1;
pfile.close();
tfile.close();
n=n-1;
tfile.open("temp.dat",ios::in|ios::binary);
pfile.open("Pass.dat",ios::out|ios::binary);
cout<<"\nOpening Tfile & pfile & .......";
while(tfile.read((char *)&prec,sizeof(prec)))
{
pfile.write((char *)&prec,sizeof(prec));
void print()
{
int rec=0;float cr,cc=0.0,net_amt=0.0;
char ans;
pfile.open("Pass.dat",ios::in|ios::ate|ios::binary);
int n=pfile.tellg()/sizeof(prec);
pfile.close();
do
{
clrscr();
cout<<"\nTotal Number of Records in data file are : "<<n;
pfile.open("Pass.dat",ios::in|ios::ate,ios::binary);
if (toupper(ans)=='Y')
{
for(int x=0;x<80;x++) cout<<"=";
cout<<"\nPassPort Number :
"<<setw(10)<<prec.pno<<setw(35)<<"Passenger Name :
"<<setw(10)<<prec.nm<<endl<<endl;
cout<<"\nFlight Number
:
"<<setw(10)<<prec.flight<<setw(35)<<"Airlines
:
"<<setw(10)<<prec.airline<<endl<<endl;
cout<<"\nName of Item
:
"<<setw(10)<<prec.it<<setw(35)<<"Item Price
:
"<<setw(10)<<prec.pr<<endl<<endl;
cout<<"\nCustom Rate
:
"<<setw(10)<<cr<<setw(36)<<"Custom Cahrges
:
"<<setw(10)<<cc<<"\n\n\n";
cout<<setw(45)<<"Net Payable Amount : "<<net_amt<<"\n";;
for(x=0;x<80;x++) cout<<"=";
}
}
//getch();
cout<<"\n\n";
cout<<setw(50)<<"Print any other record [y/n] : ";
cin>>ans;
pfile.close();
}
while( toupper(ans) != 'N');
}
void All()
{
pfile.open("Pass.dat",ios::in|ios::binary);
while(pfile.read((char *)&prec,sizeof(prec)))
{
cout<<prec.pno<<"
"<<prec.nm<<prec.airline<<prec.flight<<prec.it<<prec.pr<<endl;
}
pfile.close();
getch();
}
void main()
{
PASS prec;
char ans,ch;
do
{
menu();
cin>>ch;
clrscr();
switch(toupper(ch))
{
case 'N' : new_file();
break;
case 'A' : append();
break;
case 'M' : modi();
break;
case 'D' :
del();
break;
case 'S' :
print();
break;
case 'P' :
All();
break;
}
while(toupper(ch) !='X');
//getch();
Sample output:
Main Menu
====================================================
N. To Create New File
A. To Append records
M. To Modify Records
D. To Delete Records
P. To Print all records
S. To Process any Record
X. To Exit
====================================================
Enter choice : n
Data Entry
====================================================
Enter passport number : 100098650
Enter Passenger Name : karan
Enter Flight Number : 121
Enter Airline Name : jet
Enter Name of Item : bags
Enter Price of Item : 20000
====================================================
Feed more records [y/n] : n
: 1
Passenger Name :
karan
Flight Number
121
Airlines
Name of Item
bags
Item Price
Custom Rate
25
Custom Cahrges
jet
20000
5000