Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below with appropriate functions for the required task.
class Customer {
long int CNo; //Customer Number
char CName[20]; //Customer Name
char Email[30]; //Email of Customer
public :
void Allocate(); //Function to allocate a member
void Show(); //Function to show customer data
void ModifyEmail() //Function to modify Email ,
{ cout<<"Enter Modified Email:";
gets(Email);
}
long int GetCno( ) {return CNo;}
};
void ChangeData( )
{
fstream File;
File.open ("CUST.DAT", ios: :.binary | ios: :in|ios: :out);
int Change=0, Location; long int ChangeCno;
cout<<"Cno - whose email required to be modified:"; cin>>ChangeCno;
Customer CU;
while(Modify && File,read((char*)&CU, sizeof(CU)))
{
if (CU.GetCno()==ChangeCno)
{
CU.ModifyEmail ();
Location=File.tellg()- sizeof(CU);
//Statement 1: To place file pointer to the required position
//Statement 2: To write the object CU on to the binary file
Change ++;
}
}
if (Change)
cout<<"Email Modified... "<
else
cout <<"Customer not found... "<
File. close();
}
Answer -
Statement 1:
File.seekp (-l*size of (CU), ios ::cur);
Statement 2:
File.write ((char*)&CU, sizeof (CU));
Comment(S)
Show all Coment
Leave a Comment