Chapter 3 quiz

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

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

'B'

Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A BCChoose the value of ch3 after the following statement executes:cin >> ch1 >> ch2 >> ch3; 'A' 'B' '\n' 'C'

'C'

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

12345678901234567890 ***18**Happy**Sleepy

What is the output of the following statements? cout << "123456789012345678901234567890" << endlcout << setfill('#') << setw(10) << "Mickey"<< setfill(' ') << setw(10) << "Donald" << setfill('*') << setw(10) << "Goofy" << endl; 123456789012345678901234567890####Mickey####Donald*****Goofy 23456789012345678901234567890****Mickey####Donald#####Goofy 123456789012345678901234567890####Mickey####Donald#####Goofy 123456789012345678901234567890 ####Mickey Donald*****Goofy

123456789012345678901234567890 ####Mickey Donald*****Goofy

Suppose that x and y are int variables, ch is a char variable, and the input is:4 2 A 12Choose the values of x, y, and ch after the following statement executes:cin >> x >> ch >> y; x = 4, ch = ' ', y = 2 x = 4, ch = A, y = 12 x = 4, ch = 2, y = 12 This statement results in input failure

This statement results in input failure

Suppose that ch1 and ch2 are char variables and the input is: WXYZWhat is the value of ch2 after the following statements execute?cin.get(ch1);cin.putback(ch1);cin >> ch2; W X Z Y

W

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

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 int variables.) cin >> x;cin >> y; True False

false

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

fstream

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

true

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

true

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 False

true

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

true

Suppose that x is an int variable and y is a double variable and the input is:10 20.7Choose the values after the following statement executes: cin >> x >> y;. x = 10, y = 20.7 x = 10, y = 20 x = 10, y = 21.0 x = 10, y = 20.0

x = 10, y = 20.7

Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is:15A 73.2Choose the values after the following statement executes:cin >> x >> ch >> y; x = 15, ch = 'A', y = 73.0 This statement results in an error because there is no space between 15 and A. x = 15, ch = 'A', y = 73.2 x = 15, ch = 'a', y = 73.0

x = 15, ch = 'A', y = 73.2

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

false

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

false

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

false

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

false

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.780 123.980 1565.683 85.7800 123.98 1565.680 85.8000 123.98 1565.683 85.8000 123.98

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.876 7623.967 25.67 356.87 7623.96 25.67 356.87 7623.97 25.67 356.88 7623.97

25.67 356.88 7623.97

Suppose that alpha, beta, and gamma are int variables and the input is: 100 110 120200 210 220300 310 320What is the value of gamma after the following statements execute?cin >> alpha;cin.ignore(100, '\n');cin >> beta;cin.ignore(100,'\n');cin >> gamma; 100 320 200 300

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; 55.680 476.859 23.821 55.680 476.859 23.82 55.680 476.860 23.82 55.690 476.860 23.82

55.680 476.859 23.82

Suppose that ch1 and ch2 are char variables and the input is: WXYZWhat is the value of ch2 after the following statements execute?cin >> ch1;ch2 = cin.peek();cin >> ch2; W Y Z X

X

Suppose that alpha is an int variable and ch is a char variable and the input is: 17 AWhat are the values after the following statements execute?cin >> alpha;cin >> ch; alpha = 17, ch = 'a' alpha = 1, ch = 7 alpha = 17, ch = ' ' alpha = 17, ch = 'A'

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:cin >> ch >> x; ch = '2', x = 76 ch = 'b', x = 76 ch = '276', x = '.' ch = ' ', x = 276

ch = '2', x = 76

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

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

Suppose that x and y are int variables. Which of the following is a valid input statement? cout << x << y; cin << x << y; cin >> x >> y; cin >> x >> cin >> y;

cin >> x >> y;

C++ has a special name for the data types istream and ostream. They are called ____________________.

classes

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

ignore

Consider the following program segment. ifstream inFile; //Line 1int 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? open.inFile("progdata.dat"); inFile.open("progdata.dat"); inFile(open,"progdata.dat"); open(inFile,"progdata.dat");

inFile.open("progdata.dat");

Manipulators without parameters are part of the ____ header file. ifstream iostream iomanip pmanip

iostream

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

member access

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

member access

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"); open(outFile,"outputData.out"); outFile.open("outputData.out"); open.outFile("outputData.out");

outFile.open("outputData.out");

The function ____________________ returns the next character in the input stream; it does not remove the character from the input stream.

peek

C++ comes with a wealth of functions, called ____________________ functions, that are written by other programmers.

pre-defined

____ is a parameterized stream manipulator. fixed endl scientific setfill

setfill

Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is:15 76.3 14Choose the values after the following statement executes:cin >> x >> y >> z; x = 15, y = 76, z = 0 x = 15, y = 76.3, z = 14 x = 15, y = 76, z = 14 x = 15.0, y = 76.3, z = 14.0

x = 15, y = 76.3, z = 14

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

x = 28, y = 32, z = 0.6


Kaugnay na mga set ng pag-aaral

BUS 312 Chapter 11 Practice Test

View Set

Chapter 14 Transactions and Locking SQL

View Set

Chapter 3 - The Organic Molecules of Life

View Set

European History Test 4 Study Guide (Howie's Classs)

View Set