LIVE Course for free

Rated by 1 million+ students
Get app now
JEE MAIN 2023
JEE MAIN 2023 TEST SERIES
NEET 2023 TEST SERIES
NEET 2023
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
996 views
in Computer by (69.1k points)
recategorized by

Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2 using fstream functions for performing the required task.

#include

class Stock {

long Ino; // Item Number

char Item[20]; // Item Name

int Qty; // Quantity public:

void Get(int);

Get(int); // Function to enter the content

void Show( );  // Function to display the content

void Purchase(int Tqty)

{

Qty+ = Tqty; // Function to increment in Qty

}

long KnowIno( )

return Ino;}

};

void Purchaseitem(long PINo, int PQty)

// PINo -> Info of the item purchased

// PQty -> Number of items purchased

{

fstream File;

File.open(“ITEMS.DAT”,ios::binary|ios::in|ios::cut); int Pos=-1; Stock S;

while (Pos== -1 && File.read((char*)&S, sizeof(S)))

if (S.KnowInc( ) == PINo)

{

S.Purchase(PQty);  // To update the number of items

Pos = File.tellg()- sizeof(S); 

//Line 1 : To place the file pointer to the required position ______________________________________; 

//Line 2 : To write the objects on the binary file ______________________________________;

}

if (Pos == -1)

cout<<“No updation done as required Ino not found...”; 

File.close( );

}

1 Answer

0 votes
by (60.8k points)
selected by
 
Best answer

Line 1: File.seekp(Pos);

Line 2: File.write((char*) &S, sizeof(S));

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...