Download presentation
Presentation is loading. Please wait.
Published byDina Ferguson Modified over 9 years ago
1
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 7.1 Test-Driving the Wage Calculator Application 7.2 Algorithms 7.3 Pseudocode 7.4 Control Structures 7.5 if Selection Statement 7.6 if…else Selection Statement 7.7 Constructing the Wage Calculator Application 7.8 Assignment Operators 7.9 Formatting Text 7.10 Using the Debugger: The Watch Window 7.11 Wrap-Up Tutorial 7 – Wage Calculator Application Introducing Algorithms, Pseudocode and Program Control
2
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Objectives In this tutorial, you will learn to: –Understand basic problem-solving techniques. –Understand control structures. –Understand and create pseudocode. –Use the if and if…else selection statements to choose among alternative actions. –Use the assignment operators. –Use the debugger’s Watch window.
3
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 3 7.1 Test-Driving the Wage Calculator Application
4
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 4 7.1 Test-Driving the Wage Calculator Application Load the Wage Calculator application –Debug > Start –Notice the alignment of the TextBox es Figure 7.1 Wage Calculator application.
5
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 5 7.1 Test-Driving the Wage Calculator Application Initializing TextBox fields –Set Hourly wage: TextBox to 10 –Set Weekly hours: TextBox to 45 –Click Calculate Button Figure 7.2 Calculating wages by clicking the Calculate Button.
6
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 6 7.2 Algorithms An algorithm –Actions –Order in which the actions occur Program control
7
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 7 7.3 Pseudocode Pseudocode –Informal language Everyday English Describes only executable statements Not a programming language –Helps plan algorithms and programs
8
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 8 7.4 Control Structures Three control structures –Sequence structure –Selection structure –Repetition structure Activity diagram –Models the workflow
9
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 9 7.4 Control Structures Figure 7.3 Sequence structure activity diagram.
10
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 10 7.5 if Selection Statement
11
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 11 7.5 if Selection Statement
12
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 12 7.5 if Selection Statement Figure 7.6 if single-selection statement activity diagram.
13
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 13 7.6 if…else Selection Statement
14
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 14 7.6 if…else Selection Statement Figure 7.8 if…else double-selection statement activity diagram.
15
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 15 7.6 if…else Selection Statement Pseudocode for an application that displays a student’s grades. If student’s grade is greater than or equal to 90 Display “A” Else If student’s grade is greater than or equal to 80 Display “B” Else If student’s grade is greater than or equal to 70 Display “C” Else If student’s grade is greater than or equal to 60 Display “D” Else Display “F”
16
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 16 7.6 if…else Selection Statement C# code converted from pseudocode if ( intStudentGrade >= 90 ) { lblDisplay.Text = "A"; } else { if ( intStudentGrade >= 80 ) { lblDisplay.Text = "B"; } else { if ( intStudentGrade >= 70 ) { lblDisplay.Text = "C"; } else { if ( intStudentGrade >= 60 ) { lblDisplay.Text = "D"; } else { lblDisplay.Text = "F"; } } } }
17
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 17 7.6 if…else Selection Statement if…else statement using the else if structure. if ( intStudentGrade >= 90 ) { lblDisplay.Text = "A"; } else if ( intStudentGrade >= 80 ) { lblDisplay.Text = "B"; } else if ( intStudentGrade >= 70 ) { lblDisplay.Text = "C"; } else if ( intStudentGrade >= 60 ) { lblDisplay.Text = "D"; } else { lblDisplay.Text = "F"; }
18
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 18 7.7 Constructing the Wage Calculator Application
19
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 19 7.7 Constructing the Wage Calculator Application Generating the btnCalculate_Click event handler –Button calculates gross earnings
20
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 20 7.7 Constructing the Wage Calculator Application Figure 7.10 Calculate Button event handler. Generated event handler
21
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 21 7.7 Constructing the Wage Calculator Application Declaring variables –Primitive data types double decimal
22
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 22 7.7 Constructing the Wage Calculator Application Figure 7.11 Declaring variables of type double and d ecimal. Variable declarations
23
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 23 7.7 Constructing the Wage Calculator Application Declaring a constant variable –Keyword c onst –Value set at declaration and cannot be changed thereafter
24
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 24 7.7 Constructing the Wage Calculator Application Figure 7.12 Creating a constant. Constant declaration
25
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 25 7.7 Constructing the Wage Calculator Application Assigning data to variables –Double.Parse method –Decimal.Parse method
26
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 26 7.7 Constructing the Wage Calculator Application Figure 7.13 Assigning data to variables. Variable assignment
27
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 27 7.7 Constructing the Wage Calculator Application Determining wages –Use if…else statement Regular wage Time and half for overtime
28
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 28 7.7 Constructing the Wage Calculator Application Figure 7.14 i f…else statement to determine wages. Added if…else statement
29
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 29 7.7 Constructing the Wage Calculator Application Displaying output –Using Label ’s Text property
30
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 30 7.7 Constructing the Wage Calculator Application Figure 7.15 Assigning the result to lblEarningsResult. Displaying output
31
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 31 7.7 Constructing the Wage Calculator Application Figure 7.16 Running the application before formatting the output. Displaying output
32
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 32 7.8 Assignment Operators
33
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 33 7.8 Assignment Operators Using the assignment operator –Makes statement shorter
34
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 34 7.8 Assignment Operators Figure 7.18 Using the addition assignment operator in a calculation. Assignment operator shortens statement
35
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 35 7.9 Formatting Text Formatting output –Use Format specifier –Use C for currency
36
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 36 7.9 Formatting Text Figure 7.19 Using the Format method to display the result as currency. Formatting output as currency
37
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 37 7.9 Formatting Text
38
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 38 WageCalculator.cs (1 of 5)
39
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 39 WageCalculator.cs (2 of 5)
40
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 40 WageCalculator.cs (3 of 5)
41
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 41 WageCalculator.cs (4 of 5) Condition after keyword if Keyword const specifies constant else body executes when condition evaluates to false
42
Outline © Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 42 WageCalculator.cs (5 of 5) Format result as currency Assignment operator assigns left operand result of adding left and right operands
43
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 43 7.10 Using the Debugger: The Watch Window Using the debugger –Set breakpoints
44
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 44 7.10 Using the Debugger: The Watch Window Figure 7.22 Breakpoints added to Wage Calculator application.
45
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 45 7.10 Using the Debugger: The Watch Window Suspending program execution –Run the application –IDE switch to break mode –Active window changes Figure 7.23 Suspending program execution.
46
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 46 7.10 Using the Debugger: The Watch Window Examine data –Enabling the Watch window The Name column The Value column The Type column Figure 7.24 Watch window. Variable typesVariable values Variable names
47
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 47 7.10 Using the Debugger: The Watch Window Examining different expressions –Evaluating arithmetic expressions –bool expressions –Invalid expressions Figure 7.25 Examining expressions. Invalid expression bool expressionComplex expression
48
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 48 7.10 Using the Debugger: The Watch Window Deleting a watch Figure 7.26 Deleting a watch. Delete Watch option
49
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 49 7.10 Using the Debugger: The Watch Window Changes to the Watch window –Modified values displayed in red Figure 7.27 Modified values in Watch window. Modified value appears in red
50
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 50 7.10 Using the Debugger: The Watch Window Changing a variable’s value –Test various values to confirm behavior of the application Figure 7.28 Modifying values in a Watch window. Value modified directly
51
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 51 7.10 Using the Debugger: The Watch Window Noting the changes to the variable’s values –Allow the debugging process to continue Figure 7.29 Dialog to continue running application after changing values in the Watch window.
52
© Copyright 1992-2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 52 7.10 Using the Debugger: The Watch Window Notice the result from the debugging process Figure 7.32 Output displayed after the debugging process. Earnings result based on altered input
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.