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
2.4k views
in Computer by (69.4k points)
recategorized by

Write a function in C++ to read and display the detail of all the users whose status is ‘A’ (i.e. Active) from a binary file “USER.DAT”. Assuming the binary file “USER.DAT” is containing objects of class USER, which is defined as follows:

class USER {

int Uid;  // User Id 

char Uname[20];  // User Name

char Status; // User Type: A Active

public:

void Register( );  // Function to enter the content 

void show( );  // Function to display all data members char Getstatus( )

{ return Status; }

};

1 Answer

+1 vote
by (61.3k points)
selected by
 
Best answer

void DisplayActive( )

{

USER U; 

 ifstream fin; 

 fin.open(“USER.DAT”, ios:: binary);

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

{  if (U.Getstatus( ) = = ‘A’) U.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

...