Chapter 3 - CS 225

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

True or False: If input failure occurs in a C++ program, the program terminates immediately and displays an error message.

False

True or False: In an output statement, each occurrence of endl advances the cursor to the end of the current line on an output device.

False

True or False: In the statement cin >> x;, x can be a variable or an expression.

False

True or False: It is a good idea to redefine cin and cout in your programs.

False

True or False: The extraction operator >> skips only all leading blanks when searching for the next data in the input stream.

False

True or False: The following statements will result in input failure if the input values are not on a separate line. (Assume that x and y are intvariables.) cin >> x; cin >> y;

False

True or False: Entering a char value into an int variable causes serious errors, called input failure.

True

True or False: The number of input data extracted by cin and >> depends on the number of variables appearing in the cin statement.

True

True or False: 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.

True

True or False: You can use the function getline to read a string containing blanks.

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 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;

X

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; a. 123456789012345678901234567890 ####Mickey Donald*****Goofy b. 123456789012345678901234567890 ####Mickey####Donald*****Goofy c. 123456789012345678901234567890 ####Mickey####Donald#####Goofy d. 23456789012345678901234567890 ****Mickey####Donald#####Goofy

a. 123456789012345678901234567890 ####Mickey Donald*****Goofy

Consider the following program segment. ifstream inFile; //Line 1 int x, y; //Line 2 ... //Line 3 inFile >> x >> y; //Line 4 Which of the following statements at Line 3 can be used to open the file progdata.dat and input data from this file into x and y at Line 4? a. inFile.open("progdata.dat"); b. inFile(open,"progdata.dat"); c. open.inFile("progdata.dat"); d. open(inFile,"progdata.dat");

a. inFile.open("progdata.dat");

What is the output of the following statements? cout << setfill('*'); cout << "12345678901234567890" << endl cout << setw(5) << "18" << setw(7) << "Happy" << setw(8) << "Sleepy" << endl; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy**

b. 12345678901234567890 ***18**Happy**Sleepy

Suppose that ch1, ch2, and ch3 are variables of the type char and 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'

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 doubles x = 462.191, y = 794.579, and z = 32.1238. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(1); cout << x << ' ' << y << ' ' << setprecision(3) << z << endl;

462.2, 794.6, 32.124

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? a. outFile("outputData.out"); b. outFile.open("outputData.out"); c. open(outFile,"outputData.out"); d. open.outFile("outputData.out");

b. outFile.open("outputData.out");

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

ignore

Manipulators without parameters are part of the ____ header file.

iostream

In C++, the dot is an operator called the ____ operator.

member access

____ is a parameterized stream manipulator.

setfill


Kaugnay na mga set ng pag-aaral

Intro to Criminal Justice Chapter 12 NEW

View Set

Testout Ethical Hacker Pro 12.3.6 Preform an SQL Injection Attack

View Set

West B Writing Ch2 Organizing an Essay

View Set

SAP Basics - Materials Management (MM)

View Set

Passpoint- fluid and electrolyte balance

View Set

Global Corporate Citizenship Test Questions Chapter 19

View Set

HMGT 3310 Chapter 5, HMGT 3310 Chapter 6, Quiz 3: Chapter 5 & 6, HMGT 3310 Final, Healthcare Regulations, Healthcare Regulations 2, HMGT 3310 Quiz 3 and 4

View Set

ATI Individual & Family Well Being: Adult

View Set