Unlock access to all the studying documents.
View Full Document
Copyright Cengage Learning. Powered by Cognero.
1. It is a good idea to redefine cin and cout in your programs.
2. In the statement cin >> x;, x can be a variable or an expression.
3. The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y
are int variables.)
cin >> x;
cin >> y;
4. The number of input data extracted by cin and >> depends on the number of variables appearing in the cin
statement.
Copyright Cengage Learning. Powered by Cognero.
12. Suppose that x and y are int variables. Which of the following is a valid input statement?
13. Suppose that x is an int variable, y is a double variable, and ch is a char variable. The input is:
15A 73.2
Choose the values after the following statement executes:
cin >> x >> ch >> y;
x = 15, ch = ‘A’, y = 73.2
x = 15, ch = ‘A’, y = 73.0
x = 15, ch = ‘a’, y = 73.0
This statement results in an error because there is no space between 15 and A.
14. Suppose that alpha is an int variable and ch is a char variable. The input is:
17 A
What are the values after the following statements execute?
cin >> alpha;
cin >> ch;
Copyright Cengage Learning. Powered by Cognero.
18. Suppose that x is an int variable, ch is a char variable, and the input is:
276.
Choose the values after the following statement executes:
cin >> ch >> x;
19. Suppose that x and y are int variables, ch is a char variable, and the input is:
4 2 A 12
Choose the values of x, y, and ch after the following statement executes:
cin >> x >> ch >> y;
This statement results in input failure
Copyright Cengage Learning. Powered by Cognero.
23. Suppose that alpha, beta, and gamma are int variables and the input is:
100 110 120
200 210 220
300 310 320
What is the value of gamma after the following statements execute?
cin >> alpha;
cin.ignore(100, ‘\n’);
cin >> beta;
cin.ignore(100,’\n’);
cin >> gamma;
24. Suppose that ch1 and ch2 are char variables and the input is:
WXYZ
What is the value of ch2 after the following statements execute?
cin.get(ch1);
cin.putback(ch1);
cin >> ch2;
Copyright Cengage Learning. Powered by Cognero.
25. Suppose that ch1 and ch2 are char variables and the input is:
WXYZ
What is the value of ch2 after the following statements execute?
cin >> ch1;
ch2 = cin.peek();
cin >> ch2;
26. In C++, the dot is an operator called the ____ operator.
27. Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements?
cout << fixed << showpoint;
cout << setprecision(2);
cout << x << ‘ ‘ << y << ‘ ‘ << z << endl;
Copyright Cengage Learning. Powered by Cognero.
28. Suppose that x = 55.68, y = 476.859, and z = 23.8216. What is the output of the following statements?
cout << fixed << showpoint;
cout << setprecision(3);
cout << x << ‘ ‘ << y << ‘ ‘ << setprecision(2) << z << endl;
29. Suppose that x = 1565.683, y = 85.78, and z = 123.982. What is the output of the following statements?
cout << fixed << showpoint;
cout << setprecision(3) << x << ‘ ‘;
cout << setprecision(4) << y << ‘ ‘ << setprecision(2) << z << endl;
Copyright Cengage Learning. Powered by Cognero.
30. What is the output of the following statements?
cout << setfill(‘*’);
cout << “12345678901234567890” << endl
cout << setw(5) << “18” << setw(7) << “Happy”
<< setw(8) << “Sleepy” << endl;
12345678901234567890
***18 Happy Sleepy
12345678901234567890
***18**Happy**Sleepy
12345678901234567890
***18**Happy Sleepy
12345678901234567890
***18**Happy Sleepy**
31. What is the output of the following statements?
cout << “123456789012345678901234567890” << endl
cout << setfill(‘#’) << setw(10) << “Mickey”
<< setfill(‘ ‘) << setw(10) << “Donald”
<< setfill(‘*’) << setw(10) << “Goofy” << endl;
123456789012345678901234567890
####Mickey Donald*****Goofy
123456789012345678901234567890
####Mickey####Donald*****Goofy
123456789012345678901234567890
####Mickey####Donald#####Goofy
23456789012345678901234567890
****Mickey####Donald#####Goofy
Copyright Cengage Learning. Powered by Cognero.
open(inFile,”progdata.dat”);
35. Suppose that outFile is an ofstream variable and output is to be stored in the file outputData.out. Which of
the following statements opens the file outputData.out and associates outFile to the output file?
outFile(“outputData.out”);
outFile.open(“outputData.out”);
open(outFile,”outputData.out”);
open.outFile(“outputData.out”);
36. The function ____________________ returns the next character in the input stream; it does not remove the character
from the input stream.
37. C++ comes with a wealth of functions, called ____________________ functions, that are written by other
programmers.
predefined
pre defined
pre-defined
Copyright Cengage Learning. Powered by Cognero.
38. C++ has a special name for the data types istream and ostream. They are called ____________________.
39. In C++, the dot is an operator called the ____________________operator.
40. C++ provides a header file called ____________________, which is used for file I/O.