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?
APPEARS IN
Advertisement Remove all ads