Chapter 7&8
Chapter 7&8
Computer Science
Department
Institute of International
Professionalism
Program Development
Life Cycle
• Analysis
abstraction, decomposition of the problem,
identification of the problem and requirements
• Design
decomposition, structure diagrams, flowcharts,
pseudocode
• Coding
writing program code and iterative testing
• Testing
testing program code with the use of test data
Variable and a Constant
Meaningful Names
•The name should describe exactly the type of data stored
in it.
Example
count = 0
student_name = “ ”
Const ticket_price=25
Use Suitable Declaration
Variables
•Use either camel casing (without any white space, 1st letter is lower
and every word starts with a capital letter [fileNotFound]) or snake
casing (uses an underscore between words to create separation
[build_docker])
Use Suitable Declaration
Constants
• Use “Const” at the start of the name
• Capitalise name
• Use either camel casing or snake casing
Camel
ConstTICKETPRICE = 25
Snake
Const_TICKET_PRICE = 25
Use Suitable Declaration
Array
• Can be either a specified or unspecified length
• Always use the square brakets
No length given
totalPrice= [ ]
Length declared
home_start_code = [0:4]
Data
type
Mathematical operators
Comparison Operators
Operators Description
== equal to
!= , <> not equal
> greater than
< less than
>= greater than or equal to
<= less than or equal to
Logical Operators
Operators Description
&& And
|| Or
ALGORITHMS
An algorithm is a set of
instructions/steps/ rules that are
followed to solve a problem.
Algorithm design
1.Pseudocode
2.Flowcharts.
Pseudocode
PSEUDOCODE is a method of expressing an
algorithm design.
Pseudocode is lines of instructions written in a
language close to English but with common
programming terms used where possible (selection
and iteration etc).
Pseudocode is set out with the same structure as a
programming language, but it is not a not
programming language in itself.
Pseudocode
E.g:
Output “How many number”
Input userinput
Number=number+1
Selection or Conditional
statements
Creati ng the ability to choose the path to
follow in a program is called selecti on.
When different actions are preformed by an
algorithm according to the values of the
variables, conditional statements can be used to
decide which action should be taken.
Library
a store of pre-programmed instructions that can be
imported into a program
(print, cout, cin)
Predefined Procedures
a pre-programmed set of instructions that do not
return a value.
(clear the screen command)
Example of Function
Counting and
Totalling
Counting
Counting is used with repetition with the
counter increased by 1 every time the loop
is repeated.
Totalling
Totalling is used with repetition with the
total updated every time the loop is
repeated.
Global and Local
Variables
• A global variable can be used by any part of a
program – its scope covers the whole program.
• A local variable can only be used by the part of the
program it has been declared in – its scope is
restricted to that part of the program.
Arrays
An array is a data structure containing
several elements of the same data type;
these elements can be accessed using
the same identifier name.
An array is a way of storing data that is
all related and of the same type.
e.g: a list of the names of the students in
your class
An array is a data structure, storing
more than one item of data (value) at a
time
Allows to store an unlimited number of
Arrays
An Element is an individual data location in an
array.
Each of the individual items in an array is called an
element.
The index indicates the position of the element
within the array
The dimension of an array is the number of indices
needed to select an element.
0 1 2 3 4
Score[4]
0 1 2 3 4
Syntax Error
Syntax Error occurs when a programmer
does not follow the rules or structure of
the language they are writing in.
Logic Error
A logic error is an error in the code that
causes the program to do something it
should not.
Testing
Testing is the process of finding and
removing errors from your code.
removing syntax errors is easy to spot as
your interpreter
Finding Logical errors can be a lot
trickier and can end up being a very
time consuming process.
Example of Test
Data
A system has validation to ensure that only
numerical values between 1 and 10 are entered
as an input.
Checks the data falls between an acceptable upper and lower value,
Range check
within a set range. E.g: number will be 1 to 5
Checks that the data entered is of an expected type, e.g. text or a number
Type check
Email address, ID Number
Checks that the user has at least inputted something, stopping them from
Presence check
accidentally entering nothing
Double entry Data is entered twice and the computer checks that they match up.
Eg:
Enter password:
Re enter password:
The user manually reads and compares the newly inputted data
Visual check
against the original source to ensure they match