Question: IMPORTANT: In the following questions use the notation x = fail state to indicate that cin entered the fail state before assigning a valid value

IMPORTANT: In the following questions use the notation x = fail state to indicate that cin entered the fail state before assigning a valid value to the variable x. In reality some compilers generate code in which fail state assignments are zero or the null character, but such behavior is not required by standard C++.

You can denote character assignments with two single quotes around the character or escape sequence. For example, the space character would be and ' ' the newline character would be' '. For an empty string use "".

1. In this question you are to play computer and analyze five different programs (a. through e.) which are run using the same input line:

23 46 # 78 *

In each program num1 and num2 are int variables and symbol is a char variable. What value (if any) is assigned to num1, num2, and symbol after each of the following statements executes?

  1. cin >> num1 >> symbol >> num2;
  2. cin >> symbol >> num1 >> num2;
  3. cin >> num1;

cin.get(symbol);

cin >> num2;

  1. cin >> num1 >> num2;

cin.get(symbol);

  1. cin.get(symbol);

cin >> num1 >> num2;

2. In this question you are to play computer and analyze three different programs (a. through c.) which are run using the same input. Suppose x and y are int variables and z is a double variable. Describe either fail state or the variable assignments of x, y, and z. For example, if the x assignment occurs before cin enters the fail state then write something like x = 7, otherwise write something like x = fail state.

Input data:

1.2 .5 4

  1. cin >> x >> y >> z;
  2. cin >> x >> z >> y;
  3. cin >> z >> y >> x;

3. In this question you are to play computer and analyze five different programs (a. through e.) which are run using the same input. Note that there may be more lines of input available than will be read in. Suppose x and y are int variables and symbol is a char variable.

Input data:

12 34 * 67 11

89 $ 55 # 93

# & 42 83

What value (if any) is assigned to x, y, and symbol after each of the following statements executes?

  1. cin >> x >> y;

cin.ignore(100, ' ');

cin >> symbol;

  1. cin >> x;

cin.ignore(100, '*');

cin >> y;

cin.get(symbol);

  1. cin >> y;

cin.ignore(100, ' ');

cin >> x >> symbol;

  1. cin.get(symbol);

cin.ignore(100, '*');

cin >> x;

cin.ignore(100, ' ');

cin >> y;

  1. cin.ignore(100, ' ');

cin >> x >> symbol;

cin.ignore(100, ' ');

cin.ignore(100, &);

cin >> y;

4. Suppose x and y are int variables, z is a double variable, and ch is a char variable. Suppose the input statement is:

cin >> x >> y >> ch >> z;

Write the either fail state or the new values read into x, y, z, and ch if the input is as follows:

  1. 71 45.97
  2. 71 45A 97.6
  3. 71 .45A 97

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!