CMSC 140 Final Exam Review Part 1
What will be the result of the expression 7 / 2 ?
3
What will be the result of the expression 7.0/2
3.5
What must you use in the variable name when you create a reference variable?
A ampersand (&) before the name in the function header and after the data type declaration in the function
What is a reference variable?
A reference variable is a variable that, used as a function parameter, can be changed within the function.
Posttest
Evaluate its expression after the loop executes once.
Pretest
Evaluate its expression before the loop executes once.
What are the three parts of a for loop definition called?
Initialization, test, and update
When used as function parameters, how do reference variables differ from normal parameters?
Reference variables are unlike normal variables, which any changes in a function to the variable will not remain outside the function.
What operator is used in C++ to represent division?
The / operator is used to represent division in C++.
What will be the data type of the result of division between two integers?
The data type will be an integer.
What loops are posttest?
do-while loop
What do the following statements evaluate to, given the defined variables? string name1 = "John", name2 = "Jane", name3 = "Devin", name4 = "John "; name1 < name2; name2 > "Janet"; name3 != "devin"; name3 < "DEVIN"; name1 == name4;
false, false, true, false, false
Create the code below to open a file named 'testing123.txt' for writing. Save the values 1, 2, 20, and 37 into the file. Each value should be on its own line inside the file. Then close the file.
ofstream outputFile; outputFile.open("testing123.txt"); outputFile << 1 << endl; outputFile << 2 << endl; outputFile << 20 << endl; outputFile << 37 << endl; outputFile.close();
What will the variables 'someNum', 'anotherNum', 'lastNum', and 'aBool' contain after the execution of the following code?: int someNum = 2, anotherNum = 3, lastNum = 1; bool aBool; aBool = !(++someNum > (--anotherNum * lastNum++));
someNum = 3, anotherNum = 2, and lastNum = 2
What will be displayed on the screen after the execution of the following code? int counter = 0; bool moreThan20 = false; while (!moreThan20) { if (counter != 6) { cout << counter << endl; } if (counter == 14) { cout << "...Getting close..." << endl; } else if (counter == 18) { cout << "...Almost there..." << endl; } if (counter > 20) { cout << "...It's over twenty..." << endl; moreThan20 = true; } counter += 2; }
2 4 6 8 10 12 14 ...Getting close... 16 18 ...Almost there... 20 22 ...It's over twenty...
Postfix Mode
The value is incremented after used in any expression in the same statement.
Prefix Mode
The value is incremented before used in any expression in the same statement.
What does it mean to decrement something? What operator is used in C++ to do this?
To decrement something is to decrease its value by 1. The operator in C++ is the -- (minus-minus) operator.
What does it mean to find the modulus of something? What operator is used in C++ to do this?
To find the remainder after the division of two numbers. The operator % is used in C++
What does it mean to increment something? What operator is used in C++ to do this?
To increment something is to increase its value by 1. The operator in C++ is the ++ (plus-plus) operator.
Name the three different types of loops
While Loop, do-while loop, and for loops
What loops are pretest?
while loop and for loop
Given the function definition below, what will the value of 'x' and 'y' be after the code executes below? nt x = 10, y = 2; refVarFunc(x, y); void refVarFunc(int &num1, int num2) { for (int i = 0; i < 5; i++) { num1++; num2 += 2; } }
x = 15 and y = 2