C++ COP1220 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Given integers i, j , k, which XXX correctly passes three integer arguments for the following function call? addInts XXX; (j, 6 + 7) (i + j + k) (10, j, k +5) (10 15 20)

(10, j, k +5)

Given function Multiply(u, v) that returns u * v, and Add(u, v) that returns u + v, which expression corresponds to: Add(Multiply(x, Add(y, z)), w)

(x * (y + z)) + w

Which input value causes "Goodbye" to be output next? int x;cin >> x;while (x >= 0) {// Do somethingcin >> x;}cout << "Goodbye"; -1 0 1 No such value

-1

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

B

Which header file is required to access the file pointer (FILE*)? a.stdlib.h b.stddef.h c.stdio.h d.stdint.h

C

Which includes a header file in the same directory as the file including the header? a.#include "myheader.h"; b.#include 'myheader.h'; c.#include "myheader.h" d.#include 'filename.h'

C

Which is a valid preprocessor directive? a.#include filename.h b.#include filename.h; c.#include "filename.h" d.#include "filename.h";

C

Which is correct? a.int area = 3.2; b.500 = int distance; c.int changeAmt = -321; d.212 = length;

C

Which is not a valid identifier? a.firstName b.first_name c.1stName d.name1

C

Which assigns the last vector element with 20? vector<int> userNum(N_SIZE);

userNum.at(N_SIZE - 1) = 20;

Which assigns the last vector element with 20? vector<int> userNum(N_SIZE); userNum.at(20); userNum.at() = 20; userNum.at(N_SIZE) = 20; userNum.at(N_SIZE - 1) = 20;

userNum.at(N_SIZE - 1) = 20;

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____.

variables

Which declares two related integer vectors named personName and personAge each with 50 elements? vector<int> personName(50); vector<int> personAge(50); vector<int> personName, personAge = 50; vector<int> personName = 50; vector<int> personAge = 50;

vector<int> personName(50);vector<int> personAge(50);

The _____ is a process that manages programs and interfaces with peripherals.

operating system

What code for XXX, YYY correctly swaps a and b? Choices are written as XXX / YYY. XXX; a = b; YYY; b = tmp; Question options: tmp = a / (nothing) tmp = a / tmp = b tmp = b / (nothing) (nothing) / tmp = a

tmp = a / (nothing)

Which character array declaration is appropriate? a.char name[5] = "Alexa"; b.char name[5] = "Alex"; c.char name[5] = "Alexandria"; d.char name[5] = "Alexander";

B

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

B

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

B

Which expression for YYY will result in an output of "Pass" only if x is exactly 32? int x; scanf("%d", &x); if(YYY) { printf("Pass"); }else {printf("Fail"); } a.x != 32 b.x == 32 c.x >= 32 d.x <= 32

B

Which function has two int parameters, startVal and endVal, that are passed by pointer? a.void function SwapVals(int startVal, int endVal) b.void function SwapVals(int* startVal, int* endVal) c.void function SwapVals(int &startVal, int &endVal) d.void function SwapVals(*startVal, *endVal)

B

Which is a valid compound operator? a. $= b. %= c. != d. ?=

B

Which is true regarding how functions work? a.After a function returns, its local variables keep their values, which serve as their initial values the next time the function is called b.A function's local variables are discarded upon a function's return; each new call creates new local variables in memory c.A return address indicates the value returned by the function d.If a function returns a variable, the function stores the variable's value until the function is called again

B

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

For the given pseudocode, which XXX and YYY will output the smallest non-negative input (stopping when a negative value is input)? Choices are in the form XXX / YYY. min = 0 val = Get next input min = val While val is not negative If XXX YYY val = Get next input Put min to output a.val > 0 / min = val b.min < val / val = min c.val > min / val = min d.val < min / min = val

d

How many x's will be output? i = 1; while (i <= 3) { j = 1;while (j <= i) { printf("x"); ++j; } printf("\n"); ++i; } a. 0 b. 3 c. 4 d. 6

d

If the input is 12, what is the final value for numItems? int x; int numItems = 0; scanf("%d", &x); if (x <= 12) { numItems = 100;} else { numItems = 200;} numItems = numItems + 1; a. 201 b. 100 c. 200 d. 101

d

What is the output for x = 15? switch (x) { case 10: // Output: "First " break; case 20: // Output: "Second " break; default: // Output: "No match " break; } a.First b.Second c.First Second d.No match

d

What is the output? char letter1; char letter2; letter1 = 'p'; while (letter1 <= 'q') { letter2 = 'x'; while (letter2 <= 'y') { printf("%c%c ", letter1, letter2); ++letter2; } ++letter1; } a.px b.px py c.qx qy d.px py qx qy

d

Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline? int[] keysList = new int[SIZE_LIST]; int[] itemsList = new int[SIZE_LIST]; Question options: System.out.println(keysList[SIZE_LIST - 1] + ", " + itemsList[SIZE_LIST - 1]); System.out.println(keysList[SIZE_LIST] + ", " + itemsList[SIZE_LIST]); for (i = 0; i < SIZE_LIST - 1; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]); for (i = 0; i < SIZE_LIST; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]);}

for (i = 0; i < SIZE_LIST; ++i) { System.out.println(keysList[i] + ", " + itemsList[i]);

Which is an invalid access for the vector? vector<int> numsList(5);int x = 3; numsList.at(x-3) numsList.at(0) numsList.at(x+2) numsList.at((2*x) - x)

numsList.at(x+2)

Which is an invalid access for the array? int[] numsList = new int[5]; int x = 3; Question options: numsList[x-3] numsList[0] numsList[x+2] numsList[(2*x) - x]

numsList[x+2]

Which declares two related integer vectors named personName and personAge each with 50 elements? vector<int> personName, personAge; vector<int> personName, personAge = 50; vector<int> personName = 50;vector<int> personAge = 50; vector<int> personName(50);vector<int> personAge(50);

vector<int> personName(50);vector<int> personAge(50);

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 somethingYYY;} w < 100 / cin >> w w >= 100 / (nothing) w < 100 / (nothing) w >= 100 / cin >> w

w < 100 / cin >> w

Given x = 4 and y = 8, what are the ending values of x and y? x = y; y = x; x = y; Question options: x = 4, y = 4 x = 4, y = 8 x = 8, y = 4 x = 8, y = 8

x = 8, y = 8

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 columns;int rows;for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) {cout << "x";}cout << endl;} xxx xxx xx xx xx xxxxxx xxxxxx

xxxxxx

Which XXX is valid for the following code? int CalcSum(int a, int b) {return a + b;}int main() {int y;XXXreturn 0;} y = CalcSum(); y = CalcSum(4, 5); y = CalcSum(4 + 5); CalcSum(y, 4, 5);

y = CalcSum(4, 5);

The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int[] userVals = new int[20]; int i; numNegatives = XXX; for (i = 0; i < 20; ++i) { if (userValues[i] < 0) { numNegatives = numNegatives + 1; } } Question options: No initialization needed 0 -1 userVals[0]

0

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 2 3 4

1

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

How many x's will be output? i = 1; while (i <= 3) { j = 1; while (j <= i) { cout << "x";++j; } cout << endl; ++i; }

6

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 6, 7, 8 7, 8 6, 7, 0

6, 7

Given char x, which reads an input character into x? a. scanf("%c", &x); b. scanf("%s", x); c. scanf("%s", &x); d. scanf("%c", x);

A

What is output? int pop = 1340; printf("There are %06d residents of the city. \n", pop); a.There are 001340 residents of the city. b.There are 1340 residents of the city. c.There are 0001340 residents of the city. d.There are +0001340 residents of the city.

A

What is the ending value of x? x = 160 / 20 / 4; a.2 b.16 c.32 d.No value; runtime error

A

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

A

What is the ending value of y? int x; int y; x = 6; y = (1 / 2) * (x + 5); a.0 b.3 c.5 d.6

A

What is the error in this code? void MyFct(int& x) { x = (x * x) + 1; } int main(void) { printf("%d", MyFct(9)); return 0; } a.MyFct() cannot be called with a literal b.MyFct() is missing a return statement c.MyFct() cannot both read and assign x d.No error exists; the program will output 82

A

What is the output? for (i = 0; i <= 10; ++i) { if (i == 6) continue; else printf("%d ", i); } a. 0 1 2 3 4 5 b. 0 1 2 3 4 5 6 c. 0 1 2 3 4 5 7 8 9 d. 0 1 2 3 4 5 7 8 9 10

d

Given string str1 and string str2, which expression is true? str1 = "Flat"; str2 = "Last"; a. strcmp(str1, str2) == 0 b. strcmp(str1, str2) < 0 c. strcmp(str1, str2) > 0 d. (Comparison not possible)

b

Which is true regarding accessing elements of arrays and vectors?

Any arbitrary array element can be accesses, but vector elements must be accessed sequentially

For what values of x will "Medium" be output? If x > 40: Output "Large"Else If x > 20: Output "Medium"Else If x > 10: Output "Small"

Any x from 21 to 40

An identifier can _____ . a.be a reserved word b.start with an underscore c.contain a period d.contain spaces

B

Assuming char* firstSymbol; is already declared, return a pointer to the first instance of an '!' in userInput. a.firstSymbol = strchr(*userInput,'!'); b.firstSymbol = strchr(userInput, '!'); c.firstSymbol = strchr('!', userInput); d.firstSymbol = strrchr('!', userInput);

B

What is the output? #include <stdio.h> int main(void) { double dividend = 0.0; double divisor = 0.0; printf("%lf\n", dividend / divisor); dividend = 3.0; printf("%lf\n", dividend / divisor); return 0; } a.inf nan b.nan inf c.inf 0.0 d.nan 0.0

B

Which item converts a high-level language program to low-level machine instructions?

Compiler

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

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

Which XXX will output only values up to 3? i is an int. for (i = 1; i < 10; i++) { cout << i << " "; XXX { break; } }

if (i == 3)

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 / (nothing) w >= 100 / (nothing) w < 100 / cin >> w w >= 100 / cin >> w

w < 100 / cin >> w

For an integer constant x, which statement will yield a compiler error? y = x; w = x + 1; z = x + x; x = y + 1;

x = y + 1;

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 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;}} No initialization needed 0 -1 userVals.at(0)

0

What is the output? int n;for (n = 0; n < 10; n = n + 3) {cout << n << " ";} 0 1 2 3 4 5 6 7 8 9 1 4 7 10 0 3 6 9 0 3 6 9 12

0 3 6 9

Which is the correct representation of 3.9e-5?

0.000039

The binary equivalent of the decimal number 15 is _____ .

00001111

