CSCI 207, COP1220 Final, Midterm, Computer Programming 1500 Final

Ace your homework & exams now with Quizwiz!

the file is overwritten with the new data

If a file exists in a directory and contains data, when an ofstream is used to write data into the file ______

What is read into string myString for input "One-hit wonder". One One- One-hit One-hit wonder

One-hit

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

a

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

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

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

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

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

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

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

10

What is y after executing the statements? x = 4; y = x + 1; x = 3; y = y * 2;

10

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

1stName

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

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

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

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? 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 declaration assigns a variable with 5 such that the value can not be later changed? const int = 5; int numItems = 5; int NUM_ITEMS = 5; const int NUM_ITEMS = 5;

const int NUM_ITEMS = 5;

Which expression fails to compute the area of a triangle having a base b and height h (area is one-half base time height)? (1.0 / 2.0) * b * h (1 / 2)* b * h (b * h) / 2.0 0.5 * b * h

(1 / 2)* b * h

What is the ending value of x? x = 160 / 20 / 4;

2

For which quantity is a double the best type?

Height of a building

Which expression evaluates to 3.5? int x = 7; int y = 1; x * (1 / 2) (x / 2.0) x.0 / 2 (x / 2) * 1.0

(x / 2.0)

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

0..9

What is the ending value of y? int x; int y; x = 2; y = ((x + 1) / 5) + (x / 2) ;

1

Which is a correct scientific notation for the floating-point literal: 0.00001 0.1e-6 0.1e-5 1.0e-5 1.0e-6

1.0e-5

What is the ending value of cost? int numApples = 3; double cost; cost = 1.2 * numApples;

3.6

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

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

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

Error: Any default parameters must always end the parameter list

A programmer defines the following: int CalcRoute(int x = -1, int y, int z) ...What is true for the following call: CalcRoute(2,3)?

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

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

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

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

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

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

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

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

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

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

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

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

Using various calls involving assert() is a good way to test the function

Which is true about testing a function with three integer parameters and one integer return value?

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

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

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

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() { 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 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 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 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

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

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

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

2

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

Line 3

Function CalcSum() was copied and modified to form the new function CalcProduct(). Which line of the new function contains and error? int CalcSum( int a, int b) { int p; //Line 1 p = a * b; //Line 2 return s; // Line 3 }

Constant, and pass by reference

Give a function with one vector parameter ages. How should the parameter be defined if ages may be very large, and the function will not modify the parameter?

(10,j,k+5)

Given integers i, j, k, which XXX correctly passes three integer arguments for the following function call? addInts XXX;

Test('x');

Given the following function definition, which function call prints x, y, 0? void Test(char 1, char b - 'y', int num = 0) { cout << a << "," << b << "," << num << endl; }

9

If the function's vector parameter is 0 3 9 7 7, what does the function return? int MyFct(const vector<int>& v) { int i; int x; x = v.at(0); for (i=0;i<v.size();++i) { if(v.at(i)>x) { x = v.at(i); } } return x; }

1

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

3

How many function arguments exist in the code? double FahrenheitToCelsuis(double fahrenheit) { return (fahrenheit - 32.0) * 5.0 / 9.0; } int main () { double fahrenheit; cin >> fahrenheit; int c1; int c2; int c3; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(fahrenheit + 5.0); }

3

How many function calls exist in the following code? int Calc1 (int a, int b) { return 1 + b /2; } int main() { int x; int y; x = Calc1 (5,3); cout << x; y = Calc2 (5,3); cout << y; cout << Calc2 (5,3); }

1

How many function parameters exist in the code? double FahrenheitToCelsius(double fahrenheit) { return (fahrenheit - 32.0) * 5.0 / 9.0; } int main() { double fahrenheit; cin >> fahrenheit; int c1; int c2; int c3; int c4; c1 = FahrenheitToCelsius(fahrenheit); c2 = FahrenheitToCelsius(32); c3 = FahrenheitToCelsius(78); c4 = FahrenheitToCelsius(100); }

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

b

fail.()

The ______ function returns true if the previous stream operation had an error.

false when the end of the file has not been reached

The eof() function of input streams returns __________

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

name

The inFS.open(str) function has a string parameter str that specifies the _____ of the file to open.

Which is best declared as a constant?

The number of feet in a yard

Reading from the file... This

What is output? #include <iostream> #include <fstream> using namespace std; int main () { ofstream outFS; ifstream inFS; string str; outFS.open("myfile.txt."); outFS << "This is a test data"; if(!outFS.is_open()) { cout << "Could not open file myoutfile.txt" << endl; return 1; } outFS.close(); inFS.open("myfile.txt"); cout << "Reading from file..." << endl; inFS >> str; cout << str; return 0; }

6.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; }

MyFct() cannot be called with a literal

What is the error in this code? void MyFct(int& x) { x = (x*x) + 1; } int main () { cout << MyFct(9); }

Opening the file Could not open the file.

What is the output if myContact.txt file does not exist? #include <iostream> #include <fstream> using namespace std; int main () { ifstream inFS; cout << "Opening the file." << endl; inFS.open("myContact.txt"); if(!inFS.is_open()) { cout << "Could not open the file." << endl; return 1; } inFS.close(); return 0; }

Tom

What is the output if the input is Tom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl << playerName; return 0; }

