Programming One Final
A _____ is a computer component that stores files and other data. a. disk b. monitor c. keyboard d. processor
A _____ is a computer component that stores files and other data. disk
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; } a. i = 0; i < n / i b. i = 0; i < n / i + 1 c. i = 1; i < n / i d. i = 1; i < n / i + 1
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
C++ is _____. a. derived from Fortran b. derived from C c. derived from Python d. derived independently of any other language
C++ is _____. derived from C
Choose the statement(s) that generate(s) this output: I wish you were here a. cout << "I wish" + "you were here"; b. cout << "I wish" << endl; cout << "you were here"; c. cout << "I wish"; cout << "you were here" << endl; d. cout << "I wish" << ln << "you were here";
Choose the statement(s) that generate(s) this output: I wish you were here cout << "I wish" << endl; cout << "you were here";
For the following function, which is a valid function call? Assume maxValue is an integer. int Max(int x, int y) { if (x > y){ return x; } else { return y; } } a. maxValue = Max(15 25); b. maxValue = Max(); c. maxValue = Max(15, Max(35, 25)); d. Max = maxValue(15, 25);
For the following function, which is a valid function call? Assume maxValue is an integer. int Max(int x, int y) { if (x > y){ return x; } else { return y; } } maxValue = Max(15, Max(35, 25));
For which quantity is a double the best type? a. People in a household b. Boxes on a conveyor belt c. Planes above a city d. Height of a building
For which quantity is a double the best type? Height of a building
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; a. 100 b. 101 c. 200 d. 201
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
RAM is an abbreviation that stands for: a. Real Analog Memory b. Ranged Access Memory c. Random Access Memory d. Random Abbreviated Memory
RAM is an abbreviation that stands for: Random Access Memory
The _____ is a process that manages programs and interfaces with peripherals. a. clock b. BIOS c. integrated circuit d. operating system
The _____ is a process that manages programs and interfaces with peripherals. operating system
The following program generates an error. Why? void PrintSum(int num1, int num2) { cout << num1 + num2; } int main() { int y; y = PrintSum(4, 5); return 0; } a. The void function is missing a "return;" statement. b. The values 4 and 5 cannot be passed directly to PrintSum() c. main() has a return statement that returns the value 0 d. PrintSum() has void return type, so cannot be assigned to a variable
The following program generates an error. Why? void PrintSum(int num1, int num2) { cout << num1 + num2; } int main() { int y; y = PrintSum(4, 5); return 0; } PrintSum() has void return type, so cannot be assigned to a variable
What does this code output? cout << "I "; cout << "want pie." << endl; a. I want pie. b. "I " "want pie." c. I want pie d. I want pie e. I wantpie
What does this code output? cout << "I "; cout << "want pie." << endl; I want pie.
Which is true? a. C came after C++ b. C++ came after C+ c. C++ came after C d. C++ came after C+ but before C
Which is true? C++ came after C
In what year was the first book of C published? a. 1819 b. 1920 c. 1978 d. 2010
In what year was the first book of C published? 1978
An identifier can _____ . a. be a reserved word b. start with an underscore c. contain a period d. contain spaces
An identifier can _____ . start with an underscore
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; } a. sum = 0 / currVal != 0 / sum = sum + currVal b. sum = currVal / currVal == 0 / sum = currVal c. sum = 1 / currVal != 0 / sum = sum + 1 d. cin >> sum / currVal == 0 / cin >> sum
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
A program should compute two times x. Which statement has a logic error? a. y = x + x; b. y = 2 * x; c. y = x * x; d. y = x * 2;
A program should compute two times x. Which statement has a logic error? y = x * x;
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? a. (age < 10) && (age > 55) b. (age < 10) || (age > 55) c. (age >= 10) && (age <= 55) d. (age >= 10) || (age <= 55)
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)
A sequence of instructions that solves a problem is called a(n) _____ . a. instruction b. process c. algorithm d. variable
A sequence of instructions that solves a problem is called a(n) _____ . algorithm
For the given program, how many cout statements will execute? void PrintShippingCharge(double itemWeight) { if ((itemWeight > 0.0) && (itemWeight <= 10.0)) { cout << (itemWeight * 0.75) << endl; } else if ((itemWeight > 10.0) && (itemWeight <= 15.0)) { cout << (itemWeight * 0.85) << endl; } else if ((itemWeight > 15.0) && (itemWeight <= 20.0)) { cout << (itemWeight * 0.95)<< endl; } } int main() { PrintShippingCharge(18); PrintShippingCharge(6); PrintShippingCharge(25); return 0; } a. 1 b. 2 c. 3 d. 9
For the given program, how many cout statements will execute? void PrintShippingCharge(double itemWeight) { if ((itemWeight > 0.0) && (itemWeight <= 10.0)) { cout << (itemWeight * 0.75) << endl; } else if ((itemWeight > 10.0) && (itemWeight <= 15.0)) { cout << (itemWeight * 0.85) << endl; } else if ((itemWeight > 15.0) && (itemWeight <= 20.0)) { cout << (itemWeight * 0.95)<< endl; } } int main() { PrintShippingCharge(18); PrintShippingCharge(6); Pr intShippingCharge(25); return 0; } 2
For what values of x does the default case execute in the code below? x is declared as an integer. switch (x) { case 2: ... break; case 3: ... break; case 4: ... break; default: ... // When does this execute? } a. Only for value 5 b. Only for all values greater than 4 c. Only for values that are not 2, 3, or 4 d. For any value
For what values of x does the default case execute in the code below? x is declared as an integer. switch (x) { case 2: ... break; case 3: ... break; case 4: ... break; default: ... // When does this execute? } Only for values that are not 2, 3, or 4
Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? a. All the errors b. The first error only c. The middle error only d. The last error only
Given a list of syntax errors from a compiler, a programmer should focus attention on which error(s), before recompiling? The first error only
Given an integer vector of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the vector? Choices are in the form XXX / YYY / ZZZ. vector<int> myVect(NUM_ELEMENTS); int cntFours; XXX for (i = 0; YYY; ++i) { if (myVals.at(i) == 4) { ZZZ; } } a. cntFours = myVect.at(0); / i > myVect.size(); / cntFours = myVect.at(i); b. cntFours = myVect.at(1); / i < myVect.size(); / cntFours = myVect.at(i) + 1; c. cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1; d. cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;
Given an integer vector of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the vector? Choices are in the form XXX / YYY / ZZZ. vector<int> myVect(NUM_ELEMENTS); int cntFours; XXX for (i = 0; YYY; ++i) { if (myVals.at(i) == 4) { ZZZ; } } cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;
Given integer vector itemNumbers has three elements with values 33, 34, 35. What are the values in itemNumbers after the following? itemNumbers.push_back(32); a. 32, 34, 35 b. 33, 34, 32 c. 32, 33, 34, 35 d. 33, 34, 35, 32
Given integer vector itemNumbers has three elements with values 33, 34, 35. What are the values in itemNumbers after the following? itemNumbers.push_back(32); 33, 34, 35, 32
Given integers i, j , k, which XXX correctly passes three integer arguments for the following function call? addInts XXX; a. (j, 6 + 7) b. (i + j + k) c. (10, j, k +5) d. (10 15 20)
Given integers i, j , k, which XXX correctly passes three integer arguments for the following function call? addInts XXX; (10, j, k +5)
Given myVector initially has 5 elements with values 3, 4, 6, 8, and 9. What are the values in myVector after the following? myVector.resize(2); a. 3 b. 3, 4 c. 3, 4, 6 d. 3, 4, 6, 8, 9, 0, 0
Given myVector initially has 5 elements with values 3, 4, 6, 8, and 9. What are the values in myVector after the following? myVector.resize(2); 3, 4
Given only int variables a and b, which is a valid expression? a. 4a + 3 b. a + ab c. a + -2 d. 2 x 3
Given only int variables a and b, which is a valid expression? a + -2
Given the following function. To change the function to return the product instead of the sum, how many lines of code need to be changed? int Calculate(int a, int b) { return a + b; } int main() { cout << Calculate(3, 4); cout << Calculate(5, 2); cout << Calculate(6, 7); return 0; } a. 1 b. 2 c. 3 d. 4
Given the following function. To change the function to return the product instead of the sum, how many lines of code need to be changed? int Calculate(int a, int b) { return a + b; } int main() { cout << Calculate(3, 4); cout << Calculate(5, 2); cout << Calculate(6, 7); return 0; } 1
Given two integer vectors origList = {2, 3, 4, 5} and offsetList = {6, 7, 8, 9}, which statement prints out the sum of the second element in the origList with the corresponding element in the offsetList? a. cout << origList + offsetList << endl; b. cout << origList.at(2) + offsetList.at(2) << endl; c. cout << origList.at(1) + offsetList.at(1) << endl; d. cout << origList.at(2) + offsetList.at(2) << endl;
Given two integer vectors origList = {2, 3, 4, 5} and offsetList = {6, 7, 8, 9}, which statement prints out the sum of the second element in the origList with the corresponding element in the offsetList? cout << origList.at(1) + offsetList.at(1) << endl;
Given two vectors, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX/ YYY. vector<string> studentNames(NUM_STUDENTS); vector<int> studentScores(NUM_STUDENTS); unsigned int i; for (i = 0; i < studentScores.size(); ++i) { if (XXX > 80) { cout << YYY << " "; } } a. studentNames.at(i) / studentNames.at(i) b. studentNames.at(i) / studentScores.at(i) c. studentScores.at(i) / studentNames.at(i) d. studentScores.at(i) / studentScores.at(i)
Given two vectors, studentNames that maintains a list of students, and studentScores that has a list of the scores for each student, which XXX and YYY prints out only the student names whose score is above 80? Choices are in the form XXX/ YYY. vector<string> studentNames(NUM_STUDENTS); vector<int> studentScores(NUM_STUDENTS); unsigned int i; for (i = 0; i < studentScores.size(); ++i) { if (XXX > 80) { cout << YYY << " "; } } studentScores.at(i) / studentNames.at(i)
Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first. (x == 5) || (y == 2) && (z == 5) a. false OR (true AND false) --> false OR false --> false b. false OR (true AND false) --> false OR true --> true c. (false OR true) AND false --> true AND false --> false d. (false OR true) AND false --> true AND false --> true
Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first. (x == 5) || (y == 2) && (z == 5) (false OR true) AND false --> true AND false --> false
How many elements does the vector declaration create? vector<int> scores(10); // Vector declaration scores.at(0) = 25; scores.at(1) = 22; scores.at(2) = 18; scores.at(3) = 28; a. 0 b. 4 c. 9 d. 10
How many elements does the vector declaration create? vector<int> scores(10); // Vector declaration scores.at(0) = 25; scores.at(1) = 22; scores.at(2) = 18; scores.at(3) = 28; 10
How many function calls exist in the following code? int Calc1 (int a, int b) { return a + b / 2; } int Calc2 (int a, int b) { return a * b / 100; } int main () { int x; int y; x = Calc1 (5,3); cout << x; y = Calc2 (5,3); cout << y; cout <<Calc2 (5,3); } a. 2 b. 3 c. 4 d. 5
How many function calls exist in the following code? int Calc1 (int a, int b) { return a + b / 2; } int Calc2 (int a, int b) { return a * b / 100; } int main () { int x; int y; x = Calc1 (5,3); cout << x; y = Calc2 (5,3); cout << y; cout <<Calc2 (5,3); } 3
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 } a. 0 b. 1 c. 2 d. 3
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
How many times will the loop iterate, if the input is 105 107 99 103? cin >> x; while (x > 100) { // Do something cin >> x; } a. 1 b. 2 c. 3 d. 4
How many times will the loop iterate, if the input is 105 107 99 103? cin >> x; while (x > 100) { // Do something cin >> x; } 2
If a program compiles without errors, the program is free from _____. a. syntax errors b. logic errors c. runtime errors d. semantic errors
If a program compiles without errors, the program is free from _____. syntax errors
If the input is -5, what is the output? If x less than 0 Put "Low " to output Else if x greater than 0 Put "OK " to output Else if x less than -3 Put "Very low " to output a. Low b. Low Very low c. (Runs, but no output) d. Error: The compiler will complain about a missing else statement
If the input is -5, what is the output? If x less than 0 Put "Low " to output Else if x greater than 0 Put "OK " to output Else if x less than -3 Put "Very low " to output Low
If the input is 5, what is the output? int x; cin >> x; if (x < 10) { cout << "Live "; } else if (x < 20) { cout << "long "; } else if (x < 30) { cout << "and "; } cout << "prosper!"; a. Live b. Live long c. Live prosper! d. Error: The compiler will complain about a missing else statement
If the input is 5, what is the output? int x; cin >> x; if (x < 10) { cout << "Live "; } else if (x < 20) { cout << "long "; } else if (x < 30) { cout << "and "; } cout << "prosper!"; Live prosper!
In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. a. output b. visibles c. variables d. instructions
In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. variables
In what component does a processor store the processor's required instructions and data? a. Mailbox b. Switch c. Memory d. Bit
In what component does a processor store the processor's required instructions and data? Memory
What is the output? void Swap(int& x, int y) { int tmp; tmp = x; x = y; y = tmp; } int main() { int p = 4, q = 3; Swap(p, q); cout << "p = " << p << ", q = " << q << endl; } a. p = 3, q = 3 b. p = 4, q = 3 c. p = 3, q = 4 d. Error: Argument names must match parameter names
What is the output? void Swap(int& x, int y) { int tmp; tmp = x; x = y; y = tmp; } int main() { int p = 4, q = 3; Swap(p, q); cout << "p = " << p << ", q = " << q << endl; } p = 3, q = 3
The numNegatives variable counts the number of negative values in the vector userVals. What should numNegatives be initialized to? vector<int> userVals(20); unsigned int i; numNegatives = XXX; for (i = 0; i < userValues.size(); ++i) { if (userValues.at(i) < 0) { numNegatives = numNegatives + 1; } } a. No initialization needed b. 0 c. -1 d. userVals.at(0)
The numNegatives variable counts the number of negative values in the vector userVals. What should numNegatives be initialized to? vector<int> userVals(20); unsigned int i; numNegatives = XXX; for (i = 0; i < userValues.size(); ++i) { if (userValues.at(i) < 0) { numNegatives = numNegatives + 1; } } 0
The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be? for (XXX) { cout << i << " "; } a. i = -10; i < 10; i = i + 2 b. i = -10; i <= 10; i = i + 2 c. i = -10; (i * 2) < 10; ++i d. i = -10; (i * 2) <= 10, ++i
The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be? for (XXX) { cout << i << " "; } i = -10; i <= 10; i = i + 2
The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error? a. int worldPopulation; b. long worldPopulation; c. long long worldPopulation; d. long long long worldPopulation;
The world population is over 7 billion. Which declaration uses the fewest bits while guaranteeing that worldPopulation can be assigned the value 7 billion without error? long long worldPopulation;
Three sock types A, B, C exist in a drawer. Pulled socks are kept and not returned. Which is true? a. If the first two pulls are different socks, only one more pull is needed for a match b. If the first three pulls are different socks, only one more pull is needed for a match c. If the first two pulls are different socks, at least two more pulls are needed for a match d. If the first three pulls are different socks, at least two more pulls are needed for a match
Three sock types A, B, C exist in a drawer. Pulled socks are kept and not returned. Which is true? If the first three pulls are different socks, only one more pull is needed for a match
What are the ending values in itemCount? vector<int> itemCount; itemCount.push_back(6); itemCount.push_back(7); itemCount.push_back(8); itemCount.pop_back(); a. 6, 7 b. 6, 7, 8 c. 7, 8 d. 6, 7, 0
What are the ending values in itemCount? vector<int> itemCount; itemCount.push_back(6); itemCount.push_back(7); itemCount.push_back(8); itemCount.pop_back(); 6, 7
What does a clock do? a. Stores the computer's programs b. Counts the number of instructions executed by a processor c. Interfaces with peripherals d. Determines the rate of execution for a processor's instructions
What does a clock do? Determines the rate of execution for a processor's instructions
What does the compiler do upon reaching this variable declaration? int x; a. Allocates a memory location for x b. Initializes x with the value -1 c. Converts variable x from a double to an integer d. Increments x's value by 1
What does the compiler do upon reaching this variable declaration? int x; Allocates a memory location for x
What is Moore's law? a. A processor used in cold weather is more likely to fail b. Every action has an equal and opposite reaction c. The capacity of ICs doubles roughly every 18 months d. Any given program will become obsolete
What is Moore's law? The capacity of ICs doubles roughly every 18 months
What is output? double MyFct(double a, double b) { return (a + b) / 2.0; } int main() { double x = 3.0; double y = 5.0; double z = 8.0; double t; t = MyFct(x, y); t = MyFct(t, z); cout << t << endl; return 0; } a. 4.0 b. 6.0 c. 8.0 d. 16.0
What is output? double MyFct(double a, double b) { return (a + b) / 2.0; } int main() { double x = 3.0; double y = 5.0; double z = 8.0; double t; t = MyFct(x, y); t = MyFct(t, z); cout << t << endl; return 0; } 6.0
What is read into string myString for input "One-hit wonder". cin >> myString; a. One b. One- c. One-hit d. One-hit wonder
What is read into string myString for input "One-hit wonder". cin >> myString; One-hit
What is the ending value of cost? int numApples = 3; double cost; cost = 1.2 * numApples; a. 3 b. 3.2 c. 3.6 d. 4
What is the ending value of cost? int numApples = 3; double cost; cost = 1.2 * numApples; 3.6
What is the ending value of sum, if the input is 2 5 7 3? All variables are ints. cin >> x; sum = 0; for (i = 0; i < x; ++i) { cin >> currValue; sum += currValue; } a. 5 b. 10 c. 12 d. 15
What is the ending value of sum, if the input is 2 5 7 3? All variables are ints. cin >> x; sum = 0; for (i = 0; i < x; ++i) { cin >> currValue; sum += currValue; } 12
What is the ending value of x? x = 160 / 20 / 4; a. 2 b. 16 c. 32 d. No value; runtime error
What is the ending value of x? x = 160 / 20 / 4; 2
What is the ending value of y? int x;int y;x = 2;y = ((x + 1) / 5) + (x / 2) ; a. 1 b. 1.6 c. 4.5 d. Error: Division not possible
What is the ending value of y? int x;int y;x = 2;y = ((x + 1) / 5) + (x / 2) ; 1
What is the ending value of y? sqrt(u) returns the square root of u. pow(u, v) returns u raised to the power of v. x = 9.0;y = 4.0;y = pow(sqrt(x), sqrt(y)); a. 8.0 b. 9.0 c. 6561.0 d. Error: The sqrt functions cannot appear in the call to the pow function
What is the ending value of y? sqrt(u) returns the square root of u. pow(u, v) returns u raised to the power of v. x = 9.0;y = 4.0;y = pow(sqrt(x), sqrt(y)); 9.0
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; a. 5 b. 6 c. 7 d. 8
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
What is the output if count is 4? for (i = count; i > 0; --i) { // Output count } a. 4 b. 321 c. 4321 d. 43210
What is the output if count is 4? for (i = count; i > 0; --i) { // Output count } 4321
What is the output, if the input is 3 2 4 5? All variables are ints. cin >> num; for (i = 0; i < num; ++i) { cin >> curr; cout << curr; } a. 24 b. 245 c. 324 d. 3245
What is the output, if the input is 3 2 4 5? All variables are ints. cin >> num; for (i = 0; i < num; ++i) { cin >> curr; cout << curr; } 245
What is the output? int Calc(int num1, int num2) { return 1 + num1 + num2; } int main() { int x; x = Calc(4, 5); cout << Calc(x, 5); return 0; } a. 5 b. 10 c. 16 d. Error: Cannot have a function call in a cout statement
What is the output? int Calc(int num1, int num2) { return 1 + num1 + num2; } int main() { int x; x = Calc(4, 5); cout << Calc(x, 5); return 0; } 16
What is the output? int columns; int rows; for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) { cout << "x"; } cout << endl; } a. xxx xxx b. xx xx xx c. xx xx xx d. xxx xxx
What is the output? int columns; int rows; for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) { cout << "x"; } cout << endl; } xxx xxx
What is the output? int n; for (n = 0; n < 10; n = n + 3) { cout << n << " "; } a. 0 1 2 3 4 5 6 7 8 9 b. 1 4 7 10 c. 0 3 6 9 d. 0 3 6 9 12
What is the output? int n; for (n = 0; n < 10; n = n + 3) { cout << n << " "; } 0 3 6 9
What is the output? int x = 18; while (x > 0) { // Output x and a spacex = x / 3; } a. 6 2 b. 6 2 0 c. 18 6 2 d. 18 6 2 0
What is the output? int x = 18; while (x > 0) { // Output x and a spacex = x / 3; } 18 6 2
What is the output? void WaterTemperatureForCoffee(int temp) { if (temp < 195) { cout << "Too cold."; } else if ((temp >= 195) && (temp <= 205)) { cout << "Perfect temperature."; } else if (temp > 205) { cout << "Too hot."; } } int main( { WaterTemperatureForCoffee(205); WaterTemperatureForCoffee(190); return 0; } a. Too cold. b. Perfect temperature. c. Perfect temperature. Too cold. d. Perfect temperature.Too cold.
What is the output? void WaterTemperatureForCoffee(int temp) { if (temp < 195) { cout << "Too cold."; } else if ((temp >= 195) && (temp <= 205)) { cout << "Perfect temperature."; } else if (temp > 205) { cout << "Too hot."; } } int main( { WaterTemperatureForCoffee(205); WaterTemperatureForCoffee(190); return 0; } Perfect temperature.Too cold.
What is y after executing the statements? x = 4; y = x + 1; x = 3; y = y * 2; a. 6 b. 8 c. 10 d. 12
What is y after executing the statements? x = 4; y = x + 1; x = 3; y = y * 2; 10
What possible values can x % 10 evaluate to? (x is an integer). a. 0..9 b. 1..10 c. 0..10 d. 1..11
What possible values can x % 10 evaluate to? (x is an integer). 0..9
What value of x outputs "Junior"? if (x < 56) { // Output "Sophomore" } else if (x > 56) { // Output "Senior" } else { // Output "Junior" } a. Value 56 b. Values 57 or larger c. Values 55 or 57 d. No such value
What value of x outputs "Junior"? if (x < 56) { // Output "Sophomore" } else if (x > 56) { // Output "Senior" } else { // Output "Junior" } Value 56
What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */ rate = 0.5; */ a. Ignore numItems = 2, but generate code for rate = 0.5. b. Generate code for numItems = 2, but ignore rate = 0.5. c. Ignore both statements. d. Generate an error.
What will a compiler do for the following code? /* numItems = 2; /* Total items to buy */ rate = 0.5; */ Generate an error.
`What will a compiler do for the following three lines of code? // x = 2; // width // y = 0.5 // z = x * y; Total area a. Yield an error for line 1 (x = ...) b. Yield an error for line 2 (y = ...) c. Yield an error for line 3 (z = ...) d. Ignore all three lines
What will a compiler do for the following three lines of code? // x = 2; // width // y = 0.5 // z = x * y; Total area Ignore all three lines
Which XXX / YYY declare a vector having MAX_SIZE elements and initializes all elements with -1? const int MAX_SIZE = 4; vector<int> myNumbers(XXX); int i; for (i = 0; i < YYY; ++i) { myNumbers.at(i) = -1; } a. MAX_SIZE / MAX_SIZE b. MAX_SIZE / MAX_SIZE - 1 c. MAX_SIZE - 1 / MAX_SIZE d. MAX_SIZE - 1 / MAX_SIZE - 1
Which XXX / YYY declare a vector having MAX_SIZE elements and initializes all elements with -1? const int MAX_SIZE = 4; vector<int> myNumbers(XXX); int i; for (i = 0; i < YYY; ++i) { myNumbers.at(i) = -1; } MAX_SIZE / MAX_SIZE
Which XXX and YYY correctly output the smallest value? Vector userVals contains integers (which may be positive or negative). Choices are in the form XXX / YYY. // Determine smallest (min) value int minVal; XXX for (i = 0; i < userVals.size(); ++i) { if (YYY) { minVal = userVals.at(i); } } cout << "Min: " << minVal << endl; a. minVal = 0; / userVal > minVal b. minVal = 0; / userVal < minVal c. minVal = userVals.at(0); / userVals.at(i) > minVal d. minVal = userVals.at(0); / userVals.at(i) < minVal
Which XXX and YYY correctly output the smallest value? Vector userVals contains integers (which may be positive or negative). Choices are in the form XXX / YYY. // Determine smallest (min) value int minVal; XXX for (i = 0; i < userVals.size(); ++i) { if (YYY) { minVal = userVals.at(i); } } cout << "Min: " << minVal << endl; minVal = userVals.at(0); / userVals.at(i) < minVal
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; } a. w < 100 / cin >> w b. w >= 100 / (nothing) c. w < 100 / (nothing) d. w >= 100 / cin >> w
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
Which XXX calls GetUserScore() to get the user's name and score and store those values in the userName and userScore variables? void GetUserScore(string& userName, int& userScore) { cout << "Enter your name: " << endl; cin >> userName; cout << "Enter your score: " << endl; cin >> userScore; } int main() { string userName; int userScore; XXX; cout << userName << ", " << userScore << endl; return 0; } a. GetUserScore(string& userName, int& userScore); b. GetUserScore(string userName, int userScore); c. GetUserScore(userName, userScore); d. GetUserScore(&userName, &userScore);
Which XXX calls GetUserScore() to get the user's name and score and store those values in the userName and userScore variables? void GetUserScore(string& userName, int& userScore) { cout << "Enter your name: " << endl; cin >> userName; cout << "Enter your score: " << endl; cin >> userScore; } int main() { string userName; int userScore; XXX; cout << userName << ", " << userScore << endl; return 0; } GetUserScore(userName, userScore);
Which XXX causes every character in string inputWord to be output? for (XXX) { cout << inputWord.at(i) << endl; } a. i = 0; i < (inputWord.size() - 1); ++i b. i = 0; i < inputWord.size(); ++i c. i = 0; i < (inputWord.size() + 1); ++i d. i = 0; i <= inputWord.size(); ++i
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 XXX causes the program to output the message "Hello!"? void PrintMessage() { cout << "Hello!"; } int main() { XXX; return 0; } a. cout << PrintMessage() b. PrintMessage() c. void PrintMessage() d. PrintMessage("Hello!")
Which XXX causes the program to output the message "Hello!"? void PrintMessage() { cout << "Hello!"; } int main() { XXX; return 0; } PrintMessage()
Which XXX is valid for the following code? int CalcSum(int a, int b) { return a + b; } int main() { int y; XXX return 0; } a. y = CalcSum(); b. y = CalcSum(4, 5); c. y = CalcSum(4 + 5); d. CalcSum(y, 4, 5);
Which XXX is valid for the following code? int CalcSum(int a, int b) { return a + b; } int main() { int y; XXX return 0; } y = CalcSum(4, 5);
Which XXX outputs all the elements of vector myVals? for (i = 0; XXX; ++i) {cout << myVals.at(i) << " ";} a. i < myVals.size; b. i <= myVals.size(); c. i < myVals.size(); d. No such expression as the number of elements is unknown.
Which XXX outputs all the elements of vector myVals? for (i = 0; XXX; ++i) {cout << myVals.at(i) << " ";} i < myVals.size();
Which YYY outputs the string in reverse? Ex: If the input is "Oh my", the output is "ym hO". int i; string str; getline(cin, str); for (YYY) { cout << str.at(i); } a. i = str.length(); i < 0; --i b. i = str.length(); i > 0; --i) c. i = str.length() - 1; i >= 0; --i) d. i = str.length() + 1; i > 0; --i)
Which YYY outputs the string in reverse? Ex: If the input is "Oh my", the output is "ym hO". int i; string str; getline(cin, str); for (YYY) { cout << str.at(i); } i = str.length() - 1; i >= 0; --i)
Which assigns the last vector element with 20? vector<int> userNum(N_SIZE); a. userNum.at(20); b. userNum.at() = 20; c. userNum.at(N_SIZE) = 20; d. userNum.at(N_SIZE - 1) = 20;
Which assigns the last vector element with 20? vector<int> userNum(N_SIZE); userNum.at(N_SIZE - 1) = 20;
Which assigns the vector's first element with 99? vector<int> myVector(4); a. myVector.at() = 99; b. myVector.at(-1) = 99; c. myVector.at(0) = 99; d. myVector.at(1) = 99;
Which assigns the vector's first element with 99? vector<int> myVector(4); myVector.at(0) = 99;
Which assigns the vector's last element with 99? vector<int> myVector(15); a. myVector.at(0) = 99; b. myVector.at(14) = 99; c. myVector.at(15) = 99; d. myVector.at(16) = 99;
Which assigns the vector's last element with 99? vector<int> myVector(15); myVector.at(14) = 99;
Which best describes what is output? Assume v is a large vector of ints. int i; int s; s = v.at(0); for (i = 0; i < v.size(); ++i) { if (s > v.at(i)) { s = v.at(i); } } cout << s; a. first value in v b. max value in v c. min value in v d. last value in v
Which best describes what is output? Assume v is a large vector of ints. int i; int s; s = v.at(0); for (i = 0; i < v.size(); ++i) { if (s > v.at(i)) { s = v.at(i); } } cout << s; min value in v
Which corrects the logic error in the following program? void FindPrevNext (int x, int prev, int next) { prev = x - 1; next = x + 1; } int main () { int x = 10; int y; int z; FindPrevNext (x, y, z); cout << "Previous = " << y << ", Next = " << z; return 0; } a. The variables prev and next should be passed by reference b. The variables y and z should be initialized to 0 c. The function FindPrevNext() should have a return statement for variables prev and next d. prev and next should be initialized in FindPrevNext()
Which corrects the logic error in the following program? void FindPrevNext (int x, int prev, int next) { prev = x - 1; next = x + 1; } int main () { int x = 10; int y; int z; FindPrevNext (x, y, z); cout << "Previous = " << y << ", Next = " << z; return 0; } The variables prev and next should be passed by reference
Which declaration assigns a variable with 5 such that the value can not be later changed? a. const int = 5; b. int numItems = 5; c. int NUM_ITEMS = 5; d. const int NUM_ITEMS = 5;
Which declaration assigns a variable with 5 such that the value can not be later changed? const int NUM_ITEMS = 5;
Which declares two related integer vectors named personName and personAge each with 50 elements? a. vector<int> personName, personAge; b. vector<int> personName, personAge = 50; c. vector<int> personName = 50; vector<int> personAge = 50; d. vector<int> personName(50); vector<int> personAge(50);
Which declares two related integer vectors named personName and personAge each with 50 elements? vector<int> personName(50); vector<int> personAge(50);
Which expression doubles x? a. x += 2; b. x *= 2; c. x *= x; d. x *= x * 2;
Which expression doubles x? x *= 2;
Which expression evaluates to 3.5? int x = 7; int y = 1; a. x * (1 / 2) b. (x / 2.0) c. x.0 / 2 d. (x / 2) * 1.0
Which expression evaluates to 3.5? int x = 7; int y = 1; (x / 2.0)
Which expression evaluates to false if x is 0 and y is 10? a. (x == 0) && (y == 10) b. (x == 0) && (y == 20) c. (x == 0) || (y == 10) d. (x == 0) || (y == 20)
Which expression evaluates to false if x is 0 and y is 10? (x == 0) && (y == 20)
Which expression fails to compute the area of a triangle having base b and height h (area is one-half base time height)? a. (1.0 / 2.0 ) * b * h b. (1 / 2) * b * h c. (b * h) / 2.0 d. 0.5 * b * h
Which expression fails to compute the area of a triangle having base b and height h (area is one-half base time height)? (1 / 2) * b * h
Which expression for YYY correctly outputs that x is between 50-100? if (YYY) { // Output "50, 51, ..., 99, 100" } a. (x >= 50) || (x <= 100) b. 50 >= x <= 100 c. 50 <= x <= 100 d. (x >= 50) && (x <= 100)
Which expression for YYY correctly outputs that x is between 50-100? if (YYY) { // Output "50, 51, ..., 99, 100" } (x >= 50) && (x <= 100)
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; } a. score < 91 / "Great job" / "Nice try" b. score < 91 / "Nice try" / "Great job" c. score > 90 / "Nice try" / "Great job" d. (Not possible for given code)
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"
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+" } a. x < 29 / x >= 29 b. x < 30 / x >= 30 c. x < 30 / x < 40 d. x > 29 / x > 40
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
Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young Adolescent" for ages between 10 and 20? int u; cin >> u; if (YYY) { cout << "Young"; if (ZZZ) { cout << " Adolescent"; } } a. YYY: u < 20 ZZZ: u < 10 b. YYY: u < 20 ZZZ: u > 10 c. YYY: u > 20 ZZZ: u < 10 d. YYY: u > 20 ZZZ: u > 10
Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young Adolescent" for ages between 10 and 20? int u; cin >> u; if (YYY) { cout << "Young"; if (ZZZ) { cout << " Adolescent"; } } YYY: u < 20 ZZZ: u > 10
Which for loop will iterate 100 times? a. for (i = 0; i < 99; i++) b. for (i = 1; i < 99; i++) c. for (i = 0; i < 100; i++) d. for (i = 1; i < 100; i++)
Which for loop will iterate 100 times? for (i = 0; i < 100; i++)
Which input value causes "Goodbye" to be output next? int x; cin >> x; while (x >= 0) { // Do something cin >> x; } cout << "Goodbye"; a. -1 b. 0 c. 1 d. No such value
Which input value causes "Goodbye" to be output next? int x; cin >> x; while (x >= 0) { // Do something cin >> x; } cout << "Goodbye"; -1
Which is a correct scientific notation for the floating-point literal: 0.00001 a. 0.1e-6 b. 0.1e-5 c. 1.0e-5 d. 1.0e-6
Which is a correct scientific notation for the floating-point literal: 0.00001 1.0e-5
Which is a valid definition for a function that passes two integers (a, b) as arguments, and returns an integer? a. myFunction(int a, int b) b. int myFunction(a, b) c. void myFunction (a, b) d. int myFunction(int a, int b)
Which is a valid definition for a function that passes two integers (a, b) as arguments, and returns an integer? int myFunction(int a, int b)
Which is an example of a process? a. int b. y, 10 c. 15 d. x + y
Which is an example of a process? x + y
Which is an invalid access for the vector? vector<int> numsList(5); int x = 3; a. numsList.at(x-3) b. numsList.at(0) c. numsList.at(x+2) d. numsList.at((2*x) - x)
Which is an invalid access for the vector? vector<int> numsList(5); int x = 3; numsList.at(x+2)
Which is best declared as a constant? a. The number of people in a car b. The number of feet in a yard c. The number of leaves on a tree d. The number of insects in a room
Which is best declared as a constant? The number of feet in a yard
Which is not a component of a computer? a. Clock b. Memory c. Processor d. Programmer
Which is not a component of a computer? Programmer
Which is not a valid identifier? a. firstName b. first_name c. 1stName d. name1
Which is not a valid identifier? 1stName
Which is true for comments? a. The compiler converts comments into a series of machine instructions. b. The compiler translates comments into ASCII values. c. The compiler allocates memory for comments along with for variables. d. The compiler does not generate machine code for comments.
Which is true for comments? The compiler does not generate machine code for comments.
Which item converts a high-level language program to low-level machine instructions? a. Compiler b. Machine instruction c. Assembly language d. Memory
Which item converts a high-level language program to low-level machine instructions? Compiler
Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? a. if (val > 0) { cout << "Non-negative"; } else { cout << "Negative"; } b. if (val >= 0) { cout << "Non-negative"; } else { cout << "Negative"; } c. if (val < 0) { cout << "Non-negative"; } else { cout << "Negative"; } d. if (val <= 0) { cout << "Negative"; } else { cout << "Non-negative"; }
Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? if (val >= 0) { cout << "Non-negative"; } else { cout << "Negative"; }
Which text most closely resembles the form in which one instruction is stored in a single location of a typical computer's memory? a. w = (x + y) * (y - z) b. w = x + 000111 - (y * 1110101) c. Add 34, #9, 25 d. (Mul 45, 2) + (Mul 33, 5) + (Mul 4, 8)
Which text most closely resembles the form in which one instruction is stored in a single location of a typical computer's memory? Add 34, #9, 25