CS 150 Chapter 3
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; a. W b. X c. Y d. Z
A
Suppose that ch1 and ch2 are char variables, alpha is an int variable, and the input is: A 18 What are the values after the following statement executes? cin.get(ch1); cin.get(ch2); cin >> alpha; a. ch1='A',ch2=' ',alpha=18 b. ch1='A',ch2='1',alpha=8 c. ch1='A',ch2=' ',alpha=1 d. ch1='A',ch2='\n',alpha=1
A
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); a. 'A' b. 'B' c. 'C' d. '\n'
B
In C++, the dot is an operator called the ____ operator. a. dot access c. data access b. member access d. member
B
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
Suppose that x and y are int variables. Which of the following is a valid input statement? a. cin>>x>>cin>>y; c. cin<<x<<y; b. cin>>x>>y; d. cout<<x<<y;
B
Suppose that alpha is an int variable and ch is a char variable and the input is: 17 A What are the values after the following statements execute? cin >> alpha; cin >> ch; a. alpha=17,ch=' ' b. alpha=1,ch=7 c. alpha=17,ch='A' d. alpha=17,ch='a'
C
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; a. 100 b. 200 c. 300 d. 320
C
Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C Choose the value of ch3 after the following statement executes: cin >> ch1 >> ch2 >> ch3; a. 'A' c. 'C' b. 'B' d. '\n'
C
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 c. x=4,ch='',y=2 b. x = 4, ch = A, y = 12 d. This statement results in input failure
D
____ is a parameterized stream manipulator. a. endl b. fixed c. scientific d. setfill
D
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
Manipulators without parameters are part of the ____ header file. a. iostream b. iomanip c. ifstream d. pmanip
A
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 c. 55.680 476.860 23.82 b. 55.690 476.860 23.82 d. 55.680 476.859 23.821
A
Suppose that x and y are int variables, z is a double variable, and 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
Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y; a. x=15,ch='A',y=73.2 b. x=15,ch='A',y=73.0 c. x=15,ch='a',y=73.0 d. This statement results in an error because there is no space between 15 and A.
A
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
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; a. W b. X c. Y d. Z
B
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; a. ch='2',x=276 c. ch='',x=276 b. ch='276',x='.' d. ch='b',x=76
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; a. 12345678901234567890 ***18 Happy Sleepy b. 12345678901234567890 ***18**Happy**Sleepy c. 12345678901234567890 ***18**Happy Sleepy d. 12345678901234567890 ***18**Happy Sleepy**
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; a. 1565.683 85.8000 123.98 c. 1565.683 85.7800 123.98 b. 1565.680 85.8000 123.98 d. 1565.683 85.780 123.980
C
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; a. 25.67 356.87 7623.96 c. 25.67 356.88 7623.97 b. 25.67 356.87 7623.97 d. 25.67 356.876 7623.967
C
Suppose that x is an int variable and y is a double variable and the input is: 10 20.7 Choose the values after the following statement executes: cin >> x >> y;. a. x=10,y=20 c. x=10,y=20.7 b. x=10,y=20.0 d. x=10,y=21.0
C
Suppose that x is an int variable, y is a double variable, z is an int variable, and the input is: 15 76.3 14 Choose the values after the following statement executes: cin >> x >> y >> z; a. x=15,y=76,z=14 b. x=15,y=76,z=0 c. x=15,y=76.3,z=14 d. x=15.0,y=76.3,z=14.0
C
When you want to process only partial data, you can use the stream function ____ to discard a portion of the input. a. clear c. delete b. skip d. ignore
D