in c++ i have written a simple program, which accepts 4 to 6 records and then do not accept any more when airline_no is same i.e. 1? The source code is:
#include<fstream.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<process.h>
#include<stdio.h>
int lno;
struct airln {int airline_no,routeno,dep_time,arr_time;
char port_d[15],port_a[15],week_day[10]; }r2;
class route
{
public:
void getroute()
{
cout<<"\n\tRoute no.: ";
cin>>r2.routeno;cout<<"\n";
cout<<"\tDay of Departure: ";
gets(r2.week_day);cout<<"\n";
cout<<"\tAirport for departure: ";
gets(r2.port_d);cout<<"\t";
cout<<"Departure Time: ";
cin>>r2.dep_time;cout<<"\n";
cout<<"\tAirport for arrival: ";
gets(r2.port_a);cout<<"\t";
cout<<"Arrival Time: ";
cin>>r2.arr_time;cout<<"\n";
cout<<"\n\tAirline no.: ";
cin>>r2.airline_no;
}
void display_route()
{
cout<<"\n Route No : ";cout<<r2.routeno;
cout<<"\n ";
cout<<r2.port_d;cout<<"\t";
cout<<r2.dep_time;cout<<"\t\t";
cout<<r2.port_a;cout<<" \t";
cout<<r2.arr_time;cout<<"\t\t";
cout<<r2.week_day;cout<<"\n";
}
}r3;
void main()
{
clrscr();
int airlnno,rtnodel,cntr;
char airlinename[30];
ifstream fin,fin1;
ofstream fout;
do
{
cout<<"\t1. Insert Data.\n";
cout<<"\t2. View Data.\n";
cout<<"\t3. Exit.\n";
cout>>"\tEnter Choice : ";cin>>cntr;
switch(cntr)
{
case 1:r3.getroute();
fout.open("testdata.dat",ios::app);
if(!fout)
{
gotoxy(25,10);
cout<<"No file exists or file can\'t be opened\n";
gotoxy(25,22);
cout<<"Please Press Any Key to Continue.......";
getch();
clrscr();
}
fout.write((char *) &r2,sizeof(r2));
fout.close();
clrscr();
break;
case 2:fin.open("testdata.dat",ios::in);
if(!fin)
{
gotoxy(25,20);
cout<<"No file exists or file can\'t be opened\n";
gotoxy(25,22);
cout<<"Please Press Any Key to Continue.......";
getch();
clrscr();
break;
}
cout<<"\n Dep-Airport\t";
cout<<"Dep-Time\t";
cout<<"Arr-Airport\t";
cout<<"Arr-Time\t";
cout<<"Week Day\n";
fin.read((char *) &r2,sizeof(r2));
while(!fin.eof())
{
r3.display_route();
fin.read((char *) &r2,sizeof(r2));
}
fin.close();
gotoxy(25,22);
cout<<"Please Press Any Key to Continue.......";
getch();
clrscr();
}
} while(!(cntr==3));
}