Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
8.8k views
in Computer by (69.4k points)

Write a function in C++ to search and display details. of all trains, whose destination is “Delhi” from a binary file “TRAIN.DAT”. Assuming the binary file is containing the objects of the following class.

class TRAIN

{ int Tno;     // Train Number

char From[20];   // Train Starting Point

char To[20]; // Train Destination

public:

 char* GetFrom (){return From;}

 char* GetTo (){return To;}

 void Input () {cin>>Tno;gets(From);gets(To);}

 void Show () {cout<<Tno<<:<<From<<:<<To<<endl;}

};

1 Answer

0 votes
by (61.3k points)
selected by
 
Best answer

void Read ( )

{ TRAIN T;

ifstream fin;

fin. open (TRAIN.DAT, ios::binary);

while(fin.read((char*)&T, sizeof(T)))

{

if(strcmp(T.GetTo() ,Delhi)==O)

T.Show() ;

}

fin.close(); //Ignore

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...