Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.4k views
in Computer by (69.4k points)

Observe the program segment given below carefully, and answer the question that follows:

class PracFile

{ int Pracno;

char PracName[20];

char TimeTaken;

int Marks; public:

//function to enter PracFile details 

void EnterPrac();

//function to display PracFile details

void ShowPrac(); 

//function to return TimeTaken

char RTime() { return TimeTaken; }

//fuction to assign Marks

void Assignmarks(int M)

{ Marks=M; };

};

void AllocateMarks()

{  fstream File;

File.open("MARKS.DAT",ios::in|ios::out);

PracFile P;

int Record=0;

while(File.read((char*)&P,sizeof(P)))

{ if(P.RTime()>50)

P.Assignmarks(0);

else P.Assignmarks(10); 

_____________ //statement 1 

_____________ //statement 2

Record++;

}

File.close();

}

If the function AllocateMarks() is supposed to Allocate Marks for the records in file MARKS.DAT based on their value of member TimeTaken.

Write C++ statements for the statement 1 and statement 2, where statement 1 is required to position the file write pointer to an appropriate place in the file statement 2 is to perform the write operation with the modified record. 

1 Answer

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

Statement 1: File.seekp((Record)*sizeof(P));

OR

File.seekp(-1*sizeof(P),ios::cur);

Statement 2: File.write((char*)&P,sizeof(P)); 

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

...