Midterm Exam
Question 1
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
// before’s elements set to: 0, 4, 8, then 12
after.at(0) = before.at(0);
for(i = 1; i < before.size(); ++i) {
tmp = before.at(i-1) + before.at(i);
after.at(i) = tmp / 2;
cout << after.at(i) << ” “;
}Select one:a. 0 4 8 12b. 4 8 12c. 0 2 6 10d. 2 6 10
Feedback
The correct answer is: 2 6 10
Question 2
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
char myFirstInitial = ‘b’;
switch (myFirstInitial) {
case ‘a’:
cout << ‘A’;
case ‘b’:
cout << ‘B’;
case ‘c’:
cout << ‘C’;
default :
cout << ‘D’;
}Select one:a. BCD
b. Bc. BCd. D
Feedback
The correct answer is: BCD
Question 3
Incorrect0.00 points out of 5.00Flag question
Question text
Which line of code will cause an error when added to the following program?
int main() {
const int numCtry=16;
vector<string> ctryNames(numCtry);
vector<int> ctryMins(numCtry);
// line of code here
return 0;
}Select one:a. ctryNames = “Germany”;b. ctryNames.at(0) = ctryMins.at(0);c. ctryNames.at(5) = ctryNames.at(0);d. ctryMins.at(0) = 223;
Feedback
The correct answer is: ctryNames.at(0) = ctryMins.at(0);
Question 4
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int y = 4; int z = 7;
cout << (z % y);
return 0;
}Select one:a. 1b. 3
c. 7d. 28
Feedback
The correct answer is: 3
Question 5
Correct5.00 points out of 5.00Flag question
Question text
Which of the following defines an array named nums that stores 15 items of type int?Select one:a. int nums[15];
b. int nums[] = 15;c. int nums = [15];d. nums = int[15];
Feedback
The correct answer is: int nums[15];
Question 6
Correct5.00 points out of 5.00Flag question
Question text
Which expression determines whether x is not negative?Select one:a. !(x > 0)b. !(x >= 1)c. !(x < 0)
d. !(x == 0)
Feedback
The correct answer is: !(x < 0)
Question 7
Incorrect0.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int i = 10;
while (i < 100) {
i = i * 2;
cout << i << ” “;
}
return 0;
}Select one:a. 10 20 40 80 160b. 10 20 40 80c. 20 40 80
d. 20 40 80 160
Feedback
The correct answer is: 20 40 80 160
Question 8
Correct5.00 points out of 5.00Flag question
Question text
Which line of code contains a syntax error?int main() {
double roomTemp; // A)
string roomName;
roomTemp = 0.0; // B)
roomName = ‘living room’; // C)
// main code
return 0;
}Select one:a. double roomTemp;b. roomTemp = 0.0;c. roomName = ‘living room’;
d. No syntax errors.
Feedback
The correct answer is: roomName = ‘living room’;
Question 9
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 0; int y = 2;
while (x == 10) {
cout << x << ” “;
x = x * y;
}
return 0;
}Select one:a. 0 2 4 6 8 10b. 2 4 6 8 10c. Loop is never entered. No output.
d. Infinite loop causes infinite output.
Feedback
The correct answer is: Loop is never entered. No output.
Question 10
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 53; int y = 0;
if( x > 31 ) {
y = 30;
}
else {
y = 10;
}
cout << y;
return 0;
}Select one:a. 30
b. 53c. 10d. 0
Feedback
The correct answer is: 30
Question 11
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code assuming the vector nums contains the values: -25, 0, 3, 15, 17, -12, and 0.
cnt = 0;
for(i = 0; i < nums.size() ; ++i) {
if( nums.at(i) > 0 ) {
++cnt;
}
}
cout << cnt << endl;Select one:a. 0b. 3
c. 5d. 7
Feedback
The correct answer is: 3
Question 12
Correct5.00 points out of 5.00Flag question
Question text
What is a variable in coding?Select one:a. Used to denote a list of statements.b. A row of text.c. Represents a particular memory location.
d. Textual representation of a program.
Feedback
The correct answer is: Represents a particular memory location.
Question 13
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
double y = 5;
cout << y / 2.0;
return 0;
}Select one:a. 0b. 2c. 2.5
d. No output. Error in code.
Feedback
The correct answer is: 2.5
Question 14
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 3;
double y = 2.4;
y = y + static_cast<double>(x);
cout << y;
return 0;
}Select one:a. 2.4b. 5c. 5.4
d. No output. Error in code.
Feedback
The correct answer is: 5.4
Question 15
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
string cityName = “La Jolla”;
cityName.push_back(‘!’);
cout << cityName;
return 0;
}Select one:a. La Joll!b. !!!!!!!!c. !La Jollad. La Jolla!
Feedback
The correct answer is: La Jolla!
Question 16
Correct5.00 points out of 5.00Flag question
Question text
What is RAM in a computer?Select one:a. The doubling of IC capacity roughly every 18 months.b. Non-volatile storage with slower access.c. Manages programs and interfaces with peripherals.d. Volatile storage with faster access usually located off processor chip.
Feedback
The correct answer is: Volatile storage with faster access usually located off processor chip.
Question 17
Correct5.00 points out of 5.00Flag question
Question text
Convert the binary number 00100111 to decimal:Select one:a. 39
b. 38c. 33d. 31
Feedback
The correct answer is: 39
Question 18
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int val = 8;
val = val + val + 1;
cout << val;
return 0;
}Select one:a. 9b. 17
c. 16d. 8
Feedback
The correct answer is: 17
Question 19
Correct5.00 points out of 5.00Flag question
Question text
Which expression determines whether two times x is greater than y?Select one:a. !( (x * 2) > y)b. (x * 2) > y
c. !( (x * 2) == y)d. x > (y * 2)
Feedback
The correct answer is: (x * 2) > y
Question 20
Correct5.00 points out of 5.00Flag question
Question text
What is main in C++?Select one:a. Used to denote a list of statements.b. The starting place of a program.
c. Represents a particular memory location.d. Textual representation of a program.
Feedback
The correct answer is: The starting place of a program.
Question 21
Correct5.00 points out of 5.00Flag question
Question text
Which line of code produces the following output:
Enter an integer:Select one:a. cout << “Enter an integer:”;
b. output << “Enter an integer:”;c. cout << ‘Enter an integer:’;d. print << ‘Enter an integer:’;
Feedback
The correct answer is: cout << “Enter an integer:”;
Question 22
Correct5.00 points out of 5.00Flag question
Question text
Which function takes the log of base ten of float y?Select one:a. log(y);b. log10(y);
c. fabs(y);d. ceil(y);
Feedback
The correct answer is: log10(y);
Question 23
Correct5.00 points out of 5.00Flag question
Question text
Which statement contains a syntax error?
int main () {
int day;
cout << “Please enter which day of the month it is: “; // A)
cin >> day // B)
cout << “There are “ << 31 – day << “ days left until next month.”; // C)
return 0;
}Select one:a. cout << “Please enter which day of the month it is: “;b. cin >> day
c. cout << “There are “ << 31 – day << “ days left until next month.”;d. No errors.
Feedback
The correct answer is: cin >> day
Question 24
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
string cityName = “La Jolla”;
cout << cityName.at(3);
return 0;
}Select one:a. ab. (space)c. J
d. I
Feedback
The correct answer is: J
Question 25
Correct5.00 points out of 5.00Flag question
Question text
Which line of code causes an error?
int main() {
const int N = 5;
int nums[N] = {3, 4, 1, 6, 4}; // A)
int i = 0;
nums.at(0) = -1; // B)
cout << nums[0] << endl; // C)
return 0;
}Select one:a. int nums[N] = {3, 4, 1, 6, 4};b. nums.at(0) = -1;
c. cout << nums[0] << endl;d. None of the above.
Feedback
The correct answer is: nums.at(0) = -1;
Question 26
Correct5.00 points out of 5.00Flag question
Question text
Which of the following defines a vector of integers named nums with 3 elements each initialized to 5?Select one:a. vector<nums> 3(5);b. vector<int> nums = 3(5);c. vector<int> nums(3, 5);
d. vector<3> nums(5);
Feedback
The correct answer is: vector<int> nums(3, 5);
Question 27
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 10; int y = 15;
x = (x > y) ? x : y; // line 3
cout << x << endl; // line 4
return 0;
}Select one:a. 10b. 15
c. No output. Error on line 4.d. No output. Error on line 3.
Feedback
The correct answer is: 15
Question 28
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 10; int y = 20; int z = 15;
if (x < 0) {
z = 0;
}
else if (y < 30) {
z = 10;
}
else {
z = 20;
}
cout << z;
return 0;
}Select one:a. 0b. 10
c. 15d. 20
Feedback
The correct answer is: 10
Question 29
Correct5.00 points out of 5.00Flag question
Question text
Select the statement that completes the following for loop so that the loop iterates over the entire vector v.
vector<int> v(10);
int i = 0;
for (i = 0; /* statement goes here */ ; ++i) {
v.at(i) = i;
}Select one:a. i <= v.size()b. i < v.size()
c. i < size(v)d. i <= 10
Feedback
The correct answer is: i < v.size()
Question 30
Correct5.00 points out of 5.00Flag question
Question text
Which statement defines a 16-bit unsigned integer variable?Select one:a. short short numSeconds;b. unsigned short numSeconds;
c. unsigned int numSeconds;d. short numSeconds;
Feedback
The correct answer is: unsigned short numSeconds;
Question 31
Correct5.00 points out of 5.00Flag question
Question text
What is the value assigned to variable z for the following code, assuming the initial values of a = 2, b = 2, and c = 30?
mult = 0;
while (a < 20) {
mult = b * a;
if (mult > c) break;
a = a + 1;
}
z = a;Select one:a. 16
b. 18c. 30d. 40
Feedback
The correct answer is: 16
Question 32
Correct5.00 points out of 5.00Flag question
Question text
Which loop will be iterated exactly 5 times?Select one:a. for (i = 1; i < 5; ++i)b. for (i = 0; i <= 5; ++i)c. for (i = 1; i <= 5; ++i)
d. for (i = 1; i <= 5; –i)
Feedback
The correct answer is: for (i = 1; i <= 5; ++i)
Question 33
Correct5.00 points out of 5.00Flag question
Question text
What is a compiler in computing?Select one:a. Translates a high-level language program into low-level machine instructions.
b. Another word for program.c. Human-readable processor instructions; an assembler translates to machine instructions (0s and 1s).d. A series of 0s and 1s, stored in memory, that tells a processor to carry out a particular operation like multiplication.
Feedback
The correct answer is: Translates a high-level language program into low-level machine instructions.
Question 34
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
char c1 = ‘-‘; char c2 = ‘-‘;
c1 = ‘a’;
while (c1 < ‘c’) {
c2 = ‘a’;
while (c2 < ‘d’) {
cout << c1 << c2 << ” “;
++c2;
}
++c1;
}
return 0;
}Select one:a. aa ab ac ba bb bc
b. aa ab ba bbc. aa ab ac ba bb bc ca cb ccd. aa bb
Feedback
The correct answer is: aa ab ac ba bb bc
Question 35
Correct5.00 points out of 5.00Flag question
Question text
Given the following, assign the value stored in the fourth column of the first row of an array dataVals to a variable x.
const int rows = 7;
const int cols = 5;
int dataVals[rows][cols];
Select one:a. x = dataVals[3][0];b. x = dataVals[4][1];c. x = dataVals[0][3];
d. x = dataVals[1][4];
Feedback
The correct answer is: x = dataVals[0][3];
Question 36
Correct5.00 points out of 5.00Flag question
Question text
What is a cache in a computer?Select one:a. The doubling of IC capacity roughly every 18 months.b. Non-volatile storage with slower access.c. Manages programs and interfaces with peripherals.d. Relatively-small volatile storage with fastest access located in processor chip.
Feedback
The correct answer is: Relatively-small volatile storage with fastest access located in processor chip.
Question 37
Correct5.00 points out of 5.00Flag question
Question text
Which expression determines whether x is between 10 and 20, and y is between 0 and 99?Select one:a. ((x < y) || (x > y) && !(y > 99) && (x > 10)b. ((x == 10) || (x == 20)) && ((y == 0) || (y == 99))c. (x > 10) || (x < 20) || (y > 0) || (y < 99)d. (x > 10) && (x < 20) && (y > 0) && (y < 99)
Feedback
The correct answer is: (x > 10) && (x < 20) && (y > 0) && (y < 99)
Question 38
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code?
int main() {
int x = 5; int y = 6; int z = 2;
x = x + y;
z = x – 2;
cout << z;
return 0;
}Select one:a. 2b. 5c. 11d. 9
Feedback
The correct answer is: 9
Question 39
Correct5.00 points out of 5.00Flag question
Question text
What is the output of the following code if the code output 19574 in the previous run?
int main() {
srand(50);
cout << rand();
return 0;
}Select one:a. 19574
b. 19575c. 19584d. Cannot determine.
Feedback
The correct answer is: 19574
Question 40
Correct5.00 points out of 5.00Flag question
Question text
How many total elements are in an array with 4 rows and 3 columns?Select one:a. 4b. 6c. 12
d. 16
Feedback
The correct answer is: 12
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
