This file has some practice questions that are similar to those you'll have on the second exam. ** On paper ** 1. Keep track of the values variables get and functions that are running given some code. Examples #include #include using namespace std; void printLogarithm (double x) { if (x <= 0.0) { cout << "Positive numbers only, please." << endl; return; } double result = log (x); cout << "The log of x is " << result; } void countdown (int n) { if (n == 0) { cout << "Blastoff!" << endl; } else { cout << n << endl; countdown (n-1); } } int main () { countdown (3); return 0; } //--------------------------------- int i; int val; for(i=0;i<5;i++) { val = val * val; cout << i << "\t" << val << endl; } //---------------------------------- morefun.cpp //---------------------------------- void printMultiples (int n) { int i; for(i=1; i<= 4; i++) { cout << n*i << " "; } cout << endl; } int main() { int j; for(j=1; j <= 3; j++) { printMultiples(j); } return 0; } //----------------------------- 2. Some questions about algorithms. Study the algorithms... * Use the algorithm to solve the problem, show your work. * Algorithms to know: selection sort, binary/hexadecimal/decimal conversion, determining if a number is prime, caesar encryption/decryption * Example: determine if each of the following numbers is prime; if it is prime your work should demonstrate that it is prime. 31, 33, 35, 37 * Example: convert 11001100 to hexadecimal and to decimal. * Example: Encrypt the message "good" using a caesar cipher that shifts each letter by 4. Decrypt the encoded message "qepq" using a caesar cipher that shifted each letter by 23 to get the encoded message. Your decoded message will be a normal english word. * Example: Show selection sort sorts the following list of numbers 3, 1, 7, 2, 8, 0, 4 ** On computer ** 1. Create a program from scratch to do something relatively simple. Examples * Add up the multiples of 33 up to 1000 and print the result. * Ask the user to type in 10 strings and count how many were 4 letter words. 2. Take a program that has some syntax error in it, and fix the syntax error. Examples * exam2wordcount.cpp has several syntax errors. * exam2arrayExample.cpp also has several syntax errors. * exam2caesarBetter.cpp also has several syntax errors. 3. Take a program that has some logical error in it, and fix the logical error. Examples * exam2caesar.cpp has a logical error. * exam2triangle.cpp has a logical error. * exam2multiples.cpp has a logical error.