What are the ending contents of the array? Choices show elements in index order 0, 1, 2. int[] yearsList = new int[3]; yearsList[0] = 5; yearsList[1] = yearsList[0]; yearsList[0] = 10; yearsList[2] = yearsList[1]; Question options: 5, 5, 5 5, 10, 10 10, 10, 10 10, 5, 5

10, 5, 5

What are the ending contents of the vector? Choices show elements in index order 0, 1, 2. vector<int> yearsList(3); yearsList.at(0) = 5; yearsList.at(1) = yearsList.at(0); yearsList.at(0) = 10; yearsList.at(2) = yearsList.at(1);

10, 5, 5

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

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;} 5 10 12 15

12

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;} 5 10 16 Error: Cannot have a function call in a cout statement

16

What is the output? int x = 18;while (x > 0) {// Output x and a spacex = x / 3; } 6 2 6 2 0 18 6 2 18 6 2 0

18 6 2

Which is not a valid identifier? name1 first_name 1stName firstName

1stName

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;} 1 2 3 9

2

Given a vector/array with values 5, 10, 15, 20, 25, what are the fewest number of swaps needed to reverse the list?

2

How many times will the loop iterate, if the input is 105 107 99 103? cin >> x;while (x > 100) {// Do somethingcin >> x;} 1 2 3 4

2

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);} 2 3 4 5

3

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 3, 4 3, 4, 6 3, 4, 6, 8, 9, 0, 0

3, 4

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); 32, 34, 35 33, 34, 32 32, 33, 34, 35 33, 34, 35, 32

33, 34, 35, 32

What is the ending value of the element at index 0? int[] numbers = new int[10]; numbers[0] = 35; numbers[1] = 37; numbers[1] = numbers[0] + 4; Question options: 0 35 37 39

35

What is the ending value of the element at index 1? int[] numbers = new int[10]; numbers[0] = 35; numbers[1] = 37; numbers[1] = numbers[0] + 4; Question options: 0 35 37 39

39

