dry run
Download
Skip this Video
Download Presentation
Dry Run

Loading in 2 Seconds...

play fullscreen
1 / 15

Dry Run - PowerPoint PPT Presentation


  • 106 Views
  • Uploaded on

Dry Run. You can test your program without using a computer by dry running it on paper You act as the computer – following the instructions of the program, recording the valves of the variables at each stage You can do this with a table . Dry Run.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Dry Run' - robyn


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
dry run
Dry Run
  • You can test your program without using a computer by dry running it on paper
  • You act as the computer – following the instructions of the program, recording the valves of the variables at each stage
  • You can do this with a table
dry run1
Dry Run
  • The table with have column headed with the names of the variables in the program
  • Each row in the table will be labelled with a line number form the program.
  • The entries of each row in th e table will be values of the variables after the execution of the statement on that line
  • You don’t need a row for every line in the program, just those lines where some significant change to the state of the program occurs e.g a variable gets a new value
dry run2
Dry Run
  • In this table you can record all relevant changes to the variables as the program progresses, thereby test the logic of the program / algorithm
  • Do a dry run before you code your program on computer this way any logic errors will come to light during the dry run
example of a dry run
Example of a Dry run
  • L1 Declare two variables , first num second num
  • L2 Initialise both variables to 0
  • L3 first num = 0 second num = 0
  • L4 Ask user to enter first number
  • L5 Assign user input to first num variable
  • L6 Ask user to enter second number
  • L7 Assign user input to second num variable
  • L8 Add first num to second num
  • L9 Print result
  • Do a Dry run for this program assuming the user enters 17 for first number and 24 for the second
relational operators
Relational Operators
  • Give examples
  • < less than
  • > greater than
  • <= Less than or equal to a<=b
  • >= greater than or equal c>=d
  • == equals
  • != not equals 5!=6
  • Boolean expression – TRUE or FALSE
if then else statements
If then Else statements
  • If <TEST>
  • <STATEMENT 1 >
  • Else
  • <STATEMENT 2 >
  • <TEST> is a boolean expression
  • Is <TEST? Has a false valve then <STATEMENT 2 > is executed
  • Is <TEST? Has a false valve then <STATEMENT 1 > is executed
  • Note the indentation – this makes it easier to read
nesting layout
Nesting Layout

If (mark > 69)

grade = “A”

Else

If (mark > 59)

grade = “B”

Else

If (mark > 49)

grade = “C”

Else

If (mark > 39)

grade = “D”

Else

grade = ‘F’

In this alternative the psuedo

code crawls across

  • To make your algorithm easier to read nest the statements

If (mark > 69)

grade = “A”

Else If (mark > 59)

grade = “B”

Else If (mark > 49)

grade = “C”

Else If (mark > 39)

grade = “D”

Else

grade = ‘F’

nesting of if else and while loops
Nesting of if-else and while loops

Int number

Number =3

For loop : 1 to 3

if number = 1

print ‘red’

else

if number = 2

print ‘green’

else

if number = 3

print ‘yellow’

endif

Loop end

more complex loop tests
More Complex Loop Tests
  • Sometimes we may want to allow the user to terminate the program/loop
  • We can do this by prompting the user with a question e.g imagine a user is entering a series of numbers which will be added to together, like student marks. We can ask the user the question (Do you want to add another student mark? )
  • We assign the user response to a variable named e.g. continue

Declare variable continue

Initialise the variable Continue = ‘X’

Ask the user (Do you want to add another student mark? )

Assign/store the user response to variable continue

Continue := user response

While (continue = ‘Y’)

Loop Body…

more complex loop tests1
More Complex Loop Tests
  • Sometimes you may want to include more than one condition in your loop tests
  • In such cases you can use boolean connectives (&& and ||)
  • E.g.
  • while (continue = ‘y’) && (item number < 10)
  • Where item number = number of items to be added
problem solving
Problem solving
  • Understanding the problem
  • The plan – decide how to tackle problem - algorithms
  • Test and Evaluate – dry run and test plans
test plans
Test Plans
  • Do before you code!
  • Do a test plan for every branch test e.g. if the else and loop statements
  • Extreme values such as 0 or negative numbers are tested in addition to ‘normal’ values. Testing the bounds is most efficient way for testing for run time errors
slide14
The following psuedo code / algorithm prints the larger of two numbers
  • Do a test plan to find it – a series of valves to be input in variables first and second .Run the program several times

Int first

Int second

Int max

Sring str

Prompt user to enter an integer (please enter a number)

Store the number into variable first

Prompt user to enter a second integer (please enter a second number)

Store the second number into variable second

Max = first

if (second > max)

max = second

Print message to screen saying (larger of the two numbers is max)

ad