C++ Chapter Three

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

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; (T/F)

False

In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device. (T/F)

False - advances cursor to beginning of next line (End current line, start new line)

peek returns next character from input stream and removes it (T/F)

False - does not remove it

The manipulator setw formats the output of an expression in a specific number of columns; the default output is left-justified.

False - right-justified

When you want to process only partial data, you can use the stream function ____ to discard a portion of the input.

Ignore

To use the manipulators setprecision, setw, and setfill, the program must include the header file ________.

Iomanip

When reading data into a char variable, after skipping any leading whitespace characters, the extraction operator >> finds and stores only the next character; reading stops after a single character. (T/F)

True

You can use the function getline to read a string containing blanks (T/F)

True

You can use the function getline to read a string containing blanks. (T/F)

True

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;

W

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;

alpha = 17, ch = 'A'

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:

b. ch = '2', x = 76

Suppose that ch1, ch2, and ch3 are variables of the type char. The input is: ​ A B C ​What is the value of ch3 after the following statements execute? ​cin.get(ch1); cin.get(ch2); cin.get(ch3);

'B'

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

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;

1565.683 85.7800 123.98

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;

25.67 356.88 7623.97

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;

300

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; A. 55.680 476.859 23.82 B. 55.690 476.860 23.82 C. 55.680 476.860 23.82 D. 55.680 476.859 23.821

A. 55.680 476.859 23.82

Suppose that x and y are int variables, and z is a double variable. The input is: ​ 28 32.6 12 ​Choose the values of x, y, and z after the following statement executes: ​cin >> x >> y >> z; A. x=28,y=32,z=0.6 B. x=28,y=32,z=12.0 C. x=28,y=12,z=32.6 D. x=28,y=12,z=0.6

A. x = 28, y = 32, z = 0.6

An expression such as pow(2,3) is called a(n) ____________________. A. function declaration B. function call C. function initialization. D. None of the above

B. Function call

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; A. 1565.683 85.8000 123.98 B. 1565.683 85.8000 123.98 C. 1565.683 85.7800 123.98 D. 1565.683 85.780 123.980

C. 1565.683 85.7800 123.98

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; A. x=4,ch=2,y=12 B. x=4,ch=A,y=12 C. x=4,ch='',y=2 D. This statement results in input failure

D. This statement results in input failure

Suppose that x is an int variable and y is a double variable. The input is: 10.5 20.7 Choose the values after the following statement executes: cin >> x >> y;. A. x= 10, y= 20 B. x= 10, y= 20.0 C. x= 10, y= 20.7 D. x= 10, y= 0.5

D. x= 10.5, y= 0.5

Entering a char value into an int variable causes serious errors, called input failure. (T/F)

True

The extraction operator >> skips only all leading blanks when searching for the next data in the input stream. (T/F)

True

The header file fstream contains the definitions of ifstream and ofstream. (T/F)

True

The manipulator setfill is used to fill the unused columns on an output device with a character other than a space. (T/F)

True

The manipulator setprecision formats the output of floating-point numbers to a specified number of decimal places. (T/F)

True

The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement. (T/F)

True

Suppose that x is an int variable and y is a double variable. The input is: ​ 10 20.7 Choose the values after the following statement executes: cin >> x >> y;.

c. x = 10, y = 20.7

Suppose that ch1 and ch2 are char variables, and alpha is an int variable. The input is: ​ A 18 ​What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha;

ch1 = 'A', ch2 = ' ', alpha = 18

the get function presented in this chapter only reads values of type _____________

char

Suppose that x and y are int variables. Which of the following is a valid input statement?

cin >> x >> y;

Which header contains the sqrt function?

cmath

>> is called stream ___ operator (cin) << is called stream ____ operator (cout)

extraction; Insertion

C++ provides a header file called ____________________, which is used for file I/O.

fstream

In C++, the dot is an operator called the ____ operator. The '.' In cin.get(ch1)

member access


Ensembles d'études connexes

Final Exam: Questions and Answers

View Set

PT Lecture 21 - More Principles of Economic Justice

View Set

Principles of Business: 4.00_Understand Business Operations Management

View Set

Legal Environment of Business - Agency

View Set

Sear's Driving Book Chapter 10 Review

View Set

Repaso de Vocabulario 1 Spanish 3

View Set

Health and Skill-Related Components

View Set