What is the output if count is 4? for (i = count; i > 0; --i) { // Output count }

4321

What is the output if count is 4? for (i = count; i > 0; --i) {// Output count} 4 321 4321 43210

4321

What is the index of the last element?int[] numList = new int[50]; Question options: 0 49 50 Unknown, because the array has not been initialized.

49

Given vector userVal has 4 elements. What is the size of userVal after the following? userVal.resize(5);

5

What is the ending value of y if x is 50? y and x are ints. y = (x < 21) ? 100 : x;

50

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;} 4.0 6.0 8.0 16.0

6.0

What is the output, if the input is 3 2 1 0? cin >> x; while (x > 0) { cout << 2 * x << " "; }

666666666...infinte

Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i; for (i = 0; i < 4; ++i) { x[i] = x[i + 1]; } Question options: 4, 4, 7, 3, 0 7, 3, 0, 8, 8 7, 3, 0, 8, 4 Error: Invalid access

7, 3, 0, 8, 8

What is the ending value of z? x = 0; y = 3; z = pow(x + 2, y);

8

A double variable stores a value in 64 bits, using some bits for mantissa, some for exponent, and one for sign. Which is true about a double variable? a. Limited bits may cause some rounding of the mantissa. b. If a value is too large for a double, a float should be used instead. c. If a value is too large for a double, a long should be used instead. d. The compiler may sometimes use 63 bits for the mantissa.

A

Given an array customerNames that stores 10 strings, each with a maximum of 50 characters. Identify the statement that will correctly output the fifth string in customerNames. char customerNames[10][50]; strcpy(customerNames[0], "Bob"); strcpy(customerNames[1], "Jim"); strcpy(customerNames[2], "Sally"); strcpy(customerNames[3], "Juan"); strcpy(customerNames[4], "Bella"); strcpy(customerNames[5], "Sam"); a.printf("%s \n", customerNames[4]); b.printf("%s \n", customerNames[5]); c.printf("%s \n", customerNames); d.printf("%s \n", customerNames[4][4]);

A

Given function Multiply(u, v) that returns u * v, and Add(u, v) that returns u + v, which expression corresponds to: Add(Multiply(x, Add(y, z)), w) a.(x * (y + z)) + w b.(x + (y + z) * w) c.((x * y) + z) + w d.(x * (y + z) * w)

A

Given two arrays, which code will output all the arrays' elements, in the order key, item followed by a newline?int keysList[SIZE_LIST];int itemsList[SIZE_LIST]; a.for (i = 0; i < SIZE_LIST; ++i) { printf("%d, %d \n", keysList[i], itemsList[i]); } b.printf("%d, %d \n", keysList[SIZE_LIST - 1], itemsList[SIZE_LIST - 1]); c.printf("%d, %d \n", keysList[SIZE_LIST], itemsList[SIZE_LIST]); d.for (i = 0; i < SIZE_LIST - 1; ++i) { printf("%d, %d \n", keysList[i], itemsList[i]); }

A

How many function parameters exist in the code? double FahrenheitToCelsius(double fahrenheit) { return (fahrenheit - 32.0) * 5.0 / 9.0; } int main(void) { double fahrenheit; scanf("%lf", &fahrenheit); int c1; int c2; int c3; int c4; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(78); c4 = FahrenheitToCelsius(100); return 0; } a.1 b.3 c.4 d.Error: Cannot pass a variable to a function

A

Identify the correct declaration of an array of strings. a.char stringArr[10][50]; b.char stringArr[10]; c.stringArr[10][50]; d.char[50] stringArr[10];

A

Identify the statement that checks whether myChar exists within myString, returning NULL if myChar does not exist, or returning the address of the first occurrence if myChar does exist? a.strchr(myString, myChar) b.strcat(myString, myChar) c.if(myChar != NULL) d.strcmp(myString, myChar)

A

If a program compiles without errors, the program is free from _____. a.syntax errors b.logic errors c.runtime errors d.semantic errors

A

What is the ending value of myStr? char myStr[5] = "Hi"; strcpy(myStr, "Hey"); a.Hi b.Hey c.HiHey d.HeyHi

B

The feof() function of input streams returns a _____. a.false when the end of the file has not been reached b.false when the end of the file has been reached c.true when the end of the file has not been reached d.true when the end of the file has been reached

A

The fopen(str) function has a string parameter str that specifies the _____ of the file to open. a.name b.size c.contents d.reference

A

What are the possible values for ((rand() % 9) + -4)? a.-4...4 b.-9...9 c.0...4 d.0...9

A

What are the possible values for rand() % 6? a.0...5 b.0...6 c.0...7 d.1...6

A

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

A

What does this code output? printf("I "); printf("want pie.\n"); a.I want pie. b."I " "want pie." c.I want pie d.I want pie e.I wantpie

A

What is the final value of y? int x = 6; int y = 2; if (x < 10) { if (y < 5) { y = y + 1; } else { y = 7; } } else { y = y + 10; } a.3 b.7 c.12 d.13

A

What is the output if myContact.txt file does not exist? int main(void) { FILE* inputFile = NULL; printf("Opening the file."); inputFile =fopen("myContact.txt", "r"); if (inputFile ==NULL) { printf("Could not open the file. "); return 1; } fclose(inFS); return 0; } a.Opening the file. Could not open the file. b.Could not open the file. c.Opening the file. d.Could not open the file. Opening the file.

A

What is the output? const int MAX_LEN = 10; char userStr[MAX_LEN] = "PASS123"; int i; for (i = 0; userStr[i] != '\0'; ++i) { userStr[i] = tolower(userStr[i]); } a.pass123 b.Pass123 c.PASS123 d.Error: The string contains a digit that cannot be converted to lowercase

A

What is the output? void Swap(int& x, int y) { int tmp; tmp = x; x = y;y = tmp; } int main(void) { int p = 4, q = 3; Swap(p, q); printf("p = %d, q = %d\n", p, q); return 0; } a.p = 3, q = 3 b.p = 4, q = 3 c.p = 3, q = 4 d.Error: Argument names must match parameter names

A

Which function call passes a string myStr to the given function? void StrMod(char modString[]) { int i; // Loop index for (i = 0; i < strlen(modString); ++i) { if (modString[i] == '.') { modString[i] = '!'; } } } a.StrMod(myStr); b.StrMod(myStr[]); c.StrMod(char myStr[]); d.StrMod(char myStr[strlen(myStr)]);

A

Which input value causes "Goodbye" to be output next? int x; scanf("%d", &x); while (x >= 0) { // Do something scanf("%d", &x); } printf("Goodbye\n"); a.-1 b.0 c.1 d.No such value

A

myChar is a character variable and is the only declared variable. Which assignment is valid? a.myChar = 't'; b.myChar = "t"; c.myChar = t; d.myChar = 'tx';

A

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

What is output? double MyFct(double a, double b) { return (a + b) / 2.0; } int main(void) { double x = 3.0; double y = 5.0; double z = 8.0; double t; t = MyFct(x, y); t = MyFct(t, z); printf("%lf\n", t); return 0; } a.4.0 b.6.0 c.8.0 d.16.0

B

Choose the statement(s) that generate(s) this output: I wish you were here a.printf("I wish", "you were here"); b.printf("I wish\n"); printf("you were here"); c.printf("I wish"); printf("you were here\n"); d.printf("I wish", \n, "you were here");

B

For the given program, how many printf statements will execute? void PrintShippingCharge(double itemWeight) { if ((itemWeight > 0.0) && (itemWeight <= 10.0)) { printf("%lf\n", itemWeight * 0.75); } else if ((itemWeight > 10.0) && (itemWeight <= 15.0)) { printf("%lf\n", itemWeight * 0.85); } else if ((itemWeight > 15.0) && (itemWeight <= 20.0)) {printf("%lf\n", itemWeight * 0.95); } } int main(void { PrintShippingCharge(18); PrintShippingCharge(6); PrintShippingCharge(25); return 0; } a.1 b.2 c.3 d.9

B

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

B

Given integer variables totalTickets, vipTickets, and sessionNum, which line of code correctly calls the following function? void FinalTally(int* totalAttendees, int* vipAttendees, int numSessions); a.FinalTally(totalTickets, vipTickets, &sessionNum); b.FinalTally(&totalTickets, &vipTickets, sessionNum); c.FinalTally(*totalTickets, *vipTickets, sessionNum); d.FinalTally(&totalTickets, &vipTickets, &sessionNum);

B

Given string str is "Great", which choice has all matching expressions? a.strcmp(str, "Great"), strcmp(str, "great") b.strcmp(str, "Great") c.strcmp(str, "Great"), strcmp(str, "Great!") d.strcmp(str, "Great"), strcmp(str, "great"), strcmp(str, "Great!")

B

Given that integer array x has elements 4, 7, 3, 0, 8, what are the elements after the loop? int i; for (i = 0; i < 4; ++i) { x[i] = x[i + 1]; } a.4, 4, 7, 3, 0 b.7, 3, 0, 8, 8 c.7, 3, 0, 8, 4 d.Error: Invalid access

B

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(void) { int x; int y; x = Calc1 (5,3); printf("%d", x); y = Calc2 (5,3); printf("%d", &y); printf("%d", Calc2 (5,3)); return 0; } a.2 b.3 c.4 d.5

B

The following program results in a compiler error. Why? int FindMin(int a, int b) { int min; if (a < b) { min = a; } else { min = b; } return min; int main(void) { int x;int y; scanf("%d", &x); scanf("%d", &y); min = FindMin(x,y); printf("The smaller number is: %d\n", min); return 0; a.FindMin() should be defined after main(), not before. b.The variable min is declared in FindMin(), but is used in main() c.The variable min is not initialized d.The variable min should be a parameter

B

The numNegatives variable counts the number of negative values in the array userVals. What should numNegatives be initialized to? int userVals[20]; unsigned int i; numNegatives = XXX; for (i = 0; i < 20; ++i) { if (userValues[i] < 0) { numNegatives = numNegatives + 1; } } a.No initialization needed b.0 c.-1 d.userVals[0]

B

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

B

What is the ending value of z? int x = 5; int y = 12; double z; z = (double)(y / x); a.0.0 b.2.0 c.2.4 d.3.0

B

What is the output? int MyFct(int x) { int y; x = x * 2; y = x + 1; return y; } int main(void) { int a; a = 5; printf("%d %d", a, MyFct(a)); return 0; } a.5 6 b.5 11 c.6 11 d.Error: Cannot assign parameter x

B

What is the relation between a string's length and the string's last index? a.lastIndex == length b.lastIndex == length - 1 c.lastIndex == length + 1 d.lastIndex == length + 2

B

What is the value of x? int y = 9; int z = 3; double x; x = (y / (z + 1.0)); a.2 b.2.25 c.3 d.Error: The operands are different types and cannot be divided

B

What line of code assigns a char variable outputGames with the value the gamesPointer points to? char userGames = 'B'; char* gamesPointer; a.outputGames = gamesPointer; b.outputGames = *gamesPointer; c.someChar = &gamesPointer; d.gamesPointer = outputGames;

B

Which XXX causes the program to output the message "Hello!"? void PrintMessage() { printf("Hello!"); } int main(void) { XXX; return 0; } a.printf("%s", PrintMessage())b.PrintMessage()c.void PrintMessage()d.PrintMessage("Hello!")

B

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

B

Which assigns the array's last element with 99?int myVector[15]; a.myVector[0] = 99; b.myVector[14] = 99; c.myVector[15] = 99; d.myVector[16] = 99;

B

Which expression doubles x? a.x += 2; b.x *= 2; c.x *= x; d.x *= x * 2;

B

Which is true regarding passing C strings to functions? a.A C string cannot be passed to a function b.A C string is automatically passed by pointer c.Functions that modify a string must have a char return type d.Passing a C string to a function creates a copy of that string within the function

B

Which is true regarding this preprocessor directive? #include <stdfile.h> a.The preprocessor looks for stdfile in the same directory as the including file b.The preprocessor looks for stdfile in the system's standard library c.The preprocessor looks for stdfile on the web d.The directive causes an error because of a missing .h at the end of stdfile

B

Which prints a percent sign? a.printf("\%"); b.printf("%%"); c.printf("%"); d.printf('%');

B

Which statement causes overflow? int x = 3000; int y = 1000; int z; a. z = x * y; b .z = x * y * y; c. z = (x * x) + (y * y); d. z = (x * y) + (x * y) + (x * y);

B

Which statement is incrementing the integer x, where y is also an integer? a.x = x - 1; b.x = x + 1; c.y = x + 1; d.y = x - 1;

B

Which statement outputs "Success!" to the system's standard output file using a file pointer? a.fprintf("%s \n", "Success!") b.fprintf(stdout, "Success!"); c.printf("%s \n","Success!") d.printf("Success!")

B

Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true? Question options: Using two arrays saves memory versus using one array. Both arrays should be of the same data type. Both arrays should be declared to have the same number of elements. The item names should appear in both arrays.

Both arrays should be declared to have the same number of elements.

Which expression is most appropriate for randomly choosing a day of the week? a.rand() % 1; b.rand() % 6; c.rand() % 7; d.rand() % 8;

C

A function defined beginning with void SetNegativesToZeros(int userValues[], ... should modify userValues such that any negative integers are replaced by zeros. The function _____. a.should make a local copy of the array and then set the copy's negative values to zeros b.cannot be written because an array passed to a function is constant so cannot be modified c.can modify the array's elements directly because arrays are passed by pointer d.should define userValues as const int& userValues to be able to modify the array's elements

C

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;

C

A programmer compares x == y, where x and y are doubles. Many different values are expected for x and y. For values that a programmer expects to be equal, the comparison will _____ . a.always evaluate to true b.always evaluate to false c.sometimes evaluate to true, sometimes to false, depending on the values d.sometimes immediately exit the program, for values that are slightly different

C

A sequence of instructions that solves a problem is called a(n) _____ . a.instruction b.process c.algorithm d.variable

C

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

C

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

C

Which data type can be used instead of int to avoid overflow for an integer containing the value 3,000,000,000,000? a.double b.long c.long long d.long int

C

Given a function defined beginning with: void PrintMaxItem(int valsArray[], ... that prints the largest item in any array of integers. How would this function most likely iterate through the array? a.for (i = 0; i < valsArray.size(); ++i) where size is a built-in function for arrays b.for (i = 0; i < valsArray; ++i) due to the compiler knowing the size of arrays c.for (i = 0; i < arraySize; ++i) where arraySize is a second function parameter d.for (i = 0; i != lastItem; ++i) where lastItem is the value of the array's last element

C

Given char x and char z, which assigns x with the character value held in z? a.x = 'z'; b.x = "z"; c.x = z; d.'x' = 'z';

C

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)

C

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

C

Given two arrays, 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. char studentNames[NUM_STUDENTS]; int studentScores[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) { if (XXX > 80) { printf("%s \n", YYY ); } } a.studentNames[i] / studentNames[i] b.studentNames[i] / studentScores[i] c.studentScores[i] / studentNames[i] d.studentScores[i] / studentScores[i]

C

Given two integer arrays 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.printf("%d \n", origList + offsetList); b.printf("%d \n", origList[2] + offsetList[2] ); c.printf("%d \n", origList[1] + offsetList[1]); d.printf("%d \n", origList[1] + offsetList[2]);

C

How many function arguments exist in the code? double FahrenheitToCelsius(double fahrenheit){ return (fahrenheit - 32.0) * 5.0 / 9.0; } int main(void) { double fahrenheit; scanf("%lf", &fahrenheit); int c1; int c2; int c3; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(fahrenheit + 5.0); return 0; } a.1 b.2 c.3 d.4

C

In an instruction like: z = x + y, the symbols x, y, and z are examples of _____. a.output b.visibles c.variables d.instructions

C

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;

C

What is output if the value of modString is "Great. They won. " void MyFct(char modString[]) { int i; // Loop index for (i = 0; i < strlen(modString); ++i) { if (modString[i] == ' ') { modString[i] = '-'; } } } a.Great-They-won- b.Great.-They won. c.Great.-They-won.- d.Great.-They-won.

C

What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) { if (pointVar1 == NULL && pointVar2 == NULL) { printf("Pointer is null\n");} else if (*pointVar2 > *pointVar1) { printf("%p\n", *pointVar2);} else if (*pointVar1 > *pointVar2) { printf("%p\n", *pointVar1); } } int main() { int num1 = 5; int num2 = 9; CheckValue(&num1, &num2); return 0; } a.0 b.5 c.9 d.Pointer is null

C

What is output? char level[] = "Minimum"; int amount = 13; printf("You have a %-.3s. of %d miles left to go \n", level, amount); return 0; a."You have a Minimum. of 13 miles left to go" b."You have a Min of 13 miles left to go" c."You have a Min. of 13 miles left to go" d.Error: The string sub-specifier is not correct

C

What is read into string myString for input "One-hit wonder"? scanf("%s", myString); a.One b.One- c.One-hit d.One-hit wonder

C

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

C

What is the ending value of numItems if myChar = 'X'? switch (myChar) { case 'W': numItems = 1; case 'X': numItems = 2; case 'Y': numItems = 3; case 'Z': numItems = 4;} a.2 b.3 c.4 d.9

C

What is the ending value of x? int y = 6; x = (1 / 2) * y + 8; a.7 b.8 c.11 d.14

C

What is the ending value of z? x = 0; y = 3; z = pow(x + 2, y); a.0 b.4 c.8 d.Error: Cannot have an expression within a function call

C

What is the output? int Calc(int num1, int num2) { return 1 + num1 + num2; } int main(void) { int x;x = Calc(4, 5); printf("%d", Calc(x, 5)); return 0; } a.5 b.10 c.16 d.Error: Cannot have a function call in a printf statement

C

What is the purpose of a variable? a.To assign values b.To perform calculations c.To hold a value d.To hold a constant value

C

Which is the first thing the compiler does when a function is called? a.Converts the function's code to assembly b.Creates instructions to jump to the function c.Stores the address of the function call d.Creates a jump instruction to the function

C

Which is true about arrays and functions? a.Arrays cannot be passed to functions b.Passing an array to a function creates a copy of that array within the function c.An array is automatically passed to a function as a pointer d.A programmer must first make a copy of an array to pass the array to a function

C

Which statement XXX outputs each element of array customerName to a file called CustomerList.txt using a file pointer? char* customerName[5] = {"Bob", "Sally", "Jim", "Joe", "Denise"}; FILE *inputFile = NULL; int numberPlayers;inputFile = fopen ("CustomerList.txt", "w"); for (int i = 0; i < (5); ++i) { XXX } a.fprintf("CustomerList.txt", "%s\n", customerName[i]); b.fprintf(inputFile, "%s\n", customerName); c.fprintf (inputFile, "%s\n", customerName[i]); d.fprintf(stdout, "%s\n", customerName[i]);

C

Which statement correctly assigns 12 into the fifth row and third column of array itemArray? a.numVals[5][3] = 12; b.numVals[3][5] = 12; c.numVals[4][2] = 12; d.numVals[2][4] = 12;

C

Which statement correctly declares a char array named myText initialized to Hello? a.char myText = {"Hello"}; b.char[10] myText= "Hello"; c.char myText[10] = "Hello"; d.myText[] = {"Hello"};

C

Which statement declares a two-dimensional integer array called myArray with 3 rows and 4 columns? a.int myArray[3, 4]; b.int myArray[7]; c.int myArray[3][4]; d.int myArray[4][3];

C

Which statement is not true? a.A char* can be passed as const* argument. b.Strings passed as char* arguments can be modified by the function. c.Strings passed as const char* can be modified by the function. d.Each string library function operates on one or more strings.

C

Which variable naming convention is used for distanceFromSun? a.snake case b.hill valley case c.lower camel case d.varied capitalization case

C

myString is declared as a string and is the only variable declared. Which is a valid assignment? a.myString[] = 'Hello'; b.myString = ["Hey"]; c.myString[] = "H"; d.myString = [Hoy];

C

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

Which assignments would yield a non-floating-point number for y? y = 32.0 + (x / (z + 1.0)); a.x = 0.0; z = 1.0; b.x = -32.0; z = 1.0; c.x = 0.0; z = 0.0; d.x = 1.0; z = -1.0;

D

A character variable's value is stored in memory as _____ . a.a graphical symbol b.a string c.a floating-point value d.an integer value

D

A pointer is a(n) _____ that contains a _____. a.constant, memory address b.array, constant value c.struct, constant value d.variable, memory address

D

Dice have 6 sides, with values 1, 2, 3, 4, 5, and 6. Which expression randomly rolls one dice, directly yielding one of those values? a. (rand() % 5) b. (rand() % 5) + 1 c. (rand() % 6) d. (rand() % 6) + 1

D

For the given program, which XXX iterates through the array to find the state that is input (userState) until a match is found? string stateNames[NUM_STATES]; int statePop[NUM_STATES]; string userState; bool foundState = false; unsigned int i; scanf("%s",userState); foundState = false; for (i = 0; XXX; ++i) { if (stateNames[i] == userState) { foundState = true; printf("%s, %d \n", userState, statePop[i]); } } a.(i < NUM_STATES - 1) b.(i < NUM_STATES) c.(i < NUM_STATES - 1) && (!foundState) d.(i < NUM_STATES) && (!foundState)

D

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

D

Given an integer array of size NUM_ELEMENTS, which XXX, YYY, and ZZZ will count the number of times the value 4 is in the array? Choices are in the form XXX / YYY / ZZZ.int myArr[NUM_ELEMENTS]; int cntFours; XXX for (i = 0; YYY; ++i) { if (myVals[i] == 4) {ZZZ; } } a.cntFours = myArr[0]; / i > NUM_ELEMENTS; / cntFours = myArr[i]; b.cntFours = myArr[1]; / i < NUM_ELEMENTS; / cntFours = myArr[i] + 1; c.cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1; d.cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

D

Given str = "Cat", what is the result of this statement? str[1] = "ab"; a.str is "abt" b.str is "Catab" c.str is "Cab" d.Error: Assigning a character with a string is not allowed

D

Given that integer array x has elements 5, 10, 15, 20, what is the output? int i; for (i = 0; i < 4; ++i) { printf("%d ", x[i] + x[i + 1]); } a.10, 15, 20, 5 b.15, 25, 35, 20 c.15, 25, 35, 25 d.Error: Invalid access

D

Given two integer arrays prevValues and newValues. Which code copies the array prevValues into newValues? The size of both arrays is NUM_ELEMENTS. a.newValues = prevValues; b.newValues[] = prevValues[]; c.newValues[NUM_ELEMENTS] = prevValues[NUM_ELEMENTS]; d.for (i = 0; i < NUM_ELEMENTS; ++i) { newVals[i] = prevVals[i]; }

D

Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes? for (i = 0; i < 4; ++i) { largerArray[i] = smallerArray[i]; } a.All the elements of largerArray will get copied to smallerArray. b.Some of the elements of largerArray will get copied to smallerArray. c.All of the elements of smallerArray will get copied to largerArray. d.Error: The two arrays are not the same size.

D

How many elements are in the array? int userVals[2][4]; a.2 b.4 c.6 d.8

D

How many elements does the array declaration create? int scores[10]; // Array declaration scores[0] = 25; scores[1] = 22; scores[2] = 18; scores[3] = 28; a.0 b.4 c.9 d.10

D

The following program generates an error. Why? const int NUM_ELEMENTS = 5; int userVals[NUM_ELEMENTS]; unsigned int i; userVals[0] = 1; userVals[1] = 7; userVals[2] = 4; for (i = 0; i <= NUM_ELEMENTS; ++i) { cout << userVals[i] << endl; } a.Variable i is declared as an unsigned integer. b.The array userVals has 5 elements, but only 3 have values assigned. c.The integer NUM_ELEMENTS is declared as a constant. d.The for loop tries to access an index that is out of the array's valid range.

D

What is output, if the input is 3 2 1 0? scanf("%d", &x); while (x > 0) { printf("%d ", 2 * x); } a.6 b.6 4 2 c.6 4 2 0 d.6 6 6 6 6 ... (infinite loop)

D

What is output? #include <stdio.h> int main() { int myInt; int* myRestaurant; int myVar; int* myBill = NULL; myInt = 10; myRestaurant = &myInt; myVar = *myBill; myVar = *myRestaurant + 10.5; printf("%f\n", myVar); return 0; } a.10.5 b.20.5 c.Error: Syntax error d.Runtime errors

D

What is output? printf("Calculation: %+09.4lf \n", -13.785742835); a.Calculation: -13.7857 b.Calculation: 1.3780e+01 c.Calculation: +13.7857 d.Calculation: -013.7857

D

What is the ending value of y? pow(u, v) returns u raised to the power of v. x = 2.0; y = 3.0; y = pow(pow(x, y)) + 1.0; a.8.0 b.9.0 c.65.0 d.Error: The compiler complains about calling a function within another function

D

What is the output? double CheckForFever (double temperature) { const double NORMAL_TEMP = 98.6; const double CUTOFF_TEMP = 95; double degreesOfFever; if (temperature > NORMAL_TEMP) { degreesOfFever = temperature - NORMAL_TEMP; printf("You have %lf degrees of fever.", degreesOfFever); else if (temperature < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temperature; printf("Your temperature is %lf below 95.", degreesOfFever); return degreesOfFever; int main(void) { double bodyTemperature; double degreesOfFever; bodyTemperature = 96.0; printf("Checking for fever..."); degreesOfFever = CheckForFever(bodyTemperature); return 0; } a.(Nothing is output) b.Checking for fever...Your temperature is 2.6 below 95. c.Checking for fever...Your temperature is 2.6 below 95. d.Checking for fever...

D

What is the output?void WaterTemperatureForCoffee(int temp) { if (temp < 195) { printf("Too cold."); } else if ((temp >= 195) && (temp <= 205)) { printf("Perfect temperature."); } else if (temp > 205) { printf("Too hot."); } } int main(void) { WaterTemperatureForCoffee(205); WaterTemperatureForCoffee(190); return 0; } a.Too cold. b.Perfect temperature. c.Perfect temperature.Too cold. d.Perfect temperature.Too cold.

D

What is the purpose of style guidelines? a.To simplify compiling code from different programmers b.To enforce use of spaces over tabs for indentation c.To minimize syntax errors d.To improve consistency and readability

D

What is the purpose of the & symbol in the following code? int* myVar; int distance = 132; myVar = &distance; a.Refers to the function parameter distance b.Refers to the constant distance c.Refers to the integer value of distance d.Refers to the memory address of distance

D

What is y after executing the statements? x = 5; y = x + 1; y = y * 2; a.5 b.6 c.8 d.12

D

Which best describes the meaning of a 1 (true) being output? Assume v is a large array of ints. int i; bool s; for (i = 0; i < N_SIZE; ++i) { if (v[i] < 0) { s = true; } else { s = false; } } printf("%d", s); a.first value is negative b.all values are negative c.some value other than the last is negative d.last value is negative

D

Which changes the value of m, where m = x * y + z / -8 % 9 + w? a.m = x * y + ((z / -8) % 9) + w b.m = x * y + (z / -8 % 9) + w c.m = ((x * y) + (z / -8) % 9) + w d.m = (x * y) + z / (-8 % 9 + w)

D

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;

D

Which declares two related integer arrays named personName and personAge each with 50 elements? a.int personName, personAge; b.int personName, personAge = 50; c.int personName = 50;int personAge = 50; d.int personName[50];int personAge[50];

D

Which evaluates to true for the string str = "beta123"? a.isalpha(str[4]) b.isdigit(str[0]) c.isspace(str[2]) d.islower(str[1])

D

Which expression for XXX causes the code to output the strings in alphabetical order? (Assume the strings are lowercase) if (XXX) { printf("%s %s\n",firstString, secondString); } else { printf("%s %s\n",secondString, firstString); } a.strcmp(str1, str2) != 0 b.strcmp(str1, str2) == 0 c.strcmp(firstString, secondString) > 0 d.strcmp(firstString, secondString) < 0

D

Which is an example of a process? a. int b.y, 10 c 15 d. x + y

D

Why might style guidelines limit the number of characters per line? a.To speed up the code's execution b.To limit the size of the executable file c.To force use of short variable names d.To make the code more readable

D

int x is 1000000 and int y is 2000000. Outputting x * y will result in overflow. What is likely to appear at the output? a.The error message "overflow" b.The integer value -1 c.A floating-point value d.A seemingly arbitrary integer

D

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;

D. cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

Given that integer array x has elements 5, 10, 15, 20, what is the output? int i; for (i = 0; i < 4; ++i) { System.out.print(x[i] + x[i + 1]); } Question options: 10, 15, 20, 5 15, 25, 35, 25 15, 25, 35, 20 Error: Invalid access

Error: Invalid access

Given two integer arrays, largerArray with 4 elements, and smallerArray with 3 elements. What is the result after this code executes? for (i = 0; i < 4; ++i) { largerArray[i] = smallerArray[i]; } Question options: All the elements of largerArray will get copied to smallerArray. Some of the elements of largerArray will get copied to smallerArray. All of the elements of smallerArray will get copied to largerArray. Error: The two arrays are not the same size.

Error: The two arrays are not the same size.

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

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

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

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

For an enumerated type like below, the compiler assigns what kind of value to RED, GREEN, and BLACK. enum CarColor {RED, GREEN, BLACK};

Integer

Which XXX / YYY declare a vector having MAX_SIZE elements and initializes all elements with -1? const int MAX_SIZE = 4;vecotr<int> myNumbers(XXX);int i;for (i = 0; i < YYY; ++i) {myNumbers.at(i) = -1;} MAX_SIZE / MAX_SIZE MAX_SIZE / MAX_SIZE - 1 MAX_SIZE - 1 / MAX_SIZE MAX_SIZE - 1 / MAX_SIZE - 1

MAX_SIZE / MAX_SIZE

Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1? final int MAX_SIZE = 4; int[] myNumbers = new int[XXX]; int i; for (i = 0; i < YYY; ++i) { myNumbers[i] = -1; } Question options: MAX_SIZE / MAX_SIZE MAX_SIZE / MAX_SIZE - 1 MAX_SIZE - 1 / MAX_SIZE MAX_SIZE - 1 / MAX_SIZE - 1

MAX_SIZE / MAX_SIZE

Which input for char c causes "Done" to be output next? c = 'y'; while (c = 'y') { // Do somethingcout << "Enter y to continue, n to quit: "; cin >> c; } cout << "Done";

No such value (infinite loop)

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

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

The following program generates an error. Why?final int NUM_ELEMENTS = 5; int[] userVals = new int[NUM_ELEMENTS]; int i; userVals[0] = 1; userVals[1] = 7; userVals[2] = 4; for (i = 0; i <= userVals.length; ++i) { System.out.println(userVals[i]); } Question options: Variable i is never initialized. The array userVals has 5 elements, but only 3 have values assigned. The integer NUM_ELEMENTS is declared as a constant The for loop tries to access an index that is out of the array's valid range.

The for loop tries to access an index that is out of the array's valid range.

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 The variables y and z should be initialized to 0 The function FindPrevNext() should have a return statement for variables prev and next prev and next should be initialized in FindPrevNext()

The variables prev and next should be passed by reference

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

a

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

a

According to the following expression, what is z if x is 32 and y is 25? z = (x <= y) ? y : x + y; a. 25 b. 57 c. 32 d. 7

b

A restaurant serves breakfast before 11 am, after which they serve lunch. Which expression for XXX outputs the correct string for any time? Variable time ranges from 0 to 23 (e.g., 13 means 1 pm). mealString = XXX; // Output mealString a. (time > 11) ? "Breakfast" : "Lunch" b. (time == 11) ? "Breakfast" : "Lunch" c. (time < 11) ? "Breakfast" : "Lunch" d. (time != 11) ? "Breakfast" : "Lunch"

c

Which character array declaration is appropriate? char name[5] = "Alexandria"; char name[5] = "Alexa"; char name[5] = "Alexander"; char name[5] = "Alex";

char name[5] = "Alex";

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;XXXfor (i = 0; YYY; ++i) {if (myVals.at(i) == 4) {ZZZ;}} cntFours = myVect.at(0); / i > myVect.size(); / cntFours = myVect.at(i); cntFours = myVect.at(1); / i < myVect.size(); / cntFours = myVect.at(i) + 1; cntFours = 1; / i > NUM_ELEMENTS; / cntFours = cntFours + 1; cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

cntFours = 0; / i < NUM_ELEMENTS; / ++cntFours;

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 + offsetList << endl; cout << origList.at(2) + offsetList.at(2) << endl; cout << origList.at(1) + offsetList.at(1) << endl; cout << origList.at(2) + offsetList.at(2) << endl;

cout << origList.at(1) + offsetList.at(1) << endl;

An exam with 10 questions requires all 10 answers to be correct in order to pass. Which expression represents this condition? a. (numCorrect != 10) ? "Pass" : "Fail" b. (numCorrect = 10) ? "Pass" : "Fail" c. (numCorrect >= 9) ? "Pass" : "Fail" d. (numCorrect == 10) ? "Pass" : "Fail"

d

For what values of integer x will Branch 3 execute? If x < 10 : Branch 1 Else If x > 9: Branch 2 Else: Branch 3 a.Value 10 or larger b.Value 10 only c.Values between 9 and 10 d.For no values (never executes)

d

Which declaration assigns a variable with 5 such that the value can not be later changed? a. const int = 5; b. int NUM_ITEMS = 5; c. int numItems = 5; d. const int NUM_ITEMS = 5;

d. const int NUM_ITEMS = 5;

What is the output? int columns; int rows; for (rows = 0; rows < 2; ++rows) { for (columns = 0; columns < 3; ++columns) { printf("x"); } printf(" "); } a.x x b.xx xx c.xx xx xx d.xxx xxx

d. xxx xxx

Which for loop will iterate 100 times? for (i = 0; i < 99; i++) for (i = 1; i < 99; i++) for (i = 0; i < 100; i++) for (i = 1; i < 100; i++)

for (i = 0; i < 100; i++)

Given two integer arrays prevValues and newValues. Which code copies the array prevValues into newValues? The size of both arrays is NUM_ELEMENTS. Question options: newValues = prevValues; newValues[] = prevValues[]; newValues[NUM_ELEMENTS] = prevValues[NUM_ELEMENTS]; for (i = 0; i < NUM_ELEMENTS; ++i) { newValues[i] = prevValues[i];}

for (i = 0; i < NUM_ELEMENTS; ++i) { newValues[i] = prevValues[i];}

Which regular loop corresponds to this enhanced for loop? char[] vowels = {'a', 'e', 'i', 'o', 'u'}; for (char item: vowels) { System.out.println(item); } Question options: for (int i = 0; i < item; ++i) { System.out.println(vowels[i]);} for (int i = 0; i < item.length; ++i) { System.out.println(vowels[i]);} for (int i = 0; i < vowels.length; ++i) { System.out.println(vowels[i]);} for (int i = 0; i < vowels.length; ++i) { System.out.println(item[i]);}

for (int i = 0; i < vowels.length; ++i) { System.out.println(vowels[i]);}

Which XXX causes every character in string inputWord to be output? for (XXX) {cout << inputWord.at(i) << endl; } i = 0; i < (inputWord.size() - 1); ++i i = 0; i < inputWord.size(); ++i i = 0; i < (inputWord.size() + 1); ++i i = 0; i <= inputWord.size(); ++i

i = 0; i < inputWord.size(); ++i

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 i = 0; i < n / i + 1 i = 1; i < n / i i = 1; i < n / i + 1

i = 0; i < n / i + 1

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(); i < 0; --i i = str.length(); i > 0; --i) i = str.length() - 1; i >= 0; --i) i = str.length() + 1; i > 0; --i)

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 if branch executes when an account lacks funds and has not been used recently? hasFunds and recentlyUsed are booleans and have their intuitive meanings.

if (!hasFunds && !recentlyUsed)

Which is a valid definition for a function that passes two integers (a, b) as arguments, and returns an integer? myFunction(int a, int b) int myFunction(a, b) void myFunction (a, b) int myFunction(int a, int b)

int myFunction(int a, int b)

Which XXX and YYY correctly complete the code to find the maximum score? Choices are in the form XXX / YYY. int[] scores = {43, 24, 58, 92, 60, 72}; int maxScore; maxScore = scores[0]; for (XXX) { if (num > maxScore) { YYY; } } Question options: int scores: num / maxScore = num scores != 0 / num = maxScore int num: scores / maxScore = num num < scores / num = maxScore

int num: scores / maxScore = num

Which is the simplest expression that is true only when myChar is among a-z or A-Z? isalpha(myChar) isalpha(tolower(myChar)) isalpha(tolower(myChar)) || isalpha(toupper(myChar)) isalpha(myChar) && !isspace(myChar)

isalpha(myChar)

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 25); maxValue = Max(); maxValue = Max(15, Max(35, 25)); Max = maxValue(15, 25);

maxValue = Max(15, Max(35, 25));

Which best describes what is output? Assume v is a large array of ints. int i; int s; s = v[0]; for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; } } System.out.println(s); Question options: first value in v max value in v min value in v last value in v

min 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; first value in v max value in v min value in v last value in v

min value in v

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) valueint minVal;XXX for (i = 0; i < userVals.size(); ++i) {if (YYY) {minVal = userVals.at(i);}}cout << "Min: " << minVal << endl; minVal = 0; / userVal > minVal minVal = 0; / userVal < minVal minVal = userVals.at(0); / userVals.at(i) > minVal minVal = userVals.at(0); / userVals.at(i) < minVal

minVal = userVals.at(0); / userVals.at(i) < minVal

Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are 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 < 100; ++i) { if (YYY) { minVal = userVals[i]; } } System.out.println("Min: " + minVal); Question options: minVal = 0; / userVal > minVal minVal = 0; / userVal < minVal minVal = userVals[0]; / userVals[i] > minVal minVal = userVals[0]; / userVals[i] < minVal

minVal = userVals[0]; / userVals[i] < minVal

Which assigns the vector's first element with 99? vector<int> myVector(4);

myVector.at(0) = 99;

Which assigns the vector's first element with 99? vector<int> myVector(4); myVector.at() = 99; myVector.at(-1) = 99; myVector.at(0) = 99; myVector.at(1) = 99;

myVector.at(0) = 99;

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 p = 4, q = 3 p = 3, q = 4 Error: Argument names must match parameter names

p = 3, q = 3

Which expression is most appropriate for randomly choosing a day of the week?

rand() % 7;

Given array scorePerQuiz has 10 elements. Which assigns element 7 with the value 8? Question options: scorePerQuiz = 8; scorePerQuiz[0] = 8; scorePerQuiz[7] = 8; scorePerQuiz[8] = 7;

scorePerQuiz[7] = 8;

An identifier can _____ . contain a period contain spaces start with an underscore be a reserved word

start with an underscore

Which statement appends an exclamation point at the end of myStr? char myStr[10] = "Yay";

strcat(myStr, "!");

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 << " ";}} studentNames.at(i) / studentNames.at(i) studentNames.at(i) / studentScores.at(i) studentScores.at(i) / studentNames.at(i) studentScores.at(i) / studentScores.at(i)

studentScores.at(i) / studentNames.at(i)

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} 0 1 2 3

