Phonlist ph; Fin.open(“PHONE.DAT”, ios::in | ios::binary); Fout.open(“PHONBACK.DAT”, ios::out | ios:: binary); while(Fin.read((char*)&ph, sizeof(ph))) { == 0) sizeof(ph)); } Fout.close(); } Q3. Write a function in C++ to modify the name of a student whose roll number is entered during the execution of the program. Search the accepted roll number from a binary file and modify the name, assuming the binary file is containing the objects “STUDENT.DAT” of the following class. class STUD { Ans : void Modifyname() { fstream File; File.open(“STUDENT.DAT”, ios::binary | ios::in | ios::out); STUD s; int mrno; int Rno; char cout<<”\nEnter the roll number to modify : “; Name[20]; cin>>mrno; while (File.read((char*)&s, sizeof(s))) int srno(){ { return Rno;} if(s.srno() = = mrno) { void cout<<”\n Modify the name s.Enter(); “; File.seekp( * sizeof(s), void –1 ios::cur); File.write((char *)&s, sizeof(s)); }File.close() ; } };
Phonlist ph; Fin.open(“PHONE.DAT”, ios::in | ios::binary); Fout.open(“PHONBACK.DAT”, ios::out | ios:: binary); while(Fin.read((char*)&ph, sizeof(ph))) { == 0) sizeof(ph)); } Fout.close(); } Q3. Write a function in C++ to modify the name of a student whose roll number is entered during the execution of the program. Search the accepted roll number from a binary file “STUDENT.DAT” and modify the name, assuming the binary file is containing the objects of the following class. class STUD { int Rno; char Name[20]; int srno(){ return Rno;} void void }; Ans : void { Modifyname() fstream File; File.open(“STUDENT.DAT”, ios::binary | ios::in | ios::out); STUD s; int mrno; cout<<”\nEnter the roll number to modify : “; cin>>mrno; while (File.read((char*)&s, sizeof(s))) { if(s.srno() = = mrno) { cout<<”\n Modify the name “; s.Enter(); File.seekp( –1 * sizeof(s), ios::cur); File.write((char *)&s, sizeof(s)); }File.close() ; }
Compt%20Sci.docx