1.

Write a function display() in ++ to display all the students who have got a distinction (scored percentage more than or equal to 75) from a binary file “stud.dat”, assuming the binary file is containing the objects of the following class:class student { int rno; char sname[20]; int percent; public: int retpercent() { return percent; } void getdetails() {cin>>rno;gets(sname);cin>>percent;} void showdetails(){ cout<< rno;puts(sname); cout<<percent; } };

Answer»

void display()

student s; 

ifstream i(stud.dat"); 

while(i .read((char*)&s, sizeof(s))) 

if(s.retpercent()>=75) s.showdetails():

i.close(); 

}



Discussion

No Comment Found

Related InterviewSolutions