comp11 exam2 review 2

comp11 exam2 review 2 - Comp11 Exam Two 1. What are the four

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Comp11 Exam Two 1. What are the four increment/decrement operators? How are they different in both form and action? ++num, num++, num--, --num the num’s with the actor before are called prefix mode, meaning the number is incremented or decremented before it is displayed. In postfix mode, the number is displayed and then incremented or decremented. 2. What would it mean to write a while conditional “while (1)”? Will continue to loop infinitely, because 1 == true. ? Always true till exit or break loop. 3. What would one reason be for creating such a loop? ------- 4. Could you write a while loop that is guaranteed to terminate? Yes. If you allow the program to only iterate a certain number of times it will be guaranteed to terminate. 5. What is the difference between a do-while loop and a while loop? In what situations is each of them most applicable? A while loop is a pretest loop that iterates as long as the test expression is true. A do-while loop is a post test loop. It executes the statement atleast once. It is best when the data should be displayed atleast once – in the case of a menu for example. 6. When reading a file, can you name at least two ways to know when the end of the file is reached? Use inputfile.eof as a while condition so that it reads until the end of the program. The problem is that if there is no whitespace at the end it might not read the last character so better to use… If (Inputfile >> number) ( it is the stream extraction operator) that returns true if it successfully read of false if not. 7. What are the parts of the for statement and what does each one of them do to contribute to looping? Step 1: Preform initialization expression (num =1;)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Step 2: Evaluate test expression, if thrue go to step 3. Otherwise terminate loop. Step 3: Execute body of the loop Step 4: 8. If you have nested loops where the outer loop iterates from 1 to 5 and the inner loop iterates from 1 to 10, how many times does the most inner loop iterate? How about the outer loop? Why is this important to understand? Outer loop interates 5 times, and the inner loop iterates a total of 50 times (10 *
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 7

comp11 exam2 review 2 - Comp11 Exam Two 1. What are the four

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online