write a program to write the name, roll number, and marks of `10 students in the file and read the name of student securing highest mark from the file.
Share
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
#include<iostream>#include<cstdlib> #include<fstream> using namespace std; class student { public: char name[20]; int roll; float marks; public: void input( ) { cout<>name; cout<>roll; cout<>marks; } void display( ) { cout<<“\n Name= “<<name<<endl; } }; void writerecords( ) { student s[10]; fstream fout; fout.open(“student.txt”, ios :: out | ios :: app | ios :: binary); cout<<“Enter the info of 10 student for writing into binary file:\n “; for(int i = 0; i<10; i++) { s[ i ].input( ); fout.write((char *)&s[ i ], sizeof(s[ i ])) ; } fout.close( ); } void displayspecificrecord( ) { student s; fstream fin; float highest = 0; fin.open(“student.txt”, ios :: in | ios :: binary); while(fin.read((char *)&s, sizeof(s))) { if(highest < s.marks) highest=s.marks; // here we find out the highest marks among 10 students } fin.close( ); fin.open(“student.txt”, ios :: in | ios :: binary); while(fin.read((char *)&s, sizeof(s))) { if(highest==s.marks) { s.display( ); } } fin.close( ); } int main( ) { int n; while( 1 ) { cout<<“\n 1. Add record: “<<endl; cout<<“2. Display record of student whose mark is highest: “<<endl; cout<<“3. Exit: \n”; cout<>n; switch( n ) { case 1: writerecords( ); break; case 2: displayspecificrecord( ); break; case 3: exit(0); default: cout<<“The choice you entered is wrong: “; } } return 0; }
https://drive.google.com/file/d/1MKNeKBfzAnuWaWvrpJite7ImU209CESF/view?usp=share_link