İnfografik
Ana Sayfa » Ankara Üniversitesi ANKADEM » Mühendislik Fakültesi » Introduction to Computer Programming
← Ünite 4
Introduction to Computer Programming

Ünite 4: Structured Program (4)

Counter-Controlled Grade Average Example
In Figure 2.7 of the C++ program text, a counter-controlled loop processes exactly 10 user-entered grades (98, 76, 71, 87, 83, 90, 57, 79, 82, 94) and calculates a final integer average of 81.
Sentinel-Controlled Grade Average Example
In Figure 2.9, a sentinel-controlled loop processes an unknown number of grades until the user inputs '-1'. The entered grades (75, 94, 97, 88, 70, 64, 83, 89) yield a floating-point average of 82.50.
Stream Manipulators for Precision
The program uses header '<iomanip>' alongside stream manipulators 'setprecision(2)' and 'fixed' to display floating-point average results with exactly two digits of decimal precision.
Examination Results Analysis Program
Figure 2.11 illustrates a nested control structure where 10 student exam results are categorized using codes 1 for pass and 2 for fail, tracking student counts and deciding whether to output 'Raise tuition'.

Anahtar Kavramlar

Repetition StructureA control construct used in programming to execute a set of actions repeatedly while a specified condition remains true. For example, a while loop repeatedly executes a block of code as long as the loop condition evaluates to true.
Counter-Controlled RepetitionA repetition technique used when the exact number of loop iterations is known in advance. It employs a loop control variable that is initialized, tested, and incremented during each iteration, such as processing exactly 10 student grades.
Sentinel-Controlled RepetitionA repetition technique used when the number of data items is unknown beforehand, utilizing a special input value called a sentinel to signal the end of data entry. For instance, using '-1' to stop a grade-entering loop.
Sentinel ValueA specific dummy or flag value used in sentinel-controlled repetition to indicate that no more data is to be processed. In the class average example, entering '-1' acts as the sentinel to terminate the input loop.
Top-Down, Stepwise RefinementAn algorithmic design methodology where a problem is broken down into manageable phases—typically initialization, processing, and termination—and progressively detailed into executable code.
Nested Control StructuresControl statements placed inside other control statements, such as an if/else selection statement nested inside a while repetition statement to analyze examination results for multiple students.
Assignment OperatorsShorthand operators in C++ that combine an arithmetic operation with assignment, such as 'a += 5', which is equivalent to writing 'a = a + 5'.
Increment OperatorAn operator denoted by '++' used to increase a variable's value by 1, serving as a shorthand alternative to expressions like 'c = c + 1'.
Decrement OperatorAn operator denoted by '--' used to decrease a variable's value by 1, serving as a shorthand alternative to expressions like 'c = c - 1'.
Postincrement OperatorAn increment operation (written as 'c++') where the variable's current value is used in the expression before the variable itself is incremented.
Preincrement OperatorAn increment operation (written as '++c') where the variable is incremented first, and then the new value is used in the surrounding expression.

Diğer Önemli Bilgiler

Tuition Increase Threshold

In the examination analysis program, if more than eight students pass out of the ten evaluated (passes > 8), the program automatically prints the message 'Raise tuition'.

Assignment Operator Equivalency

C++ allows shorthand notations such as 'a += 5' to replace 'a = a + 5', 'a -= 5' for 'a = a - 5', and corresponding operators for multiplication, division, and modulus operations.

Preincrement Demonstration Output

When demonstrating preincrementing in Figure 2.14, assigning 'c = 5' and executing '++c' increments the variable to 6 first, resulting in the output sequence of 5, then 6, then 6.

Postincrement Demonstration Output

When demonstrating postincrementing in Figure 2.14, executing 'c++' prints the current value of 5 first before incrementing 'c', resulting in the output sequence of 5, then 5, then 6.

Sınavda Dikkat Et

  • Pay close attention to loop termination conditions to avoid infinite loops in while statements.
  • Remember that sentinel-controlled loops require priming reads (getting the first input before the loop starts).
  • Distinguish clearly between counter-controlled repetition (known iterations) and sentinel-controlled repetition (unknown data size).
  • Understand the exact syntax and order of evaluation for preincrement (++c) versus postincrement (c++) operators.
  • Note that integer division truncates fractional parts, so static_cast is necessary for accurate decimal averages.
  • Keep in mind that header <iomanip> is required when using stream manipulators like setprecision and fixed.
  • Examine nested control structure examples carefully, ensuring inner if/else statements properly align with outer loop execution.