COMSCI

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/124

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

125 Terms

1
New cards
In an instruction like: z = x + y, the symbols x, y, and z are examples of _____.
variables
2
New cards
What does this code output?


cout << "I ";
cout << "want pie." << endl;
I want pie.
3
New cards
What will a compiler do for the following three lines of code?


// x = 2; // width
// y = 0.5
// z = x * y; Total area
Ignore all three lines
4
New cards
C++ is _____.
derived from C
5
New cards
Which is not a component of a computer?
Programmer
6
New cards
Which item converts a high-level language program to low-level machine instructions?
Compiler
7
New cards
If a program compiles without errors, the program is free from _____.
syntax errors
8
New cards
A program should compute two times x. Which statement has a logic error?
y = x * x;
9
New cards
Choose the statement(s) that generate(s) this output:
I wish
you were here
10
New cards
What will a compiler do for the following code?


/*
numItems = 2; /* Total items to buy */
rate = 0.5;
*/
Generate an error.
11
New cards
Which one of the following would be an illegal variable name?
3rdQuartile
12
New cards
What will the value of x be after the following statements execute?
int x;
x = 11 % 5;
1
13
New cards
What will the following code display?
cout << "Monday";
cout << "Tuesday";
cout << "Wednesday";
MondayTuesdayWednesday
14
New cards
What is the value of an integer variable "y" after the following statement?
y= 44/33;
1
15
New cards
What is the output of the following statement?
cout << 4 * (15 / (1 + 3)) << endl;
12
16
New cards

Assume that a program has the following string object definition: string name;

Which of the following statements correctly assigns a string literal to the string object?

name = "Jane";

17
New cards
Which yields 3.4?
static_castdouble(17) / static_castdouble(5)
18
New cards
Which statement will read an entire line of input into the following string object? string address;
getline(cin, address);
19
New cards
Convert the decimal number 24 to an 8-bit binary number.
00011000
20
New cards
What is the output of the following program fragment?age = 29;cout << "Are you" << age << "years old?" << endl;
Are you29years old?
21
New cards
Which of the following choice represents a correct logical expression (right part after "=>") of the described condition (left part before "=>")?
userNum is neither 5 nor 10 =!( (userNum == 5) || (userNum == 10) )
22
New cards
Given numPeople = 10, numCars = 2, userKey = 'q'. Which choice is false?
(numPeople = 10) (numCars 2)
23
New cards
According to code like this, when userChar = 'E', which value of variable "encodedVal" is correct?
switch (userChar) { case 'A': encodedVal = 1; break; case 'B': encodedVal = 2; break; case 'C': case 'D': encodedVal = 4; break; case 'E': encodedVal = 5; case 'F': encodedVal = 6; break; default: encodedVal = -1; break; }
6
24
New cards

What is the output of the following code?

int w = 98;

int x = 99;

int y = 0;

int z = 1;

if (x >= 99){ if (x < 99){ cout << y << endl; }

else { cout << z << endl; }}

else { if (x==99){ cout << x << endl; }

else { cout << w << endl; }}

1

25
New cards
Without this statement appearing in a switch construct, the program "falls through" all of the statements below the one with the matching case expression.
break
26
New cards

Which value can be entered to cause the following code segment to display the message: "That number is acceptable."

int number;

cin >> number;

if (number > 10 && number < 100) { cout << "That number is acceptable" << endl;}

else { cout << "That number is not acceptable" << endl;}

99

27
New cards
Which statement allows you to properly check the char variable code to determine whether it is equal to a "C" and then output "This is a check" and then advance to a new line?
if (code == 'C') { cout "This is a check" endl;}
28
New cards

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

