Download presentation
Presentation is loading. Please wait.
Published byClaude Foster Modified over 9 years ago
2
Computing with C# and the.NET Framework Chapter 3 Software Engineering with Control Structures
3
Figure 3.1 Java relational and equality operators Operator Symbol MeaningExample <less than31 < 25is false <=less than or equal to464 <= 7213is true >greater than-98 > -12is false >=greater than or equal to9 >= 99is false ==equal to9 == 12 + 12is false !=not equal to292 != 377is true
4
The if Statement Type bool Two values, true and false if (condition) if_true_statement The condition is a bool expression. If it is true then the if_true_statement will be executed if (x >2) y = x + 17;
5
Figure 3.2 The sequence control flow Entry int item1 = 25; int item2 = 12; Item2 = item1+15; Exit
6
Figure 3.3 Control flow for the if statement condition false if_true_statement true
7
Figure 3.4 Control Flow for Example 3.2 int hours = int.parse(Console.ReadLine()); Hour s >40 Console.WriteLine( “you worked {0} hours”, hours); False Console.WriteLine(“You “ + “worked overtime this week”) True
8
The if-else statement Choose between two alternatives if (condition)if ( x <= 20) if_true_statementx += 5;else if_false_statementx+=2;
9
Figure 3.5 Flow chart for the if-else statement Condition if_true_statementif_false_statement TrueFalse
10
Blocks Group a sequence of statements inside braces { x = 5; y = -8; z = x*y; } May use a block in an if or if-else statement
11
Figure 3.6 Flow chart for if statement with block, step 1 Z <= 10 True False x = 2; y = 7;
12
Figure 3.7 Flow chart if statement with block, step 2 Z <= 10 x = 2; True False y = 7;
13
Scientific Notation Small or large numbers are hard to read Use exponents instead 3.937E-8 instead of.00000003937 5.88E12 instead of 5,880,000,000,000 E or e E12 or E+12
14
Type double Provides about 16 decimal places double length = 173.24E5; // exponent double height 1.83; // fixed +,-,*,/ operators
15
Formatted Output {0:E} Scientific default (three decimal places) {0:F2} Fixed-point, two decimal places {O:G} General, default (same as {0}) Uses scientific notation if exponent is less than -4 or if the exponent is greater or equal to the number of significant digits in the number
16
Figure 3.8 Conversion of mixed-mode expression 2.54 Original expression After Conversion + + 361 361.0
17
while statement Provides repetition while (condition) while_true_statement while (x < 10) x += 2; If x = 5, then x becomes 7, 9 before loop stops while (x < 10) x -= 4; //does not terminate if x starts at 5
18
Figure 3.9 Flow chart for the while loop Condition while_true_statement FalseTrue
19
Figure 3.10 Pseudocode for the sum of test scores problem Read the quantity of scores; while(count < quantity) { Read the next score; Add the score to the total so far; Increment the count of scores; } Display the quantity and the total;
20
Debugging Read the code carefully to determine where the error might be located Add WriteLine statements to get more information Test thoroughly Use a debugger if available
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.