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

Assume the following stream input and variable declarations: Stream Input (from

ID: 3794335 • Letter: A

Question

Assume the following stream input and variable declarations: Stream Input (from cin): 42 75 B 19 Q 22 Declarations: int x, y; char ch; What is the result for the following statements, i.e. what values are stored in which variables after each statement is executed? Consider each part (a, b) by itself, that is, each set of instructions will be expected to interact with a fresh copy of the same stream input as given above. (a) cin >> x >> y; cin.ignore (50, ’ ’); cin >> ch; (b) cin.get (ch); cin.ignore (50, ’B’); cin >> x >> y;

Explanation / Answer

cin.ignore(x,' ') will ignore the next characters or untill new line character is inserted.

a.) x will have 42, y will have 75 and ch will have garbage value

b.) cin.get(ch); takes 44 as input but it store only first character in it i.e., 4. and next statement cin.ignore(); ignore all the characters until we recieve 'B' or new ine character. So, ch will have 4, x will have 19 and y will have default value or garbage value.

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