29
New cards
Which choice is not correct according to code like this:
int csci40Score;
if (csci40Score
3rd branch range is [69, 84];
30
New cards

Which of the following statement is required for calling function "sqrt()"?

include cmath

31
New cards
How many times will the following loop display "Hello!"?
for (i=1; i
19
32
New cards

How many times will the following loop display "Hello!"?
for (i = 0; i <= 20; ++i){ cout << "Hello!" << endl; }

21

33
New cards
This is a variable that is regularly incremented or decremented each time a loop iterates.
counter
34
New cards
This statement causes a loop to terminate early.
break
35
New cards

What is the output of this code:

string x = "One";

string y = "Two";

string temp;

temp = y + x;

cout << temp << endl;

TwoOne

36
New cards
Complete the for loop to achieve the goal.
Iterate for i from 0 to 30 by 5s (0, 5, 10, 15, ...).
for (i=0; i
i=i+5
37
New cards
Complete the for loop to achieve the goal.
Iterate for i from 10 down to 0. Compare with 0.
for (i=10; ___________________ ; --i ) { // Loop body}
i=0;
38
New cards

How many times will the loop body execute?
Assume user would enter 'a', then 'b', then 'n'.

// Get userChar from user here while (userChar != 'n') { // Do something //Get userChar from user here }

Loops 2 times

39
New cards
How many times will the loop body execute?
Assume user would enter 'n', then 'n', then 'y'.

// Get userChar from user here while (userChar != 'n') { // Do something // Get userChar from user here }
0
40
New cards
What will the following code output? (For an infinite loop, type "IL")
int x = 5; int y = 18; while (y >= x) { cout << y << " "; y = y - x; }
18 13 8
41
New cards

Which input value causes "Goodbye" to be output next?

int x;

cin >> x;

while (x <= 0) { // Do something cin >> x;}

cout << "Goodbye";

1

42
New cards

What is the ending value of sum, if the input is 2 3 7 5? All variables are ints.
cin >> x;

sum = 0;

for (i = 0; i < x; ++i) { cin >> currValue; sum += currValue;}

10

43
New cards

A loop should output 1 to n. If n is 5, the output is 12345. What should XXX and YYY be? Choices are in the form XXX / YYY.

cin >> n;

for (XXX; i++) { cout << YYY;}

i = 0; i = n / i + 1

44
New cards
What is the output if count is 4?
for (i = count; i >= 0; --i) { // Output count cout << i;}
43210
45
New cards
What is the output?
int n;for (n = 0; n < 10; n = n + 3) { cout << n << " ";}
0 3 6 9
46
New cards
The program should determine the largest integer seen. What should XXX be, if the input values are any integers (negative and non-negative)? All variables are ints and have unknown initial values.
for (i = 0; i < 10; ++i) { cin >> currValue; if (i == 0) { // First iteration XXX; } else if (currValue > maxSoFar) { maxSoFar = currValue; }}
maxSoFar = currValue
47
New cards
The program should output even values between -10 and 10 (inclusive), so -10 -8 ... 8 10. What should XXX be?
for (XXX) { cout << i << " ";}
i = -10; i = 10; i = i + 2
48
New cards

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

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

49
New cards

Which input value causes the loop body to execute a 2nd time, thus outputting "In loop" again?

string s = "Go";

while ((s != "q") && (s != "Q")){ cout << "In loop" << endl; cin >> s;}

"Quit"

50
New cards

If the input is 12, what is the final value for numItems?
int x;

int numItems = 0;

cin >> x;

if (x <= 12) { numItems = 100;}

else { numItems = 200;}

numItems = numItems + 1;

101

51
New cards

Which input for char c causes "Done" to be output next?
c = 'y';

while (c = 'y') { // Do something cout << "Enter y to continue, n to quit: "; cin >> c;}

cout << "Done";

No such value (infinite loop)

52
New cards

Which expressions for XXX, YYY, and ZZZ output "Great job" for scores above 90, and "Nice try" otherwise? Choices are in the form XXX / YYY / ZZZ.

int score;

cin >> score;

if (XXX) { cout << YYY;}

else { cout << ZZZ;}

score >= 91 / "Nice try" / "Great job"

53
New cards

What is the final value of y?
int x = 77;

int y = 4;

if (x == 77) { y = y + 1;}

if (x < 100) { y = y + 1;}

if (x > 77) { y = y + 1;}

y = y + 1;

7

54
New cards
What is y's ending value?
int x;int y = 0;cin >> x;if (x = 20) { y = 3;}
Always 3 no matter what the input
55
New cards

Which outputs "Negative" for values less than 0, otherwise outputs "Non-negative"?

if (val = 0) { cout "Non-negative";}

else { cout "Negative"; }

56
New cards

Which expressions for YYY and ZZZ correctly output the indicated ranges? Assume int x's value will be 0 or greater. Choices are in the form YYY / ZZZ.
if (YYY) { // Output "0-29"} else if (ZZZ) { // Output "30-39"}else { // Output "40+"}

x < 30 / x < 40

57
New cards

What is the output, if the input is 3 2 1 0?
cin >> x;

while (x > 0) { cout << 2 * x << " ";}

6 6 6 6 6 … (infinite loop)

58
New cards
Which expression for XXX outputs "Modern era" for any year 1980 and later?
if (year < 2000) { // Output "Past"}else if (XXX) { // Output "Modern era"}
(No such expression exists)
59
New cards

A restaurant gives a discount for children under 10. They also give the discount for adults over 55. Which expression evaluates to true if a discount should be given?

(age < 10) || (age > 55)

60
New cards
Which expression evaluates to false if x is 0 and y is 10?
(x == 0) && (y == 20)
61
New cards
To quit, a user types 'q'. To continue, a user types any other key. Which expression evaluates to true if a user should continue?
!(key == 'q')
62
New cards
Which expression for YYY correctly outputs that x is between 50-100?
if (YYY) { // Output "50, 51, ..., 99, 100"}
(x >= 50) && (x
63
New cards
What is the output for x = 15?
switch (x) { case 10: // Output: "First " break; case 20: // Output: "Second " break; default: // Output: "No match " break;}
No match
64
New cards

Which XXX and YYY will loop as long as the input is an integer less than 100? Choices are in the form XXX / YYY.

cin >> w;

while (XXX) { // Do something YYY;}

w < 100 / cin >> w

65
New cards
For what values of x does the default case execute in the code below? x is declared as an integer.
switch (x) { case 2: ... break; case 3: ... break; case 4: ... break; default: ... // When does this execute?}
Only for values that are not 2, 3, or 4
66
New cards

A loop should sum all inputs, stopping when the input is 0. If the input is 2 4 6 0, sum should end with 12. What should XXX, YYY, and ZZZ be? Choices are in the form XXX / YYY / ZZZ.

int sum;

int currVal;

XXX;

cin >> currVal;

while (YYY) { ZZZ; cin >> currVal;}

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

67
New cards

How many times does the while loop execute for the given input values of -1 4 0 9?
userNum = 3;

while (userNum > 0) { // Do something // Get userNum from input}

1

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

Which for loop will iterate 100 times?

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

70
New cards
What is the output, if the input is 3 2 4 5? All variables are ints.
cin >> num;for (i = 0; i < num; ++i) { cin >> curr; cout << curr;}
245
71
New cards
This vector function returns the number of elements in a vector.
size
72
New cards
What does the following statement do?vector z(10);
It creates avectorobject with a starting size of 10.
73
New cards
Which statement correctly defines a vector object for holding integers?
vectorint v;
74
New cards
What does the following code do with a vector "v" that has N double elements?
double temp = v.at(0);
v.at(0) = v.at(N-1);
v.at(N-1) = temp;
Swap the first and last elements of vector "v"
75
New cards
for (i = 0; _______________________ ;++i){
cout<< daysList.at(i)<< endl;
}
Complete the code to print all items for the given vector:
vector daysList(365);
i 365
76
New cards
________ algorithms are used to arrange random data into some order.
Sorting
77
New cards
Assign the vector's last item's value into the first position. Assume vector scoresList has 10 items.
scoresList.at(0) = scoresList.at(9)
78
New cards
What is the size of the myVector after the following statements:
vector myVector;myVector.push_back(1);myVector.pop_back();myVector.push_back(10);myVector.back();
1
79
New cards
Define an int vector testVctr with 50 elements.
vectorint testVctr(50);
80
New cards

Assume that a vector is defined as follows. What is the correct statement if we want to set the first element to 3?
vector v;

v.push_back(3); to set it to the first element

81
New cards
Given a function definition: void CalcVal(int a, int b, int c)and given int variables i, j, and k, which are valid syntax for the call CalcVal(...)?
CalcVal(k,i+j,99)
82
New cards
Given a function that returns the bigger value of two integers as follows: int max(int x, int y). Which of the following is the incorrect syntax for getting the maximum of three variables a, b, and c?
max(a,b,c)
83
New cards
If itemPrices has element values 45, 48, then after what function, itemPrices' element values are 45,48,38?
itemPrices.push_back(38);
84
New cards
Assume itemPrices initially has elements 45, 22, 38. After "pop_back" function executes, what does "itemPrices.at(2)" return? Select "error" if appropriate.
error
85
New cards
Which of the following is the correct syntax for a function call used to print out the area of a rectangle with sides being values of variables x and y? The function declaration is as follows:
int RectArea(int a, int b);
cout RectArea(x, y);
86
New cards
The size of vector "vctr" can be set or changed while a program is executing using:
vctr.resize(N)
87
New cards
Which correctly declares a function named "PrintDistance" that takes four integer parameters x1, y1, x2, y2? The function does not return any value.
void PrintDistance(int x1, int y1, int x2, int y2);
88
New cards
Assume that table1 is an instance of the Table class, and that the Table class has a member function named addEmptyChair. Which of the following is a valid call to the addEmptyChair member function?
table1.addEmptyChair();
89
New cards
Public members of a class object can be accessed with the ________.
dot operator
90
New cards
This type of member variable may NOT be accessed directly from a statement outside the class.
private
91
New cards
This type of member variable may be accessed only from within a function that is a member of the same class.
private
92
New cards
Which of the following is the correct syntax for accessing a "public" member "GetDist()" of a variable named "runnerInfo" of class "RunnerInfo"?
runnerInfo.GetDist()
93
New cards
Which of the following is the correct syntax for accessing a "private" member "GetDist()" of a variable named "runnerInfo" of class "RunnerInfo"?
There is no way to do this directly
94
New cards
Suppose we have a class named "PointClass" defined. What is the correct syntax for creating an object of PointClass named "point1"?
PointClass point1;
95
New cards
Which of the following is the correct declaration for pass by reference for a function that converts a given time to hours and mins?
void ConvHrMin (int timeVal, int hrVal, int minVal);
96
New cards
Which correctly declares a function named "CalcVal" that takes two integer parameters x and y? The function does not return any value.
void CalcVal(int x, int y);
97
New cards
What code for XXX, YYY correctly swaps a and b? Choices are written as XXX / YYY.


XXX;
a = b;
YYY;
b = tmp;
tmp = a / (nothing)
98
New cards
Which of the following prints out the data from a pointer/memory address, given the following code?
double x = 0.0;
double* p = &x;
cout *p endl;
99
New cards
Assume variable int numStudents = 12 is at memory address 99, and variable int* myPtr is at address 44. What does
cout << &numStudents;
output?
99
100
New cards
Given a pointer variable "sp" pointing to an object of class "Point" with a public member variable "x", which of the following is a correct statement to print the member variable?
cout (*sp).x;