1

What is the output, if n is 3? for (int i = 1; i <= n; ++i) { int factorial = 1; factorial = factorial * i; cout << factorial << " "; }

1 2 3

How many elements does the array declaration create? int[] scores = new int[10]; scores[0] = 25; scores[1] = 22; scores[2] = 18; scores[3] = 28; Question options: 0 4 9 10

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 elements does the vector declaration create? vector<int> scores(10); // Vector declarationscores.at(0) = 25;scores.at(1) = 22;scores.at(2) = 18;scores.at(3) = 28; 0 4 9 10

10

What is the output? int num = 10; while (num <= 15) { cout << num << " "; if (num == 12) { break; } ++num; } cout << "Done";

10 11 12 Done

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, if the input is 3 2 4 5? All variables are ints. cin >> num;for (i = 0; i < num; ++i) {cin >> curr;cout << curr;} 24 245 324 3245

245

What possible values can x % 10 evaluate to? (x is an integer). a.0..9 b.1..10 c.0..10 d.1..11

A

Which XXX / YYY declare an array having MAX_SIZE elements and initializes all elements with -1? const int MAX_SIZE = 4; int myNumbers[XXX]; int i; for (i = 0; i < YYY; ++i) { myNumbers[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

A

Which XXX and YYY correctly output the smallest values? Array userVals contains 100 elements that are 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 < 100; ++i) { if (YYY) { minVal = userVals[i]; } } printf("Min: %d" ,minVal); a.minVal = userVals[0]; / userVals[i] < minValb.minVal = 0; / userVal > minValc.minVal = 0; / userVal < minVald.minVal = userVals[0]; / userVals[i] > minVal

A

Which XXX is used to read and store the data into the variable numberPlayers from the file that is opened by the stream inputFile? int main(void) { FILE* inputFile = NULL; int numberPlayers; inputFile = fopen("playerNumber.txt", "r"); if (inputFile==NULL) { printf("Could not open file numFile.txt."); return 1; } else { XXX; printf("Players Number: " , numberPlayers); } return 0; } a.fscanf(inputFile, "%d", &numberPlayers); b.scanf(inputFile, "%d", &numberPlayers); c.sscanf(inputFile, "%d", &numberPlayers); d.scanf("%d", &numberPlayers);

A

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(void) { int x = 10; int y; int z; FindPrevNext (x, y, z); printf("Previous = %d, Next = %d", y, 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()

A

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

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

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

For an integer constant x, which statement will yield a compiler error? a.w = x + 1; b.x = y + 1; c.y = x; d.z = x + x;

B

The programmer expected myString to contain the phrase "Girls and Boys" but instead only holds "Girls". Why? User input: Girls and Boys char myString[12]; scanf("%s", myString); a.myString must be preceded by an ampersand (&) b.scanf stops reading a string at the first whitespace c.The variable myString was improperly declared d.The "%s" parameter should be "%ws"

B

What does the following code do? char inputString[30] = "Ther3 are n0 num33r5 4er3"; int length = strlen(inputString); char numString[30]; int numIndex = 0; char alphaString[30]; int alphaIndex = 0; for (int i = 0; i < length; ++i){ if(isalpha(inputString[i])){ alphaString[alphaIndex]=inputString[i]; alphaIndex +=1; } else{ if(isdigit(inputString[i])){ numString[numIndex]=inputString[i]; numIndex+=1; } a.Removes spaces from inputString by moving chars to another char array b.Sorts alphabetic and numeric chars in inputString into two separate arrays c.Removes all numeric characters from inputString d.Sorts chars in inputString in alphabetical order

B

What is the ending value of w? int w; int y; y = 34; w = y % 5; a.1 b.4 c.6 d.7

B

Which XXX would generate "the USA has 50 states" as the output for "the usa has 50 states" as the input? #include <stdio.h> #include <string.h> int main(void) { char userInput[100]; char* stringPosition = NULL; printf("Enter a line of text: "); fgets(userInput, 100, stdin); stringPosition = strstr(userInput, "usa"); if (stringPosition != NULL) { XXX } printf("%s\n", userInput); return 0; } a.strncpy(*stringPosition, "USA", 3); b.strncpy(stringPosition, "USA", 3); c.strncpy(stringPosition, "USA"); d.strncpy(stringPosition, 'USA', 3);

B

Which best describes what is output? Assume v is a large array of ints. int i; int s; s = v[0]; for (i = 0; i < N_SIZE; ++i) { if (s > v[i]) { s = v[i]; } } printf("%d \n", s); a.first value in v b.min value in v c.last value in v d.max value in v

B

Two arrays, itemsNames and itemsPrices, are used to store a list of item names and their corresponding prices. Which is true? a.Using two arrays saves memory versus using one array. b.Both arrays should be of the same data type. c.Both arrays should be declared to have the same number of elements. d.The item names should appear in both arrays.

C

What does the following code do after populating urlArr? char urlArr[9]; int length = strlen(urlArr); // urlArr is populated here for (int i = 0; i < length; ++i){ printf("%s\n", urlArr[8]); } a.Prints the 8th character of every string in urlArr b.Prints the 8th character in urlArr c.Prints the last string in urlArr 9 times d.Prints every string in urlArr

C

What is myChar assigned with? char myChar; myChar = '\''; a.A backslash: \ b.A double-quote: " c.A single-quote: ' d.A backslash and double-quote: \"

C

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

C

Which XXX and YYY will find the minimum value of all the elements in the array? Choices are in the form XXX / YYY. int userVals[NUM_ROWS][NUM_COLS]; int minVal = userVals[0][0]; for (i = 0; i < NUM_ROWS; ++i) { for (j = 0; j < NUM_COLS; ++j) { if (XXX) { YYY; } } } a.userVals[i] < minVal / minVal = userVals[i] b.userVals[j] < minVal / minVal = userVals[j] c.userVals[i][j] < minVal / minVal = userVals[i][j] d.userVals[i][j] > minVal / minVal = userVals[i][j]

C

Which XXX calculates the area using the CalcSquare() function? The formula to calculate the area of a circle is pi * r 2 . double CalcSquare(double x) { return x*x; } double CalcArea(double r) { const double PI_VAL = 3.14159265;XXX; } int main(void) { printf("%lf", CalcArea(5.0)); return 0; } a.PI_VAL * r * r; b.PI_VAL * CalcSquare(r); c.return PI_VAL * CalcSquare(r); d.return PI_VAL * CalcSquare(r) * CalcSquare(r);

C

Which XXX results in the output "I feed my 3 cats"? #include <stdio.h>int main(void) {int numCats = 3;char choreStatement[] = "feed";XXX} a.printf("I %c my %d cats", &choreStatement, &numCats); b.printf("I %c my %d cats", choreStatement, numCats); c.printf("I %s my %d cats", choreStatement, numCats); d.printf("I %s my %d cats", &choreStatement, &numCats);

C

Which XXX will result in output "4.00 feet is equal to 1.22 meters"? #include <stdio.h> void ConvertFeetToMeters(float numFeet, float* numMeters) { *numMeters = numFeet / 3.28084; } int main(void) { float numFeet = 4.0; float numMeters = 0.0; XXX printf("%.2f feet is equal to %.2f meters", numFeet, numMeters); return 0; } a.ConvertFeetToMeters(*numFeet, &numMeters); b.ConvertFeetToMeters(numFeet, *numMeters); c.ConvertFeetToMeters(numFeet, &numMeters); d.ConvertFeetToMeters(&numFeet, *numMeters);

C

Which assigns the array's first element with 99?int myVector[4]; a.myVector[] = 99; b.myVector[-1] = 99; c.myVector[0] = 99; d.myVector[1] = 99;

C

Which expression is evaluated first? w = y + 2 + 3 * x + z; a.y + 2 b.2 + 3 c.3 * x d.x + z

C

Which is an invalid access for the array? int numsList[5]; int x = 3; a.numsList[x-3] b.numsList[0] c.numsList[x+2] d.numsList[(2*x) - x]

C

Which is likely not covered in style guidelines? a.Variable initiation b.Variable names c.Number of files created d.Spacing used in indentation

C

Which is not true? a.A variable declaration requires a name and memory location b.The compiler designates a new memory location for a variable the first time a value is assigned c.Variables must be declared before being assigned a value or read d.Every time a new value is assigned to a variable, the compiler designates a new memory location

C

The following program generates an error. Why? void PrintSum(int num1, int num2) { printf("%d", num1 + num2); } int main(void) { 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

D

What are the ending contents of the array? Choices show elements in index order 0, 1, 2. int yearsList[3]; yearsList[0] = 5; yearsList[1] = yearsList[0]; yearsList[0] = 10; yearsList[2] = yearsList[1]; a.5, 5, 5 b.5, 10, 10 c.10, 10, 10 d.10, 5, 5

D

What is output? #include <stdio.h> int main() { float newSize = 1.0; int i; for (i = 100; i < 120; ++i) { newSize *= i; } printf("%f", newSize); return 0; } a.1.000000 b.120.000000 c.4253829132348564723899756263864532992.000000 d.infinity

D

What line of code makes the character pointer studentPointer point to the character variable userStudent? char userStudent = 'S'; char* studentPointer; a.userStudent = *studentPointer ;b.userStudent = studentPointer; c.*studentPointer = &userStudent; d.studentPointer = &userStudent;

D

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.

D

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

D

Which XXX converts the string userStr to uppercase? for (i = 0; userStr[i] != '\0'; ++i) { XXX; } a.userStr = isupper(userStr); b.userStr = toupper(userStr); c.userStr[i] = isupper(userStr[i]); d.userStr[i] = toupper(userStr[i]);

D

Which XXX is most appropriate for printing out the char array userText? userText[10] = "zyBook"; for (i = 0; XXX; ++i) { // Print userText[i] } a.i < 6 b.i <= 6 c.userText != '\0' d.userText[i] != '\0'

D

Which XXX prints the message only if str1 and str2 are equal? if (XXX) { // Print "strings are equal" } a.str1 == str2 b.strcat(str1, str2) == 0 c.strcpy(str1, str2) == 0 d.strcmp(str1, str2) == 0

D

Which assigns the last array element with 20.int userNum[N_SIZE]; a.userNum[20]; b.userNum[] = 20; c.userNum[N_SIZE] = 20; d.userNum[N_SIZE - 1] = 20;

D

Which expression for XXX outputs "Modern era" for any year 1980 and later? if (year < 2000) { // Output "Past" } else if (XXX) { // Output "Modern era" } a.year > 1980 b.year >= 1980 c.year >= 2000 d.(No such expression exists)

D

Which generates a random integer in the range 13..19? a.rand() % 19 b.rand() % (19 - 13) c.(rand() % (19 - 13)) + 13 d.(rand() % (19 - 13 + 1)) + 13

D

Which identifier name shows good practice? a.m_v b.revPhyMgt c.cost_of_shipping_furniture_crates_by_sea d.sizeOfBox

D

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)

D

Which is correct? a.int main(void) { pkgHeight;pkgLength; pkgWidth; pkgVol = pkgHeight * pkgLength * pkgWidth; } b.int main(void) { int pkgHeight = 2; int pkgLength = 3; int pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } c.int main(void) { pkgHeight = 2; pkgLength = 3; pkgWidth = 5; pkgVol = pkgHeight * pkgLength * pkgWidth; } d.int main(void) { int pkgHeight; int pkgLength; int pkgWidth; int pkgVol;pkgVol = pkgHeight * pkgLength * pkgWidth;}

D

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.

D

Which is true for the following code? char userText[10]; userText[0] = 'B'; userText[1] = 'o'; userText[2] = 'o'; userText[3] = 'k'; userText[4] = '\0'; ...userText[3] = 't'; a.The first four characters of the array userText are Book. b.The first five characters of the array userText are Bookt. c.The compiler generates an error because element 3 can't be overwritten. d.Printing the array userText will work fine because the new string is 4 characters and the array size is 10.

D

Which is true? a.scanf() always truncates the input to avoid the string buffer from overflowing b.Character type variables do not require an ampersand (&) in scanf() c.A format specifier such as "%d" in scanf() is good practice but optional d.Format specifiers for scanf() and printf() are identical

D

Which statement appends an exclamation point at the end of myStr? char myStr[10] = "Yay"; a.strncpy(myStr, "!", 2); b.strcpy(myStr, "!"); c.strcat(myStr, '!'); d.strcat(myStr, "!");

D

Which statement defines the character search function strrchr()? a.Returns the position of the last occurrence of the character. b.Returns the position to the first occurrence of the character. c.Returns a pointer to the first occurrence of the character. d.Returns a pointer to the last occurrence of the character.

D

Which statement, executed once at the start of main(), enables a program to generate a different sequence of pseudo-random numbers from rand() each time the program is run? a.srand(); b.srand(100); c.time(srand()); d.srand((int)time(0));

D

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

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

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(string& userName, int& userScore); GetUserScore(string userName, int userScore); GetUserScore(userName, userScore); GetUserScore(&userName, &userScore);

GetUserScore(userName, userScore);

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

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

Which XXX causes the program to output the message "Hello!"? void PrintMessage() {cout << "Hello!";}int main() {XXX;return 0;} cout << PrintMessage() PrintMessage() void PrintMessage() PrintMessage("Hello!")

PrintMessage()

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;} The void function is missing a "return;" statement. The values 4 and 5 cannot be passed directly to PrintSum() main() has a return statement that returns the value 0 PrintSum() has void return type, so cannot be assigned to a variable

PrintSum() has void return type, so cannot be assigned to a variable

Which is true for the following code? char userText[10]; userText[0] = 'B'; userText[1] = 'o'; userText[2] = 'o'; userText[3] = 'k'; userText[4] = '\0'; ...userText[3] = 't';

Printing the array userText will work fine because the new string is 4 characters and the array size is 10.

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

RAM is an abbreviation that stands for:

Random Access Memory

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

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

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

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

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

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; scanf("%d", &currVal); while (YYY) { ZZZ; scanf("%d", &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. scanf("%d", &sum) / currVal == 0 / scanf("%d", &sum)

a

Both must be true for a person to ride: (1) At least 5 years old, (2) Taller than 36 inches. Which expression evaluates to true if a person can ride? a. (age >= 5) && (height > 36) b. (age >= 5) || (height > 36) c. (age > 5) && (height <= 36) d. (age > 5) || (height <= 36)

a

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

a

Given year is positive, which expressions for XXX, YYY, and ZZZ will output the correct range? Choices are in the form XXX / YYY / ZZZ. If XXX: Output "1-100" Else If YYY: Output "101-200" Else If ZZZ: Output "201-300" Else: Output "Other" a. year < 101 / year < 201 / year < 301 b. year > 0 / year > 99 / year > 199 c. year > 0 / year > 100 / year > 200 d. year < 100 / year < 200 / year < 300

a

How is the expression evaluated? ! x - 3 > 0 a. ((!x) - 3) > 0 b. (!(x - 3) > 0 c. (!x) - (3 > 0) d. !((x - 3) > 0)

a

In the following code, which conditions will lead to the booleans continue and needFill to both be true? halfFull = (currentTank > fullTank * .5); full = (currentTank == fullTank); empty = (currentTank == 0); almostEmpty = (currentTank < fullTank * .25) if (full || halfFull) { continue= true; needFill = false; } else if (almostEmpty && !Empty ) { continue = true; needFill = true; } else { continue = false; needfill = true; } a. almostEmpty == true && empty == false b. full == true || halfFull == true c. almostEmpty == true || empty == false d. almostEmpty == true && halfFull == true

a

What does this code do? If x less than y Put x to output Else Put y to output a. Outputs the lesser of the two integers; if they are equal, outputs that integer b. Outputs the lesser of the two integers; if they are equal, outputs nothing c. Outputs the greater of the two integers; if they are equal, outputs that integer d. Outputs the greater of the two integers; if they are equal, outputs nothing

a

Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY. scanf("%d", &w); while (XXX) { // Do something YYY; } a. w < 100 / scanf("%d", &w) b. w >= 100 / (nothing) c. w < 100 / (nothing) d. w >= 100 / scanf("%d", &w)

a

Which expression follows the practice of using parentheses to make the intended order of evaluation explicit? x > y && !a == b a. (x > y) && (!a == b) b. (x > (y)) && ((!a == b)) c. ((x > y) && !a == (b)) d. ((x > y)) && ((!a == b))

a

Which expression for YYY outputs "Quarter century!" when the input is 25? int x; scanf("%d", &x); if (YYY) { printf("Nothing special"); } else { printf("Quarter century!"); } a.x != 25 b.x == 25 c.x <> 25 d.x == !25

a

Which expressions for YYY and ZZZ will output "Young" for ages less than 20 and "Young but not too young" for ages between 10 and 20?int u; scanf("%d", &u); if (YYY) { printf("Young"); } if (ZZZ) { printf(" but not too young"); } 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

a

Which if branch executes when an account lacks funds and has not been used recently? hasFunds and recentlyUsed are booleans and have their intuitive meanings. a. if (!hasFunds && !recentlyUsed) b. if (!hasFunds && recentlyUsed) c. if (hasFunds && !recentlyUsed) d. if (hasFunds && recentlyUsed)

a

Which is an essential feature of a while loop having the following form? while (LoopExpression) { LoopBody } a. The LoopExpression should be affected by the LoopBody b. The LoopExpression should not be affected by the LoopBody c. The LoopBody should get user input d. The LoopBody should update at least two variables

a

Which is the simplest expression that is true only when myChar is among a-z or A-Z? a. isalpha(myChar) b. isalpha(tolower(myChar)) c. isalpha(myChar) && !isspace(myChar) d. isalpha(tolower(myChar)) || isalpha(toupper(myChar))

a

Which is true about incremental program development? a.All programmers, regardless of experience, benefit from incremental development b.Bugs are more likely to go unnoticed as more code is added c.Programmers don't have to compile code as often when developing incrementally d.The only benefit of incremental development is readable code

a

Which value of x results in short circuit evaluation, causing y < 4 to not be evaluated? (x >= 7) && (y < 4) a. 6 b. 7 c. 8 d. No such value

a

Which value of z will cause boolean x to short circuit to false even if y == 10? x = (z < 21) && (y == 10) a. z = 22 b. z = 12 c. z = 20 d. z = -5

a

Why should programmers avoid making the following comparison with double x? x == 0.3 a. Because 0.3 may not be exactly represented as 0.3 b. Because doubles should not be compared with integers c. Because variables should not be compared with literals d.Because the 0.3 should come first: 0.3 == x

a

A sequence of instructions that solves a problem is called a(n) _____ .

algorithm

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. scanf("%d", &n); for (XXX; i++) { printf("%d", 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;

b

A programmer must write a 500 line program. Which is most likely the best approach? a. Write 1 line, run and debug, write 1 more line, run and debug, repeat b. Write 10-20 lines, run and debug, write 10-20 more lines, run and debug, repeat c. Write 250 lines, run and debug, write 250 lines, run and debug d. Write 500 lines, run and debug

b

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)

b

For the given pseudocode, which XXX and YYY will output the number of times that 10 is input (stopping when 0 is input)? Choices are in the form XXX / YYY. count = 0 val = Get next input While val is not 0 If val == 10 XXX Else YYY val = Get next input Put count to output a. count = count + 1 / count = 0 b. count = count + 1 / (nothing) c. count = count + val / (nothing) d. count = count + val / count = 0

b

For the string "on time", what character is at index 3? a. (Space) b. t c. i d. m

b

Given userStr = "Doghouse", what is the ending value of char x? x = tolower(userStr[2]); a. G b. g c. (Space) d. Error: Compiler complains about converting an already-lowercase letter

b

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

b

How many times will the loop iterate, if the input is 105 107 99 103?scanf("%d", &x); while (x > 100) { // Do something scanf("%d", &x); } a. 1 b. 2 c. 3 d. 4

b

How many x's will be output? Assume row and col are integers. for (row = 0; row < 2; ++row) { printf("x"); for (col = 0; col < 3; ++col) { // Do something } } a. 1 b. 2 c. 3 d. 6

b

If the input is 5, what is the output? int x; int z=0; scanf("%d", &x); if(x > 9) { z = 3; } z = z + 1; printf("%d",z); a. 0 b. 1 c. 3 d. 4

b

If the input is 7, what is the output? If x less than 10 Put "Tiny " to output Else Put "Not tiny " to output If x less than 100 Put "Small " to output a. Tiny b. Tiny Small c. Not tiny Small d. (No output)

b

If the input sets int x with 5 and int y with 7, what is the ending value of z? z is declared as a boolean. z = (x > y); a. True b. False c. Error: No value assigned to z due to a runtime error d. Error: No value assigned to z due to a syntax error

b

The difference threshold indicating that floating-point numbers are equal is often called what? a. Double b. Epsilon c. Difference d. Threshold

b

The program should determine the largest integer seen. What should XXX be, if the input values are any integers (negative and non-negative)? All variables are integers and have unknown initial values. for (i = 0; i < 10; ++i) { scanf("%d", &currValue); if (i == 0) { // First iteration XXX; } else if (currValue > maxSoFar) { maxSoFar = currValue; } } a. maxSoFar = 0 b. maxSoFar = currValue c. currValue = 0 d. currValue = maxSoFar

b

The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be? for (XXX) { printf("%d \n", &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

b

To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue? a. key == 'q' b. !(key == 'q') c. (!key) == 'q' d. key == (!'q')

b

What is output, if the input is 3 2 4 5? All variables are integers. scanf("%d", &num); for (i = 0; i < num; ++i) { scanf("%d", &curr); printf("%d", curr); } a. 24 b. 245 c. 324 d. 3245

b

What is the ending value of len? str = "Mid-wife "; len = strlen(str); a. 7 b. 9 c. 8 d. 11

b

What is the output, if n is 3? for (int i = 1; i <= n; ++i) { int factorial = 1; factorial = factorial * i; printf("%d ", factorial); } a.1 1 2001 b.1 2 2003 c.1 2 2006 d.Error: Cannot use the loop variable i inside the for loop

b

Which XXX causes every character in string inputWord to be output?for (XXX) { printf("%c\n" &inputWord[i]); } a. i = 0; i < strlen(inputWord) - 1); ++i b. i = 0; i < strlen(inputWord); ++i c. i = 0; i < strlen(inputWord) + 1); ++i d. i = 0; i <= strlen(inputWord); ++i

b

Which XXX will output only values up to 3? i is an int. for (i = 1; i < 10; i++) { printf("%d ", i); XXX { break; } } a. if (i != 3) b. if (i == 3) c. if (i != 4) d. if (i == 4)

b

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)

b

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"? a.if (val > 0) { printf("Non-negative"); } else { printf("Negative"); } b.if (val >= 0) { printf("Non-negative"); } else { printf("Negative"); } c.if (val < 0) { printf("Non-negative"); } else { printf("Negative"); } d.if (val <= 0) { printf("Negative"); }else { printf("Non-negative"); }

b

What is the ending value of userString? (Note the question asks about userString, not about x). userString = "FaceBook"; x = tolower(userString[4]); a. Facebook b. FaceBook c. Faceook d. b

b FaceBook

For the given pseudocode, which XXX and YYY will output the sum of the input integers (stopping when -1 is input)? Choices are in the form XXX / YYY. val = Get next input XXX While val is not -1 YYY val = Get next input Put sum to output a.sum = val / sum = val b.sum = val / sum = sum + val c.sum = 0 / sum = sum + val d.sum = 0 / sum = val

c

For the string "Orange", what character is at index 3? a. r b. a c. n d. g

c

For what values of x will "Medium" be output?If x > 40: Output "Large" Else If x > 20: Output "Medium" Else If x > 10: Output "Small" a. Any x smaller than 20 b. Any x larger than 40 c. Any x from 21 to 40 d. Any x from 10 to 40

c

Given string str1 and string str2, which expression is true? str1 = "Hi"; str2 = "Hello"; a.strcmp(str1, str2) == 0 b.strcmp(str1, str2) < 0 c.strcmp(str1, str2) > 0 d.(Comparison not possible)

c

Given the following code, what value of numCorrect outputs "You answered all but one question correctly!"? int numCorrect; switch(numCorrect) { case 0: printf("You didn't answer any questions correctly.\n"); break; case 1: printf("You answered only one question correctly.\n"); break; case 2: printf("You answered only two questions correctly.\n"); break; case 3: printf("You answered all but one question correctly!\n"); break; case 4: printf("You answered all four questions correctly!\n"); break; default: printf("Please check your input. There are only four questions.\n"); break; a.1 b.2 c.3 d.4

c

If the input is 5, what is the output? int x; scanf("%d", &x); if (x < 10) { printf("Live "); } else if (x < 20) { printf("long "); } else if (x < 30) { printf( "and "); } printf("prosper!"); a. Live b. Live long c. Live prosper! d. Error: The compiler will complain about a missing else statement

c

What is output, if userVal is 5? int x; x = 100; if (userVal != 0) { int tmpVal; tmpVal = x / userVal; printf("%d", tmpVal); } a. 0 b. 5 c. 20 d. Error: The compiler generates an error

c

What is the ending value of sum, if the input is 2 5 7 3? All variables are integers. scanf("%d", &x); sum = 0; for (i = 0; i < x; ++i) { scanf("%d", &currValue); sum += currValue; } a. 5 b. 10 c. 12 d. 15

c

What is the ending value of y if x is 50? y and x are ints. y = (x < 21) ? 100 : x; a. 'x' b. 21 c. 50 d. 100

c

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

c

What is the output if count is 4? for (i = count; i > 0; --i) { // Output i } a. 4 b. 321 c. 4321 d. 43210

c

What is the output if the input is "Yes", "No", "Yes", "Maybe"? char response[10] = ""; scanf("%s", response); while (strcmp(response, "Maybe") != 0) { if (strcmp(response, "Yes") == 0) { printf("Wrong "); } else { printf("%s ", response); } scanf("%s", response); } a.Yes No Yes b.Wrong No Wrong Maybe c.Wrong No Wrong d.Yes No Yes Maybe

c

What is the output? int n; for (n = 0; n < 10; n = n + 3) { printf("%d ", 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

c

What is the output? int num = 10; while (num <= 15) {printf("%d ", num); if (num == 12) { break; } ++num; } printf("Done"); a. 10 Done b. 10 11 Done c. 10 11 12 Done d. 10 11 12 13 14 15 Done

c

What is the output? int x = 18; while (x > 0) { // Output x and a space x = x / 3; } a.6 2 b.6 2 0 c.18 6 2 d.18 6 2 0

c

What is the output? j and k are ints. for (j = 0; j < 2; ++j) { for (k = 0; k < 4; ++k) { if (k == 2) {break; } printf("%d%d ", j, k); } } a. 00 01 02 b. 00 01 02 03 c. 00 01 10 11 d. 00 01 02 10 11 12

c

What values for x cause Branch 1 to execute? If x > 100 : Branch 1 Else If x > 200: Branch 2 a. 100 to 200 b. 100 or larger c. 101 or larger d. 101 to 200

c

Which YYY outputs the string in reverse? Ex: If the input is "Oh my", the output is "ym hO". int i;string str; scanf("%s", str); for (YYY) { printf("%c", str[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

c

Which expression best determines if double variable x is 74.7? a.fabs (x - 74.7) != 0.0001 b.fabs (x - 74.7) > 0.0001 c.fabs (x - 74.7) < 0.0001 d.fabs (x - 74.7) == 0.0001

c

Which expression correctly evaluates 13 < num < 30? a.(num < 13) && (num < 30) b.(num < 13) || (num < 30) c.(num > 13) && (num < 30) d.(num > 13) || (num < 30)

c

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; scanf("%d", &score); if (XXX) { printf(YYY);} else { printf(ZZZ); } a.score > 90 / "Nice try" / "Great job" b.score < 91 / "Great job" / "Nice try" c.score < 91 / "Nice try" / "Great job" d.(Not possible for given code)

c

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) { printf("0-29"); } else if (ZZZ) { printf("30-39"); } else { printf("40+"); } a.x < 29 / x >= 29 b.x < 30 / x >= 30 c.x < 30 / x < 40 d.x > 29 / x > 40

c

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++)

c

Which value of y results in short circuit evaluation, causing z == 99 to not be evaluated? (y > 50) || (z == 99) a.40 b.50 c.60 d.No such value

c

What is the output? int i; for (i = 0; i < 4; ++i) { int factorial = i + 1; for (int j = 0; j < 2; ++j) { printf("%d", factorial * j); } } printf("%d\n", factorial); a.01020304 b.010203048 c.10203048 d.Error: factorial is out of scope

d

What is the output? int main() { for (int i = 0; i < 3; ++i) { printf("%d", i); } printf("%d", i); return 0; } a. 12 b. 122 c. 123 d. Error: The variable i is not declared in the right scope

d

What is y's ending value? int x; int y = 0; scanf("%d", &x); if (x = 20) { y = 3; } a. 0 when the input is 20, else 3 b. Always 0 no matter what the input c. 3 when the input is 20, else 0 d. Always 3 no matter what the input

d

Which conditional expression would cause myBoolean to short circuit to true given x = 10 and y = 5? a. myBoolean = (x < 5 || y < 10 ) ? false: true b. myBoolean = (x > 5 && y > 10 ) ? true: false c. myBoolean = (x < 5 || y > 10 ) ? true: false d. myBoolean = (x > 5 || y > 10 ) ? true: false

d

Which expression evaluates to true if the corresponding characters of strings s1 and s2 are equal independent of case? Ex: "C" and "c" should be considered equal. a. strcmp(str1[i], str2[i]) == 0 b. strcmp(tolower(str1[i]),tolower(str1[i])) == 0 c. strcmp(str1[i], toupper(str2[i])) == 0 d. strcmp(toupper(str1[i]), toupper(str2[i])) == 0

d

Which expressions for XXX and YYY correctly output the text for pre-teen and teenager? Choices are in the form XXX / YYY. if (XXX) { // Output "Pre-teen" } else if (YYY) { // Output "Teenager" } a.age >= 13 / age <= 19 b.age <= 13 / age > 13 c.age < 13 / age < 19 d.age < 13 / age <= 19

d

Which input for char c causes "Done" to be output next? c = 'y'; while (c = 'y') { // Do something printf("Enter y to continue, n to quit: \n"); scanf("%c", &c); } printf("Done\n"); a. 'y' only b. 'n' only c. Any value other than 'y' d. No such value (infinite loop)

d

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")){ printf("In loop\n"); scanf("%s", s); } a. "q" only b. "Q" only c. Either "q" or "Q" d. "Quit"

d

Why is it best to develop a large program incrementally? a. The code is less modular b. The compiler will compile without errors c. The program is easier to write but harder to debug d. The program is easier to debug

d

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.

d. Perfect temperature.Too cold.

Which XXX outputs all the elements of vector myVals? for (i = 0; XXX; ++i) {cout << myVals.at(i) << " ";} i < myVals.size; i <= myVals.size(); i < myVals.size(); No such expression as the number of elements is unknown.

i < myVals.size();

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 i = -10; i <= 10; i = i + 2 i = -10; (i * 2) < 10; ++i i = -10; (i * 2) <= 10, ++i

i = -10; i <= 10; i = i + 2

Which assigns the vector's last element with 99? vector<int> myVector(15); myVector.at(0) = 99; myVector.at(14) = 99; myVector.at(15) = 99; myVector.at(16) = 99;

myVector.at(14) = 99;

Which assigns the array's first element with 99?int[] myVector = new int[4]; Question options: myVector[] = 99; myVector[-1] = 99; myVector[0] = 99; myVector[1] = 99;

myVector[0] = 99;

Which assigns the array's last element with 99?int[] myVector = new int[15]; Question options: myVector[0] = 99; myVector[14] = 99; myVector[15] = 99; myVector[16] = 99;

myVector[14] = 99;

For the string "Orange", what character is at index 3?

n

Given two arrays, studentNames that maintains a list of student names, 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. String[] studentNames = new String[NUM_STUDENTS]; int[] studentScores = new int[NUM_STUDENTS]; int i; for (i = 0; i < NUM_STUDENTS; ++i) { if (XXX > 80) { System.out.print(YYY + " "); } } Question options:studentNames[i] / studentNames[i] studentNames[i] / studentScores[i] studentScores[i] / studentNames[i] studentScores[i] / studentScores[i]

studentScores[i] / studentNames[i]

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 sum = currVal / currVal == 0 / sum = currVal sum = 1 / currVal != 0 / sum = sum + 1 cin >> sum / currVal == 0 / cin >> sum

sum = 0 / currVal != 0 / sum = sum + currVal


Ensembles d'études connexes

What three factors affect how magma forms?

View Set

Leadership NCLEX Questions - Delegation

View Set

Biology 123 Chapter 12 (Mastering)

View Set