1/124
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Assume that a program has the following string object definition: string name;
Which of the following statements correctly assigns a string literal to the string object?
name = "Jane";
What is the output of the following code?
int w = 98;
int x = 99;
int y = 0;
int z = 1;
if (x >= 99){ if (x < 99){ cout << y << endl; }
else { cout << z << endl; }}
else { if (x==99){ cout << x << endl; }
else { cout << w << endl; }}
1
Which value can be entered to cause the following code segment to display the message: "That number is acceptable."
int number;
cin >> number;
if (number > 10 && number < 100) { cout << "That number is acceptable" << endl;}
else { cout << "That number is not acceptable" << endl;}
99
Which of the following expressions will determine whether x is less than or equal to y?
x <= y
Which of the following statement is required for calling function "sqrt()"?
include cmath
How many times will the following loop display "Hello!"?
for (i = 0; i <= 20; ++i){ cout << "Hello!" << endl; }
21
What is the output of this code:
string x = "One";
string y = "Two";
string temp;
temp = y + x;
cout << temp << endl;
TwoOne
How many times will the loop body execute?
Assume user would enter 'a', then 'b', then 'n'.
// Get userChar from user here while (userChar != 'n') { // Do something //Get userChar from user here }
Loops 2 times
Which input value causes "Goodbye" to be output next?
int x;
cin >> x;
while (x <= 0) { // Do something cin >> x;}
cout << "Goodbye";
1
What is the ending value of sum, if the input is 2 3 7 5? All variables are ints.
cin >> x;
sum = 0;
for (i = 0; i < x; ++i) { cin >> currValue; sum += currValue;}
10
A loop should output 1 to n. If n is 5, the output is 12345. What should XXX and YYY be? Choices are in the form XXX / YYY.
cin >> n;
for (XXX; i++) { cout << YYY;}
i = 0; i = n / i + 1
Which XXX causes every character in string inputWord to be output?
for (XXX) { cout << inputWord.at(i) << endl; }
i = 0; i = inputWord.size(); ++i
Which input value causes the loop body to execute a 2nd time, thus outputting "In loop" again?
string s = "Go";
while ((s != "q") && (s != "Q")){ cout << "In loop" << endl; cin >> s;}
"Quit"
If the input is 12, what is the final value for numItems?
int x;
int numItems = 0;
cin >> x;
if (x <= 12) { numItems = 100;}
else { numItems = 200;}
numItems = numItems + 1;
101
Which input for char c causes "Done" to be output next?
c = 'y';
while (c = 'y') { // Do something cout << "Enter y to continue, n to quit: "; cin >> c;}
cout << "Done";
No such value (infinite loop)
Which expressions for XXX, YYY, and ZZZ output "Great job" for scores above 90, and "Nice try" otherwise? Choices are in the form XXX / YYY / ZZZ.
int score;
cin >> score;
if (XXX) { cout << YYY;}
else { cout << ZZZ;}
score >= 91 / "Nice try" / "Great job"
What is the final value of y?
int x = 77;
int y = 4;
if (x == 77) { y = y + 1;}
if (x < 100) { y = y + 1;}
if (x > 77) { y = y + 1;}
y = y + 1;
7
Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"?
if (val = 0) { cout "Non-negative";}
else { cout "Negative"; }
Which expressions for YYY and ZZZ correctly output the indicated ranges? Assume int x's value will be 0 or greater. Choices are in the form YYY / ZZZ.
if (YYY) { // Output "0-29"} else if (ZZZ) { // Output "30-39"}else { // Output "40+"}
x < 30 / x < 40
What is the output, if the input is 3 2 1 0?
cin >> x;
while (x > 0) { cout << 2 * x << " ";}
6 6 6 6 6 … (infinite loop)
A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given?
(age < 10) || (age > 55)
Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY.
cin >> w;
while (XXX) { // Do something YYY;}
w < 100 / cin >> w
A loop should sum all inputs, stopping when the input is 0. If the input is 2 4 6 0, sum should end with 12. What should XXX, YYY, and ZZZ be? Choices are in the form XXX / YYY / ZZZ.
int sum;
int currVal;
XXX;
cin >> currVal;
while (YYY) { ZZZ; cin >> currVal;}
sum = 0 / currVal != 0 / sum = sum + currVal
How many times does the while loop execute for the given input values of -1 4 0 9?
userNum = 3;
while (userNum > 0) { // Do something // Get userNum from input}
1
Which for loop will iterate 100 times?
for (i = 0; i=100; i++)
Assume that a vector is defined as follows. What is the correct statement if we want to set the first element to 3?
vector
v.push_back(3); to set it to the first element