Chapter 10 Pseudo code and Flowcharts

Pseudo Code is a very easy way to write algorithms. It is a very simple way of checking if your program works, we call that a dry run.

Atomic Type names:

  • INTEGER – A whole number
  • REAL – A number capable of containing a fractional part
  • CHAR – A single character
  • STRING – A sequence of zero or more characters
  • BOOLEAN – The logical values are TRUE and FALSE

Literals:

Integers : Written as normal in the denary system, e.g. 5, -3

  • Real : Always written with at least one digit on either side of the decimal point, zeros being added if

necessary, e.g. 4.7, 0.3, -4.0, 0.0

  • Char: A single character delimited by single quotes, e.g. ꞌxꞌ, ꞌCꞌ, ꞌ@ꞌ
  • String: Delimited by double quotes. A string may contain no characters (i.e. the empty string) e.g.

“This is a string”, “”

  • Boolean: TRUE, FALSE

Functions:

 <– Assignment
  • – * /
Operators for mathematical equations
^ Raise to the power
() group
IF THEN ELSE END IF Limited conditional statement consisting only of two answers
CASE OF OTHERWISE ENDCASE Unlimited conditional statement which forces otherwise if an option isn’t chosen
FOR TO NEXT Limited number of repetitions
REPEAT UNTIL Unknown number of of repeats but must be run at least once
WHILE DO ENDWHILE An endless loop that can continue forever
INPUT/READ Prompts user to enter data
OUTPUT/PRINT Outputs data
< > = >= <= Comparison operators
<> Not equal to (comparison operator)
() Group
AND More than one statement or condition
OR Either input or output to be written/read
NOT neither input or output to be read
“” Speech Marks need to be used around data items
// This is used comment against functions

Rules:

  • Functions must all be written in uppercase
  • Data items or sub routines i.e. counter must be written in camelcase
  • Conditional, loop statements, repeated or selected statements must be indented.
  • Indentation must be removed when a loop or condition finishes

Examples:

Example 1:
IF Age < 18 //This is if age is lower than 18
THEN PRINT “Child” // if age is lower than 18, it will print child
ELSE PRINT “Adult” // otherwise it will print adult
ENDIF //end the code

Example 2:
CASE Grade OF // this is a function set for grades
“A” : PRINT “Excellent” //if you got an A, it will print excellent
“B” : PRINT “Good” // if you got a B, it will print good
“C” : PRINT “Average” //if you got a C, it wil print average
OTHERWISE PRINT “Imporovement is needed” //if you got lower, it will print improvement needed
ENDCASE //ends the funtion

My sample code:

racecar<– Nascar

cost <–20

price <– 10*cost

fuel <– price*1.5

driver<–50

totalmoney <–fuel + driver

discount <–0.3

finalprice<–

Activity 10.2:

activity-10-2

A dry run enables a programmer of the designer of the program to walk through the process and functions of a program in theory
A trace table enables a programmer or the designers of the program to identify normal, boundary and abnormal values and identify the execution of the program

Activity 10.6

act 10.6.PNG

  • Start/stop – act as a beginning or ending of a sequence

start

  • Process – an instruction or command

process

  • Decision – either yes or no

decision

  • Input/output – input is data received from a computer. An output is a signal or data sent from the computer

input

  • Connector – a jump from one point of the sequence to another

connector

  • Direction of flow – connects the symbols within the flowchart. Arrow shows the direction of flow of instructions

direction

my pre release code

*sorry for bad picture quality*

The page number is written on the side of the page in the image

IMG_0917IMG_0919IMG_0920

 

Advertisements