Please answer each question fully, carefully and thoughtfully.
No credit will be given for unreadable answers, please write neatly.
Answer the questions in any order, but please number each answer.
Make sure that your name is on your test.
When ask to give code segments, you need not write an entire program.
If Statement
[2 points] Give the syntax for the if-else statement
[2 points] State the flow of control of the if-else statement
[2 points] Give the preferred use case for an if-else statement
[2 points] Critique the following code
int age;
cout << "Enter your age => "
cin >> age
if (age < DRIVING_AGE) {
cout << "You are not old enough to drive legally" << endl;
}
if (age >= DRIVING_AGE) {
cout << "You are old enough to drive legally." << endl;
}
elseif
[3 points] How can a programmer construct an if-then-else-if structure in C++? Give an example of the syntax.
[2 points] Why would a programmer employ an if-then-else-if structure over a switch statement?
Short Circuit Evaluation
[2 points] What is short circuit evaluation of boolean expressions?
[4 points] Give a short example of code where short circuit evaluation will occur. Explain your example.
While Statement
[2 points] Give the syntax for a while loop
[3 points] Give three conditions necessary to build a successful loop.
For Statement
[2 points] Give the syntax for the for statement.
[2 points] Give the flow of control for the for statement.
[2 points] Given a segment of code showing how a for statement can be implemented as a while statement.
String Functions
[2 points] Describe the operation of the string at member function.
[2 points] Describe the operation of the string find member function.
[4 points] Write a small code segment which will convert the letters in the string inputPhrase to all uppercase characters.
Testing
[2 points] What is black box testing?
[2 points] What is white box testing?
[2 points] What is a test plan?
Programming
[6 points] Write a code fragment, including variable definitions, which will ask the user for a number between 0 and 5 and print the name of that number. Ie if the input is 0, print the word "zero". If the user inputs a nuber outside of the range, print "invalid input".