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?
- cin >> num1 >> symbol >> num2;
- cin >> symbol >> num1 >> num2;
- cin >> num1;
cin.get(symbol);
cin >> num2;
- cin >> num1 >> num2;
cin.get(symbol);
- 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
- cin >> x >> y >> z;
- cin >> x >> z >> y;
- 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?
- cin >> x >> y;
cin.ignore(100, ' ');
cin >> symbol;
- cin >> x;
cin.ignore(100, '*');
cin >> y;
cin.get(symbol);
- cin >> y;
cin.ignore(100, ' ');
cin >> x >> symbol;
- cin.get(symbol);
cin.ignore(100, '*');
cin >> x;
cin.ignore(100, ' ');
cin >> y;
- 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:
- 71 45.97
- 71 45A 97.6
- 71 .45A 97
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
