Page 188 - C++
P. 188

}



                                                             OR

        (b ) Given a binary file PHONE.DAT, containing records of the following class type:                  (3)

        class Phonelist

        {

               char name[20];

               char address[30];

               char areacode[5];

               char Phoneno[15];

        public:

               void Register();
               void Show();


               void CheckCode(char AC[])
               {


                       return(strcmp(areacode,AC);
               }

        };

        Write a function TRANSFER( ) in C++, that would copy all those records which are having areacode as “DEL”
        from PHONE.DAT to PHONBACK.DAT.

        Ans

        void TRANSFER()
        {
               fstream File1,File2;
               Phonelist P;
               File1.open(“PHONE.DAT”, ios::binary|ios::in);
               File2.open(“PHONEBACK.DAT”, ios::binary|ios::OUT);
               while(File1.read((char *)&P, sizeof(P)))
               {
                       if( p.CheckCode( “DEL”))
                              File2.write((char *)&P, sizeof(P));
               }
               File1.close();
               File2.close();
        }
   183   184   185   186   187   188   189   190   191   192   193