I need help with my homework. Comp 122 Chapter 3 page (166-170)exercise # 2, 4,
ID: 3540358 • Letter: I
Question
I need help with my homework.
Comp 122 Chapter 3 page (166-170)exercise # 2, 4, 6, 8, 10, 12, 14, 16, 18.
2.
Suppose x and y are int variables and ch is a char variable. Consider the following input:
5 28 36
What value (if any) is assigned to x, y, and ch after each of the following statements executes? (Use the same input for each statement.)
a.
cin >> x >> y >> ch;
b.
cin >> ch >> x >> y;
c.
cin >> x >> ch >> y;
d.
cin >> x >> y;
cin.get(ch);
4.
Suppose x and y are int variables and ch is a char variable. Assume the following input data:
13 28 D
14 E 98
15 A B 56
What value (if any) is assigned to x, y, and ch after each of the following statements executes? (Use the same input for each statement.)
a.
cin >> x >> y;
cin.ignore(50, ' ');
cin >> ch;
b.
cin >> x;
cin.ignore(50, ' ');
cin >> y;
cin.ignore(50, ' ');
cin.get(ch);
c.
cin >> y;
cin.ignore(50, ' ');
cin >> x >> ch;
d.
cin.get (ch);
cin.ignore(50, ' ');
cin >> x;
cin.ignore (50, 'E');
cin >> y;
6.
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 62.78
b.
86 32A92.6
c.
12 .45A 32
8.
Which header file must be included to use the function pow?
10.
Write a C++ statement that uses the manipulator setfill to output a line containing 35 stars, as in the following line:
***********************************
12.
Suppose that age is an int variable, ch is a char variable, and name is a string variable. What are the values of age and name after the following input statements execute:
cin >> age;
cin.get(ch);
getline (cin, name);
if the input is:
a.
23 Lance Grant
b.
23
Lance Grant
14.
What may cause an input stream to enter the fail state? What happens when an input stream enters the fail state?
16.
Suppose that infile is an ifstream variable and employee.dat is a file that contains employees' information. Write the C++ statement that opens this file using the variable infile.
18.
Suppose that infile is an ifstream variable and it is associated with the file that contains the following data: 27306 savings 7503.35. Write the C++ statement(s) that reads and stores the first input in the int variable acctNumber, the second input in the string variable accountType, and the third input in the double variable balance.
Explanation / Answer
2. a) x = 5 , y = 28 , ch = 3
b) x = 28 , y = 36 , ch = 5
c) x = 5 , y = 8 , ch = 2
d) x = 5 , y = 28 , ch = ' '
4. a) x = 5 , y = 28 , ch = ' '
b) x = 13 , y = 14 , ch = 1
c) x = 14 , y = 13 , ch = E
d) x = 14 , y = 98 , ch = 1
6. a) x = 35 , y = 62 , z = 78 , ch = '.'
b) x = 86 , y = 32 , z = 92.6 , ch = A
c) x = 12 , y = 0 , z = garbage value , ch = garbage value
8. math.h
10. cout << setfill ('*') << setw (35)<< "*"<<endl;
12. a) age = 23 , ch = ' ' , name = Lance Grant
b) age = 23 , ch = ' ' , name = Lance Grant
14. Input stream may enter to fail state beacuse of an attempt to read invalid data set. If an input stream enters a fail state , all
subsequent input statements associated with that input stream are ignored and the computer continues to execute the
program which may cause erroneous results.
16. infile >> acctNumber >> accountType >> balance;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.