01092006

CHAPTER 4

We went over the handout which has the summarization of Fall 05.
These are the things I teach:

Visualization with JAVA, HTML & C++,
https://www.paypal.com/us/cgi-bin/webscr
Perl is a language which is similar to C, or C++. Most of the languages are C based language.

 

Add to the cart

cart = 0

while true

if selection then

currentselectionprice

and if

cart=cart+currentselectionprice
end while

below is the sample template for "add cart"

we are reading from the book chapter 4 and comparing from the

make sure you read every summary, every introduction and conclusion. Every chapter has case study which is your assignment.

my friend is a chess champ

CHAPTER 4

 

Decision Making: making programs intelligent

 

 

 

why is the chess champion lose the game. its because of IF statement. There is an example on top.

 

HOW DO YOU MAKE A DECISION IN Visual Basic .Net?

 

In Visual Basic, decision making is done by using an If ..switch…Then…Else or a Select Case statement. The If...then…Else statement uses the general form shown in Figure 4.1.

Text Box: If expression then
'body of if (runs only when the if expression is true)
Else 
'body of else (runs only when the if expression is false)
End If

 

 

 


 

 

 

Text Box: Figure 4.1 – The If…Then…Else structure of visual basic

 

The expression after the If must evaluate to either true or false. If the expression evaluates to true, the 'body of the if" which is after the word "then" will be executed.  If the expression evaluates to false, the "body of the else" will be executed which is after the word "else".

LOOK AT THE FOLLOWING IF STATEMENTS IN VISUAL BASIC

Text Box: If grosspay > 1000 Then 
taxrate = 0.20
Else 
taxrate = 0.10
End If

 

 

 

  Text Box: If hoursworked > 40  Then
overtimehours = hoursworked-40
Else
overtimehours=0.0
End If 
Text Box: Figure4.2a –Assign taxrate the value of 0.20 if grosspay is greater than 1000 otherwise assign taxrate the value of 0.10.

 

 

 

 

 

 

 

 

 

 Text Box: Figure 4.2b – Assign overtimehours the value of hoursworked – 40 if hoursworked is greater than 40 otherwise assign the value of 0.0 to overtime hours.
 

 

  Figure 4.3c—if value of candidateinitial is equal to H then increment the counter named 

  hc by the value of one (1) and assign the value back to hc. If the value of

  candidateinitial is anything other than H, then add one to the value of the counter named

  oc and assign the value back to oc.

 

WHAT DOES THE “If” EXPRESSION CONSIST OF?

 

The If expression usually compares two values using the comparison operators listed below in Table 4.1.

 

Common Value Comparisons of If Expression

 

 

equality        =

 

not equal                    <>

 

less than       <

 

Less than or equal        <=

 

greater than  >

 

 

greater than or equal   >=

 

 

 

 

 

 

 

 

 Text Box: Table 4.1 – Common comparison operators of the If expression.

 

The result of the expression can be either true or false. In VB anything beside zero is considered to be true.  Therefore, the number zero is false and any other number is true.  The expression if can be made more complex when making several evaluations or even an assignment statement.

Assignment page 100 Chapter 4

What is an algorithm?

 

Loop with a input control the following program will stop the loop when users cancel the input box.

Dim hw As Integer

Dim empid As String

Dim hr, gp, np, taxrate, taxamt As Single

empid = InputBox("EMPLOYEE ID")

While empid <> ""

hw = InputBox("Hours Worked")

hr = InputBox("Hourly Rate")

gp = hr * hw

MsgBox("Employee Id " & empid)

MsgBox("Hours Worked " & hw)

MsgBox("Hourly Rate is $" & hr)

MsgBox("Gross Pay is $" & gp)

If gp > 1000 Then

taxrate = 0.3

ElseIf gp > 800 Then

taxrate = 0.2

ElseIf gp > 500 Then

taxrate = 0.1

Else : taxrate = 0.0

End If

empid = InputBox("EMPLOYEE ID")

End While