1.

Write a function in C++ to add more new objects at the bottom of a binary file "STUDENT.dat", assuming the binary file is containing the objects of the following class :class STU{int Rno;char Sname[20];public: void Enter(){cin>>Rno;gets(Sname);}void show(){count << Rno<<sname<<endl;}};

Answer»

void Addrecord()

{

ofstream ofile;

ofile.open("STUDENT.dat", ios ::out);

STU S;

char ch='Y';

while (Ch=='Y' || Ch = = 'y')

{

S.Enter();

ofile.write (Char*) & S, sizeof(s));

cout << "more (Y/N)";

cin>>ch;

}

ofile.close();

}



Discussion

No Comment Found

Related InterviewSolutions