Sum 150

What is the output if the user enters 10 20 30 40 50 ? #include <iostream> #include <sstream> #include <string> using namespace std; int main () { istringstream inSS; int number; int sum = 0; string numList; cout << "Enters numbers separated by spaces:"; getline(cin, numList); inSS.str(numList); while (inSS >> number) { sum = sum + number; } cout << "Sum:" << sum << endl; return 0; }

Invalid seconds 2:24:1

What is the output of the call DisplayTime(2, 24, 65)? void DisplayTime(int hours, int minutes, int seconds) { // Parameter error checking if ((hours < 1) || (hours > 12)) { cout << "Invalid hours" << endl; hours = 1; } if((minutes < 1) || (minutes > 60 )) { cout << "Invalid minutes" << endl; minutes = 1; } if((seconds < 1) || (seconds > 60 )) { cout << "Invalid seconds " << endl; seconds = 1; } cout << hours << ":" << minutes << ":" << seconds; }

22

What is the output? #include <iostream> using namespace std; const double LB_PER_KG = 2.2; double KgsToLbs(double kilograms) { double pounds; pounds = kilograms * LB_PER_KG; return pounds; } int main() { double pounds; pounds = KgsToLbs(10); cout << pounds; return 0; }

`Checking for fever...

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; cout << "You have " << degreesOfFever << "degrees of fever."; } else if(temperature < CUTOFF_TEMP) { degreesOfFever = CUTOFF_TEMP - temperature; cout << "Your temperature is" << degreesOfFever << "below 95."; } return degreesOfFever; } int main () { double bodyTemperature; double degreesOfFever; bodyTemperature = 96.0; cout << "Checking for fever..." ; degreesOfFEver = CheckForFever(bodyTemperature); return 0; }

16

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

10

What is the output? int FindSqr(int a) { int t; t = a * a; return a; } int main () { int square; square = FindSqr(10); cout << square; return 0; }

Error. Compiler cannot determine which function to call

What is the output? void Area (double x, double y) { cout << x * y; } void Area(int base, int height) { cout << (base * height) / 2; } void Area(int length, int width) { cout << length * width; } int main() { int b; int h; b = 4; h = 5; Area(b,h); }

Function 2: 10

What is the output? void Display (int i) { cout << "Function 1:" << i << endl; } void Display (double f) { cout << "Function 2:" << f << endl; } int main() { double i; i = 10.0; Display(i); return 0; }

No output. A compiler error occurs due to unknown variable even

What is the output? void isEven(int num) { int even; if (num % 2 == 0) { even = 1; } else { even = 0 } } int main () { IsEven(7); cout << even; return 0; }

Individually testing a small part (or unit) of a program, typically a function, using a separate program called a test harness

What is unit testing?

isstringstream inSS(userInfo);

Which XXX (string stream) returns Hello John Denver as the output? #include <iostream> #include <sstream> #include <string> using namespace std; int main () { string userInfo = "John Denver"; XXX string firstName; string lastName; inSS >> firstName; inSS >> lastName; cout << "Hello" << firstName << " " << lastName << endl; return 0; }

const vector <int> scores

Which XXX best defines the function's integer vector parameter scores, if scores will have just a few elements, and the function will not change scores? void Quiz1 (XXX) { ... }

return PI_VAL * CalcSquare(r);

Which XXX calculates the area using the CalcSquare() function? The formula to calculate the area of a circle is pi * r2. double CalcSquare(double r) { const double PI_VAL = 3.14159265; XXX; } int main() { cout << CalcArea(5.0); return 0; }

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 >> userScore; } int main() { string userName; int userScore; XXX; cout << userName << "," << userScore << endl; return 0; }

PrintMessage()

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

double ConeVolume (double r, double h); double ComputeSquare (double r);

Which XXX complete the program to calculate the volume of a cone? XXX int main () { double coneVol; coneVol = ConeVolume(2,4); cout << coneVol; return 0; } double ConeVolume (double r, double h) { return (0.33) * 3.14 * ComputeSquare(r) * h; } double ComputeSquare (double r) { return r * r; }

cout << name << "is" << age << "years old";

Which XXX generates "Adam is 30 years old." as the output? using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; }

playerObj << players << "is" << age << "years old.";

Which XXX generates "Tim Smith is 19 years old." as the output? #include <iostream> #include <sstream> #include <string> using namespace std; int main () { ostringstream playerObj; string players; int age; players = "Tim Smith"; age = 19 XXX cout << playerObj.str(); return 0; }

input >> numberPlayers;

Which XXX is used to read and store the data into the variable numberPlayers from the file that is opened by the stream inputFile? #include <iostream> #include <fstream> using namespace std; int main () { ifstream inputFile; int numberPlayers; inputFile.open("playerNumber.txt"); if (!inputFile.is_open()) { cout << "Could not open file numFile.txt." << endl; return 1; } XXX cout << "Players Number." << numberPlayers; return 0; }

if(!inFS.fail())

Which XXX will search the input mname in the GuestList.txt file? #include <iostream> #include <fstream> using namespace std; int main () { ifstream inFS; string userName; string listName; int flag = 0; inFS.open("GuestList.txt"); if(!inFS.is_open()) { cout << "Could not open file numFile.txt." <<endl; return 1; } cout << "Enter guest name: "; cin >> userName; while (!inFS.eof()) { inFS >> listName; XXX { if(listName == userName) { flag = 1; } } } if(flag == 1) { cout << userName << "is in the guest list" << endl; } else { cout << userName << "not in the guest list" << endl; } inFS.close(); return 0; }

The variables prev and next should be passed by reference

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

int ProcessData (double num, int x = 2){...};

Which function is called? p = ProcessData(9.5);

double ComputeEnergyConsumed(double power, double hours) { return (power * hours) / 1000; }

Which function is most appropriate to improve the given code? int main() { double powerConsumptionApp1; double powerConsumptionApp2; double powerConsumptionApp3; double hoursOfUse1; double hoursOfUse2; double hoursOfUse3; double EnergyPerDay1; double EnergyPerDay2; double EnergyPerDay3; double totalEnergyConsumed; powerConsumptionApp1 = 600.85; hoursOfUse1 = 12.8; energyPerDay1 = (powerConsumptionApp1 * hoursOfUse1) / 1000; powerConsumptionApp2 = 1800.45; hoursOfUse2 = 0.45; energyPerDay2 = (powerConsumptionApp2 * hoursOfUse2) / 1000; powerConsumptionApp3 = 70; hoursOfUse3 = 1.5; energyPerDay3 = (powerConsumptionApp3 * hoursOfUse3) / 1000; totalEnergyConsumed = energyPerDay1 + energyPerDay2 + energyPerDay3; cout << "The total energy consumed per day is " << totalEnergyConsumed << endl; return 0; }

#include <sstream>

Which header file should be used while working with the output string stream?

A function's local cariables are discarded upon a function's return, each new call creates a new local variable in memory

Which is true regarding how function's work?

Line 3

Which line of the function has an error? int ComputeSumOfSquare(int num1, int num2) { int sum; //line 1 sum = (num1 * num1) + (num2 * num2); //line 2 return; //line 3 }

<<

Which operator is the insertion operator?

A __________ is a computer component that stores files and other data. a. disk b. monitor c. keyboard d. processor

a

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

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

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

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

a

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

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

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

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

a

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

a

What value of 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

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

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 () { 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()

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

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 item converts a high-level language program to low-level machine instructions? a. Compiler b. Machine instruction c. Assembly language d. Memory

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

Given only int variables a and b, which is a valid expression? 4a + 3 a + ab a + -2 2 x 3

a + -2

What does the compiler do upon reaching this variable declaration? int x;

allocates a memory location for x

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

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

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

C++ is _________. a. derived from Fortran b. derived from C c. derived from Python d. derived independently of any other language

b

Choose the statement that generates 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";

b

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

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

b

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

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

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? cin >> x; while (x > 100) { // Do something cin >> x; } a. 1 b. 2 c. 3 d. 4

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

b

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

b

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

b

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

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

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

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

b

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

b

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

b

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!")

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

b

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

b

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

b

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

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

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

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;

c

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)

c

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

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

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

In what component does a processor store the processor's required instructions and data? a. Mailbox b. Switch c. Memory d. Bit

c

In what year was the first book of C published? a. 1819 b. 1920 c. 1978 d. 2010

c

RAM is an abbreviation that stands for: a. Real Analog Memory b. Ranged Access Memory c. Random Access Memory d. Random Abbreviated Memory

c

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

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 ints. cin >> x; sum = 0; for (i = 0; i < x; ++i) { cin >> 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 count } 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

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

c

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.

c

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)

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

c

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

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

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

c

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

c

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)

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

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

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

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

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

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

The ____________ is a process that manages programs and interfaces with peripherals. a. clock b. BIOS c. integrated circuit d. operating system

d

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

d

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

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

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

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

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

d

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

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

d

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;

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

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

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 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 an example of a process? a. int b. y, 10 c. 15 d. x + y

d

Which is not a component of a computer? a. Clock b. Memory c. Processor d. Programmer

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

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

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? int worldPopulation; long worldPopulation; long long worldPopulation; long long long worldPopulation;

long long worldPopulation;

An identifier can _______.

start with an underscore

Which expression doubles x? x += 2; x *= 2; x *= x; x *= x * 2;

x *=2


Related study sets

Tema 1 La crisis del Antiguo Régimen, Tema 7: La Segunda Guerra Mundial, Tema 6 La época de entreguerras (1919 - 1939), Tema 5. Imperialismo, guerra y revolución, Tema 3: La Revolución Industrial y los cambios sociales, Tema 2: Revoluciones liberales...

View Set

Blood Bank - Serologic and Molecular Testing

View Set

Leadership Midterm Case Study 7: Spinal Cord Injury

View Set

Midcourse Content Exam PDBIO 210

View Set

Chapter 10: Viral Genomics, Diversity, and Ecology

View Set