Advertisement Remove all ads

Write a Definition for Function Costly() in C++ to Read Each Record of a Binary File Gifts.Dat, Find and Display Those Items, Which Are Priced More than 2000. Assume that the File Gifts.Dat is Created with the Help of Objects of Class Gifts, Which is Defined Below - Computer Science (C++)

Write a definition for function COSTLY() in C++ to read each record of a binary file GIFTS.DAT, find and display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below

c1ass GIFTS
{
   int CODE; char ITEM[20]; f1oat PRICE;
pub1ic:
   void Procure()
  {
       cin>>CODE; gets (ITEM);cin>>PRICE;
  }
  void View()
  {
      cout<<CODE<<":"<<ITEM<<":"<<PRICE<<end1;
  }
  f1oat GetPrice () {return PRICE;}
};
Advertisement Remove all ads

Solution

void COSTLY()
{
    GIFTS G;
    ifstream fin("GIFTS.DAT",ios::binary);
    while(fin.read((char *)&G,sizeof(G)))
    {
        if(G.GetPrice()>2000)
           G.View();
    }
    fin.close();
}
Concept: Binary File in C++ :- Creation of File, Writing Data into File, Searching for Required Data from File, Appending Data to a File, Insertion of Data in Sorted File, Deletion of Data from File, Modification of Data in a File
  Is there an error in this question or solution?
Advertisement Remove all ads
Advertisement Remove all ads
Advertisement Remove all ads
Share
Notifications

View all notifications


      Forgot password?
View in app×