how to solve sir/maam?
#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<<endRead more
#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; }
See less
thank you sir
thank you sir
See less