Strings
Booleans
Conditionals
Functions
Extra
100

If you have a string named country that holds the value of "Uzbekistan" what does country.length() equal?

10

100

Which of the following is not a logical operator?

(a) &&

(b) !

(c) <=

(d) ||

c - c is a relational operator

100

Write a condition to determine if a variable num stores a number between 0 and 4, inclusive.

if (num >= 0 && num <= 4)

100

Which of the following is NOT true about functions in C++?
A) A function can return at most one value.
B) A function must always return a value.
C) Functions can take zero or more parameters.
D) Functions can call other functions.

B

100

T/F: If statements always need an Else statement afterwards

False

200

If you have a string named country that holds the value of "Uzbekistan" what does country[3] equal?

'e'

200

What is the missing value in the truth table?

F
200

int n = -5;

if (n){

    cout << "True branch"<< endl;}

else{

    cout << "False branch" << endl;}


True branch

200

int square(int n) {

    return n * n;

}

int main() {

    cout << square(3 + 1);

}

16

200

What's the difference between pass by value and pass by reference

Pass by reference actually updates the variable; pass by value only passes the current value of the variable. 

300

string s = "C++"; 

s += ' ';

s += "Rocks"; 

cout << s.length();

9

300

What are the integer representations of Boolean Values

0 and 1

300

T/F: When writing switch statements in c++ you must include a default case, otherwise your switch statement is not valid.

False

300

What does the keyword void mean when used as a function return type?

The function does not return a value (most used for printing things).

300

Why are "break"s important when writing switch statements?

So the code doesn't "fall through" to the next case.

400

If you have a string named country that holds the value of "Uzbekistan" what does country.substr[0,4] equal?

"Uzbe"

400

bool c = false;

(5 > 2) && !b

True

400

int x = 4;

if (x = 0){ 

    cout << "A"; }

else if (x > 0) {

    cout << "B"; }

else {

    cout << "C";}

C

400

int mystery(int a, int b) {

    if (a > b){

        return a - b;}

    else {

        return b - a;}

}

int main() {

    cout << mystery(10, 4) << endl;

    cout << mystery(4, 10) << endl;

}

6

6

400

What's the difference between a parameter and an argument in a function.

Arguments are the values that are actually passed into the function, parameters are the placeholders or variables defined in the function 

500

If you have a string named country that holds the value of "Uzbekistan" what does petName.substr[6,2] equal?

"st"

500

int x = 0;

int y = 2;

bool result = (x + 2 == y) || (y / x > 2);

True

500

int num = 13;

switch (num % 4) {

    case 0: cout << "Divisible by 4"; break;

    case 1: cout << "Remainder 1"; 

    case 2: cout << "Remainder 2"; break;

    default: cout << "Other";

}

Remainder1Remainder2

500

void update(int &x, int &y) {    

x = x + 5;    

y = y * 2;}

int main() {    

int a = 3, 

b = 4;    

cout << "Before: " << a << " " << b << endl; 

update(a, b);    

cout << "After: " << a << " " << b << endl;    return 0;

}

Before: 3 4

After: 8 8


500

What happens if you forget to return a value from a non-void function in C++?

Compile time error (or sometimes other unexpected behavior)