File Handling Assignments
File Handling Assignments
File Handling Assignments
1. Assuming the class DRINKS defined below, write functions in C++ to perform
the following:
(i) Write the objects of DRINKS to a binary file.
(ii) Read the objects of DRINKS from binary file and display them on
screen when DNAME has value "INDY COLA".
class DRINKS
{ int DCODE; char DNAME[13]; //Name of the drink
int DSIZE; //Size in liters
float DPRICE;
public:
void getdrinks( )
{cin>>DCODE>>DNAME>>DSIZE>>DPRICE;}
void showdrinks( )
3. Write a function in C++ to add new objects at the bottom of a binary file
“STUD.DAT”, assuming the binary file is containing the objects of the
following class.
Class STUD {
int Rno; char Name[20];
public:
void Enter(){cin>>Rno;gets(Name);}
void Display(){cout<<Rno<<Name<<endl;} };
public:
void register(); void show();
int checkcode(char AC[]) { return(strcmp(areacode,AC); } };
Write a function COPYABC() in C++ that would copy only those records
having areacode as “123” from TELE.DAT to TELEBACK.DAT.