Hi ! Studying late night...
01:29 am

Sponsor Area

Sponsor Area

Question is

Observe the program segment given below carefully and the question that follow:

class Stock
{
	int	Ino,Qty; char Item[20];
public:
	void Enter() {cin>>In0;gets(Item); cin>>Qty;}
	void Issue(int Q) { Qty+=Q}
	void Purchase(int Q) { Qty-=Q}
	int GetIno(return Ino;)
};
void Purchaseitem(int Pino, int PQty)
{
	fstream file;
	File.open('STOCK.DAT',ios::binary|ios::in|ios::out);
	Stock S;
	int Success=0;
	while (Success==0 && File.read((char*)&S, sizeof(S)))
	{
		if (Pino==S.GetIno())
		{
			S.Purchase(PQty);
			File.seekp(Success);	            //Statement 1
			File.write((char*) &S, sizeof(S));	//statement 2
		Success++;
	}
}
	if (Success==1)
		cout<<'Purchase Updated'<<endl;
	else
		cout<<'Wrong Item No'<<endl;
	File.close( );
}

(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the required item.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.

Mock Test Series

Sponsor Area

Sponsor Area

NCERT Book Store

NCERT Sample Papers

Entrance Exams Preparation