1. Suppose num1 and num2 are int variables and symbol is a char variable. Consid
ID: 3820777 • Letter: 1
Question
1. Suppose num1 and num2 are int variables and symbol is a char variable. Consider the following input:
37 18 * 48 $
What value (if any) is assigned to num1, num2, and symbol after each of the following statements executes? (Use the same input for each statement.)
a. cin >> num1 >> symbol >> num2;
b. cin >> symbol >> num1 >> num2;
c. cin >> num1;
d. cin.get(symbol);
e. cin >> num2;
f. cin >> num1 >> num2;
g. cin.get(symbol);
h. cin.get(symbol);
i. cin >> num1 >> num2;
2. Suppose x and y are int variables and z is a double variable. Assume the following input data:
7.86 76
What value (if any) is assigned to x, y, and z after each of the following statements executes? (Use the same input for each statement.)
a. cin >> x >> y >> z;
b. cin >> x >> z >> y;
c. cin >> z >> x >> y;
3. Suppose x and y are int variables and symbol is a char variable. Assume the following input data:
38 26 * 67 33
24 $ 55 # 34
# & 63 85
What value (if any) is assigned to x, y, and symbol after each of the following statements executes? (Use the same input for each statement.)
a. cin >> x >> y;
cin.ignore(100, ' ');
cin >> symbol;
b. cin >> x;
cin.ignore(100, '*');
cin >> y;
cin.get(symbol);
c. cin >> y;
cin.ignore(100, ' ');
cin >> x >> symbol;
d. cin.get(symbol);
cin.ignore(100, '*');
cin >> x;
cin.ignore(100, ' ');
cin >> y;
e. cin.ignore(100, ' ');
cin >> x >> symbol;
cin.ignore(100, ' ');
cin.ignore(100, ‘&’);
cin >> y;
4. Given the input:
46 Z 49
and the C++ code:
int x = 10, y = 18;
char z = '*';
cin >> x >> y >> z;
cout << x << " " << y << " " << z << endl;
What is the output?
5. Suppose that 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;
What values, if any, are stored in x, y, z, and ch if the input is:
a. 35 72.68
b. 6 32H 72.6
c. 12 .45A 59
6. Suppose that num is an int variable and discard is a char variable.
Assume the following input data:
#34
What value (if any) is assigned to num and discard after each of the following statements executes? (Use the same input for each statement.)
a. cin.get (discard);
cin >> num;
b. discard = cin.peek();
cin >> num;
c. cin.get (discard);
cin.putback (discard);
cin >> discard;
cin >> num;
7. Suppose that name is a variable of type string. Write the input statement to read and store the input Melinda Clinton in name. (Assume that the input is from the standard input device.)
8. Suppose that age is an int variable and name is a string variable. What are
the values of age and name after the following input statements execute:
cin >> age;
getline(cin, name);
if the input is:
a. 15 Hugh Grant
b. 23
Hugh Grant
9. The following program is supposed to read two numbers from a file named input.dat and write the sum of the numbers to a file named output.dat
However, it fails to do so. Rewrite the program so that it accomplishes what
it is intended to do. (Also, include statements to close the files.)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int num1, num2;
ifstream infile;
outfile.open("output.dat");
infile >> num1 >> num2;
outfile << "Sum = " << num1 + num2 << endl;
return 0;
}
10. Suppose that you have the following statements:
ofstream outfile;
double distance = 425;
double speed = 60;
double travelTime;
Write C++ statements to do the following:
a. Open the file travel.dat using the variable outfile.
b. Write the statement to format your output to two decimal places in fixed form.
c. Write the values of the variables day, distance, and speed in the file travel.dat.
d. Calculate and write the travelTime in the file travel.dat.
e. Which header files are needed to process the information in (a) to (d)?
Explanation / Answer
Please post one question at a time
1. Suppose num1 and num2 are int variables and symbol is a char variable. Consider the following input:
37 18 * 48 $
What value (if any) is assigned to num1, num2, and symbol after each of the following statements executes? (Use the same input for each statement.)
a. cin >> num1 >> symbol >> num2; (num1 = 37, symbol = 1, num2 = 8)
b. cin >> symbol >> num1 >> num2; (symbol = 3, num1 = 7, num2 = 18);
c. cin >> num1; (num1 = 37, num2 and symbol will be garbage)
d. cin.get(symbol); (symbol = 3, num1 and num2 garbage)
e. cin >> num2; (num2 = 37, num1 and symbol will be garbage)
f. cin >> num1 >> num2; (num1 = 37, num2 = 18)
g. cin.get(symbol); (these are repeated question)
h. cin.get(symbol); (these are repeated question)
i. cin >> num1 >> num2; (these are repeated question)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.