Chapter 5: Loops and Files

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Whats the difference between prefix and postfix In/decrementors?

As prefix, it increments or decrements, then returns the value of the variable. As a postfix, the operator returns the value of th\e variable, then increments or decrements.

Describe the while loop.

Pretest loop. Can be used for input validation. The statement is executed as long as expression is true. The loop must contain a code to make the expression become false or the loop will never stop and become an infinite loop.

Describe the for loop.

Pretest loop. Useful for counter-controlled loop. Useful when initialization is required.

What's the difference between a while loop, do-while loop, and a for loop?

While loop is a conditional pretest, keeps going as long as a certain condition is true, used to validate input and reading lists of data terminated by a sentinel. The do while is a conditional posttest loop that runs at least once and is good for repeating a menu. The for loop is a pretest loop that has built in expressions for initializing, testing, and updating. Good for situations where the exact number of iterations is known.

What is needed to use files?

the header file - fstream - for file access ifstream for input from a file ofstream for output to a file fstream for input or output to or from a file

Increment and Decrement

++ adds one to a variable -- subtracts one from a variable They can be used as a prefix and a postfix

What is a sentinel?

A value in a list of values that indicates end of data. They are special values that cannot be confused for valid value. Used to terminate input when user may not know how many values will be entered.

What is an accumulator?

A variable that hold a running total.

What is a counter?

A variable that is incremented or decremented each time a loop repeats. Used to control execution of a loop. Must be initialized before entering loop

What is a loop?

A control structure that causes a statement to repeat.

What is a nested loop?

A loop inside the body of another loop.

Describe the do-while loop.

A posttest loop (executes the loop then test the expression). Checks and does the statement before checking if the while is true. Useful in menu-driven programs.

What is a running total?

A running total is the accumulated sums of numbers from each repetition of loop.


Set pelajaran terkait

Ch 89 Urinary and Renal Disorders Saunders 122 questions

View Set

Principles of Marketing (ch. 10-14) Study Plan

View Set

Ch. 21 Starting a Business: LCCs and Other Options

View Set

Ch6 Health Insurance Underwriting

View Set