Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A Moving to another question will save this response. Question 31 The given func

ID: 3578726 • Letter: A

Question

A Moving to another question will save this response. Question 31 The given function is supposed to read an integer from a file and return the value of that integer. However integer? int read int (ifstream& infile) int int value 0, bool not found true, char ch, while (infile.get (ch) && not found) if (isdigit (ch)) infile int value, not found falses return int value, o A. The should be placed immediately before the statement that reads the integ B true and false should be switched o C not found should be replaced by found. The statement infil replace should be placed immed D The statement infile.unget should be placed immediately after the statement that reads the integer A Moving to another question will save this response.

Explanation / Answer


Ans: A

Here infile.get() -> in while loop, we are reading first character(digit) and movind pointer one step forward, so we are missing first charcter. TO make it available -> use infile.unget() before the statement that reads the integer from file so that first character will be availabl again

unget:
Decrements the internal get pointer by one, making the last character extracted from the input sequence available again as the next character to be read from the stream.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote