Decision Making - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

Decision Making

Description:

Each check box has a Checked Property that is set to true if the box is checked ... Skateboarding 32 Temp =70. Skiing 0 Temp = 32. Interpretive Dance Temp = 0 ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 58
Provided by: annwi
Category:

less

Transcript and Presenter's Notes

Title: Decision Making


1
Decision Making
  • VB .NET Unit 3

2
If Statements
  • VB .NET Lesson 8

3
Conditional Operators
4
Using If Statements (One-Way Selection)
  • If (condition) Then
  • Statement(s)
  • End If

5
Using If Statements
  • Example
  • If (decBalance lt 0.0) Then
  • MsgBox(Account Overdrawn!)
  • End If

6
Flowchart Symbols
Input/ Output
7
Using IfElse Statements(Two-Way Selection)
  • If (condition) Then
  • True-Statement(s)
  • Else
  • False-Statement(s)
  • End If

8
Using ifElse Statements
  • If (intNumber gt 0) Then
  • MsgBox(Non-Negative)
  • Else
  • MsgBox(Negative)
  • End If

9
Overtime Pay Problem
  • Create a program to compute the weekly gross pay
    for a companys employees assuming
    time-and-a-half is to be paid for hours worked in
    excess of 40. The inputs to the program are hours
    worked and hourly rate of pay. The program should
    then output the employees gross pay.

10
Using Check Boxes
  • Each check box has a Checked Property that is
    set to true if the box is checked and false if
    the box is not checked. The label that appears
    next to the check box is part of the check box
    control. The check box has a text property that
    specifies its label. This property lets the user
    know if the box is checked (true) or not (false).
    Check box controls should have a chk prefix.

11
Setting the Default Checked Property
  • You use the checked property to set the default
    value of the check box.
  • Example
  • chkTall.Checked True
  • If (intHeight gt 72) Then
  • chkTall.Checked True
  • End If

12
Using Check Boxes Radio Buttons
13
Logical Operators
14
Career Suggestion Problem
  • Create a program to suggest a career based on an
    individuals personal traits. Call the program
    Career and label the form Career Suggestion. Have
    a Tall (over 72 inches) and a Heavy (over 250
    pounds) check boxes.

15
Use the following criteria
  • Tall and Heavy Policeman
  • Not Tall and Heavy Professional Wrestler
  • Tall and Not Heavy Basketball Player
  • Not Tall and Not Heavy Jockey
  • Display a label You can be a XXXXX! when a
    button labeled Career is pushed.

16
Nested If Statements and Radio Buttons
  • VB .NET Lesson 9

17
IF Structures
Two-way
One-way
18
Nested If Statement
  • An If statement in which one or more additional
    If statements follows one of the reserved words
    Then or Else of another If statement.

19
Nested If Structure
20
Using Nested If Statements
  • If (condition-1) Then
  • If (condition-2) Then
  • Statement(s)
  • Else
  • Statement(s)
  • End If
  • Else
  • Statement(s)
  • End If

21
Activity Selection Problem
  • Create a program that is designed to read in a
    temperature and print out the activity that is
    appropriate for that temperature using the
    following guidelines.
  • Activity Temperature
  • Surfing 85 lt Temp
  • Frisbee 70 lt Temp lt 85
  • Skateboarding 32 lt Temp lt 70
  • Skiing 0 lt Temp lt 32
  • Interpretive Dance Temp lt 0

22
Using Radio Buttons
  • Radio buttons always appear in groups, and only
    one button in the group can be selected at a
    time. Radio buttons are also called option
    buttons because they allow the user to select
    from several options.

23
Using Radio Buttons (Continued)
  • Three steps are involved in using radio buttons
  • Create a GroupBox to group the radio buttons.
  • Create the radio buttons in the GroupBox.
  • Write the code to use the radio buttons.

24
Implementing Radio Buttons
  • When you create radio buttons use the prefix opt.
  • Use form-level variables as the scope to keep
    track of the option that has been selected.
    Declare these variables under the heading Windows
    Form Designer generated code. Select the form,
    open the code window, and select (Declarations)
    from the Methods list.

25
Car Rental Cost Problem
  • Construct a program for determining the cost of
    a car rental. The number of days the car was
    rented and the miles that were driven are inputs
    to the program. The rental charges are as
    follows
  • Car Type Rent
  • Compact 25 a day
  • Midsize 30 a day 0.10 a mile
  • Luxury 35 a day 0.15 a mile
  • SUV 50 a day .20 a mile for all miles
    over 100

