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

Assume the following line of data is entered at the keyboard: 1 5.2 a,b Give the

ID: 3551589 • Letter: A

Question

Assume the following line of data is entered at the keyboard:

1 5.2 a,b

Give the corresponding memory snapshot, and the value of the stream state flags, after each of the following sets of statements is executed:

1. int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> x >> y >> ch1 >> ch2;

2. int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> x >> i >> j >> ch1 >> ch2;

3. int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> i >> j >> ch1 >> ch2;

4. int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> i >> j >> x >> ch1 >> ch2;

Explanation / Answer

<<1>>

#include<iostream> // std::cout, std::ios

using namespace std;

int main ()

{

int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> x >> y >> ch1 >> ch2;

std::cout << "good()=" << cin.good();

std::cout << " eof()=" << cin.eof();

std::cout << " fail()=" << cin.fail();

std::cout << " bad()=" << cin.bad();

return 0;

}

Success Time/Memory 0s/3432KB

stdin :

1 5.2 a,b

stdout :

good()=1 eof()=0 fail()=0 bad()=0


<<2>>

#include<iostream> // std::cout, std::ios

using namespace std;

int main ()

{

int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> x >> i >> j >> ch1 >> ch2;

std::cout << "good()=" << cin.good();

std::cout << " eof()=" << cin.eof();

std::cout << " fail()=" << cin.fail();

std::cout << " bad()=" << cin.bad();

return 0;

}

Success Time/Memory 0s/3476KB

stdin :

1 5.2 a b

stdout :

good()=0 eof()=0 fail()=1 bad()=0


<<3>>

#include<iostream> // std::cout, std::ios

using namespace std;

int main ()

{

int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> i >> j >> ch1 >> ch2;

std::cout << "good()=" << cin.good();

std::cout << " eof()=" << cin.eof();

std::cout << " fail()=" << cin.fail();

std::cout << " bad()=" << cin.bad();

return 0;

}

Success Time/Memory 0s/3300KB

stdin :

1 5.2 a b

stdout :

good()=1 eof()=0 fail()=0 bad()=0


<<4>>

#include<iostream> // std::cout, std::ios

using namespace std;

int main ()

{

int i(0), j(0);

double x, y;

char ch1, ch2;

cin >> i >> j >> x >> ch1 >> ch2;

std::cout << "good()=" << cin.good();

std::cout << " eof()=" << cin.eof();

std::cout << " fail()=" << cin.fail();

std::cout << " bad()=" << cin.bad();

return 0;

}

Success Time/Memory 0s/3432KB

stdin :

1 5.2 a b

stdout :

good()=1 eof()=0 fail()=0 bad()=0

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