Write a function in C++ to search for the details (Phoneno and Calls) of those Phones, which have more than 800 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class Phone, which is defined below.
class Phone
{
char Phoneno[10]; int Calls;
public:
void Get( )
{
gets(Phoneno); cin>>Calls;
}
void Billing( )
{
cout<<Phoneno<<'#'<<Calls<<endl;
}
int GetCalls( )
{
return Calls;
}
};
void search ()
{
Phone pObj;
ifstream ifs;
ifs.open('phones.dat',ios::binary);
while(ifs.read((char*)&pObj,sizeof(pObj)))
{
if(pObj.GetCalls()>=800)
pObj.Billing();
}
ifs.close();
}