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.
Selection
[2 points] Give the syntax for the if statement
[2 points] Describe the flow of control for the if statement
[2 points] Why is a code block commonly employed for the body of the if statement?
[4 points] Give a code segment which given the integer variables num and denom prints the decimal equivalent of num/denom if denom is non-zero and error otherwise.
Loops
[2 points] Give the syntax for the while statement.
[2 points] State the flow of control for the while statement.
[2 points] What is an infinite loop?
[4 points] Give a code segment which will print out the even
integers between 4 and 23.
For statement
[2 points] Describe the steps that should be taken to
avoid an infinite loop.
[2 points] Give the syntax for the for statement.
[2 points] Give the flow of control for the for statement.
[2 points] Describe when a programmer would employ the do ... while statement.
[2 points] Describe the action of the stream extraction operator when reading an integer value.
[10 points] The file numbers.dat contains 10 integers. Write a complete program which will find the sum, average, and maximum value of the integers in the file.
[10 points] The file story.txt contains the text of a story. The story ends with the word END-OF-STORY. Write a program which will determine the number of words with 1-4, 5-8, 9-12, and 13+ letters. Your program should print the following table:
Word Size Count Percent
1-4 100 0.33
5-8 150 0.50
9-12 30 0.10
13 and up 20 0.07