26
Select Case Structures
27
Using Select Case
  • The select case is another way to make
    multi-level decisions in a program. With Select
    Case you specify a variable to test and then list
    a number of cases for which you want to test.

28
Select Case Syntax
  • Select Case variable
  • Case 1 to 2
  • Statement(s)
  • Case 3 to 4
  • Statement(s)
  • .
  • .
  • Case Else
  • Default Statement
  • End Select

29
Quarter of the Month Problem
  • Write a program to read a month number 1 to 12
    and determine and print the yearly quarter the
    month falls into.

30
Loops, Multiple Forms, Menus, and Printing
  • VB .NET Unit 4

31
Do Loops
  • VB .NET Lesson 10

32
Loops (Iteration)
  • Three kinds of loops
  • For Next, Do While, and Do Until. In this lesson
    we will examine the Do Loop. All of these loops
    repeat a block of code statements a certain
    number of times.

33
Do While Loop
  • Do While condition
  • Statement(s)
  • Loop

34
Do Loop Example
  • intSum 0
  • intIndex 1
  • Do While intIndex lt 10
  • intSum intSum intIndex
  • intIndex intIndex 1
  • Loop

35
Inflation Problem
  • Create a program to determine the effect of
    inflation on the cost of an item. The program
    should input the current cost of an item, a
    yearly inflation rate, and the number of years
    the inflation rate is to be applied to the items
    cost. The program should then display the new
    cost of the item after it has inflated, at the
    given rate, for the specified number of years.

36
Do Until Loop
  • A Do Until Loop repeats until a condition is
    true. It is an exit controlled loop
  • Do
  • Statement(s)
  • Loop Until condition

37
Do Until Loop Example
  • intSum 0
  • intIndex 1
  • Do
  • intSum intSum intIndex intIndex
  • intIndex intIndex 1
  • Loop Until intSum gt 100

38
Prices to Double Problem
  • Construct a program that will input a yearly
    inflation rate and determine and display the
    number of years for prices to double given the
    inflation rate.

39
Using the InputBox Function
  • StrName InputBox(User Prompt, Title,
    Default Text)
  • Where User Prompt is a question displayed to the
    user, Title is the boxes title bar text, and
    Default Text is the users default response.

40
InputBox Example
  • strName InputBox(Where do you live?, Enter
    City, Fairfield)

41
Threshold Problem
  • Construct a program to input number until a
    threshold value has been reached. Use 1000 as the
    threshold value. Report the sum the caused the
    threshold to be reached and how many readings
    were entered.

42
  • End Visual Basic .Net

43
Demo 2 TipCalculator Problem Statement
  • Write a program that determines how much someone
    should tip in a restaurant. The following rules
    apply
  • The minimum tip is 1.00
  • Tip 20 if the bill is 20 or less
  • Tip 15 if the bill is more than 20
  • Tip an extra 1 if the service was especially
    good

44
Demo 2 TipCalculator IPO
45
Demo 2 TipCalculator Flowchart
A
Start
Get bill
Tip lt 1
Y
Tip 1
Meal gt 20
Tip .15 Bill
Y
N
Good service
Tip Tip 1
Y
N
Tip .20 Bill
N
Tip
A
End
46
Demo 2 TipCalculator User Interface
47
Demo 3 GradeCalculator Problem Statement
Write a program that assigns student grades based
on four test scores. The user enters the three
test scores and the program computes the total,
average, and letter grade for that user.
48
Demo 3 GradeCalculator IPO
49
Demo 3 GradeCalculator Flowchart
Start
Get test scores
A
Calculate Total
Total, average, grade
Calculate Average
End
Grade?
F lt60
A gt 90
C gt70
B gt80
D gt60
A
50
Demo 3 GradeCalculator User Interface
51
Exponentiation, Order of Operations, and Error
Handling
  • VB .NET Lesson 5

52
Data Types and Variables
  • VB .NET Lesson 6

53
Strings and Decimal Types
  • VB .NET Lesson 7

54
  • End of VB .NET Unit 3

55
Pre-built Functions
  • CDec convert to decimal
  • CInt convert to integer
  • CStr convert to string
  • decScore1 CDec(txtScore1.text)
  • lblGrade.text CStr(decTotalScore)
  • NOTE The textbook uses the VAL function. We will
    be using the Convert
  • Functions Instead of the VAL function. It is a
    more current way of doing
  • things and will work better with OPTION STRICT.

56
Importance of Data Types
Liftoff of Ariane 5 Rocket, June 4, 1996 CNN
Interactive, http//www.cnn.com/TECH/9710/30/arian
e.launch
57
New Controls
Write a Comment
User Comments (0)
About PowerShow.com