Write a definition for function COUNTPICS ( ) in C++ to read each object of a binary file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS, which is defined below:
class PHOTOS
{
int PCODE;
char PTYPE[20]; //Photo Type as “PORTRAIT”,”NATURE”
public:
void ENTER()
{
cin>>PCODE;gets(PTYPE);
}
void SHOWCASE()
{
cout<<PCODE<<':'<<PTYPE<<endl;
}
char *GETPTYPE(){
return PTYPE;
}
};
void COUNTPICS( )
{
int count = 0;
PHOTOS obj;
ifstream fp1;
fp1.open('PHOTOS.DAT', ios::binary);
while (fp1.read((char*)&obj, sizeof(obj)))
{
if(strcmp(obj.GETPTYPE(),'PORTRAIT')==0){
count++;
}
}
cout<<'The total number of PHOTOS of type PORTRAIT is '<<count;
fp1.close();
}