Professional Documents
Culture Documents
Mod 1.
Mod 1.
Mod 1.
What is an Algorithm:
- An algorithm is a step by step procedure for solving a problem.
- It is a description of the processing steps necessary to transform inputs into outputs
infinite time.
- E.g a recipe
- Think of an algorithm as a plan for a piece of software.
Pseudocode:
English like sentences describe each step in the algorithm
Eg. BEGIN Add2Numbers
Get firstNumber
Get secondNumber
total=firstNumber + secondNumber
Display “The sum of your two numbers is” total
END Add2Numbers
P.
Pseudocode example
BEGIN MAINPROGRAM
Total = random_number between 1 and 100
loop flag = true
WHILE loopflag
Print out total
Number = user input
Total = total - number
IF total <=0 THEN
loopflag = false
ENDIF
ENDWHILE
Print “Game Over”
End Main program
Flowcharts:
- A graphical method of representing an algorithm.
- Flow from top to the bottom of the page
- Each flowchart should be about one page each
Process
Start/End
Decision
Output/Input
In theory, all problems can be solved using just the four control structures.
eg
Create a pseudocode and flowchart algorithm that prompts a user to enter two numbers Num1
and Num2, displays them, swap their values, and displays them.
BEGIN MAIN PROGRAM NumberSwap
Get Num1
Get Num2
Display Num1 and Num2
Temp=num2
Num2=Num1
Temp=Num1
Display Num1 and Num2
END MAIN PROGRAM NumberSwap
Process 1
Process 2
……….
ENDIF
More instruction
……………….
__ = Operand
__ = Relational operand
= Equal to
≠ Not equal to
<Less than
<Less than or equal to
>Greater than
>Greater than or equal to
EG.
BEGINMAINPROGRAM RideChecker
Get Age from user
If (Age<16 NO ride)
If (Age >16 Welcome to ghost train)
Print Thankyou message
END MAINPROGRAM
Complex Conditions
● These are constructed using logical operators
○ AND (All conditions need to be true)
○ OR (Either of the conditions are true)
○ NOT (Neither conditions are true)
● EXAMPLE
○ If (Age < 16) AND (Height >120 cm) THEN
● EXAMPLE
○ eof=False
○ IF NOT eof THEN………………
Multiway Selection:
An alternative to using multiple binary selection statements
More than two alternative parts
The first choice that equates to true.
Basically IF with Elif and else.
Example of pseudocode
……………………………..
CASEWHERE Expression is
Choice A: Process 1
Choice B: Process 2
………………………………..
OTHERWISE: Default Process
ENDCASE
a. Flowchart algorithm:
ENDCASE
END MAIN PROGRAM
- Repetition: repeating blocks of code
- iterating or looping code.
- repeating a sequence of steps.
Two types of loops use a condition
- Pre test loop- the condition is laced at the start of the loop.
- Post test loop, the condition is placed at the end of the loop.
The process within the loop structure are known as the body of the loop
The loop body is repeated while ever he condition holds true.
ENDWHILE
ENDIF
END MAIN PROGRAM
Pseudocode:
………………
REPEAT:
Process1
Process2
…………….
Processn
UNTIL condition
Process
…………………
Repetition:
The body of the loop is to be repeated a fixed number of times, OR
Repetition is to occur while a sentry value increments between within the limits of two values
E.g. We wish a variable to take the values 1, 2 ,3, 4...100
Increments:
It is possible to alter the magnitude of each increment (or step)
Example sequences:
2,4,6,8
10 ,9 ,8, 7...
OR -1, -0.5, 0, 0.5, 1, 1.5, 2
Keywords:
FOR……..(STEP).......NEXT
FOR……..(STEP)......ENDFOR
Pseudocode syntax
FOR loopcounter = initial value TO final value BY stepvalue
Process
Process
………………………..
ENDFOR
Flowcharts:
These are just while loops
Tasks:
Develop a pseudocode algorithm that displays the first ten multiples of 3
Develop a flowchart algorithm which outputs the following:
-100, -95, -90, -85, …, 0
PSEUDOCODE
BEGIN MAINPROGRAM BY 3
FOR loopcounter = 3 TO 30 BY 3
Display the value loopcounter
………………………………….
NEXT loopcounter
Subprograms:
Aka subroutines or modjules
Self contained fragments of algorithm code
They are incorporated into a admin algorithm
Top/down designs
● Subprograms are a consequence of developing solutions using the top down design
approach
● The highest level of algorithm code is known as the main program or mainline
Subprograms in pseudocode
● In the mainline a call to a subprogram is indicated by the underlined name of the
subprogram
● To call a subprogram means to transfer execution to the subprogram
Pseudocode Keywords
● BEGIN SUBPROGRAM
● END SUBPROGRAM
Modularity:
- Many subprograms are stored separately
- Usually in a code library (sometimes called dynamic link library)
- The subprograms are called modules
- Modularity refers to the process of creating reusable code modules
- A module can contain one or many subprograms
- Subprograms can be stored in a code module have to have complete, self contained
blocks of code, independent of the calling code.
Writing Software:
● First step - write the mainline:
○ Include calls to required code modules
○ Try to avoid too many selections or repetitions in the mainline
○ Include calls to code modules where necessary
○ Stubs are written in place of the complete modules
○ Stubs are empty subprograms or perform simple commands like a print
statement are least to begin with
○ Code for the modules are developed separately
○ When the module is complete it replaces the stub
Parameters:
● Provide data to the sub programs (modules)
● Return data to the mainline
● Are an interface between the module of code and the mainline
● Data is passed via parameters to the subroutines during calling
● A key factor that enables reuse of code module
Modularity
● A software module*(subprogram) can
○ Call other lower level modules and
○ Pass values to the lower level modules using parameters
● The order of the parameters is important
○ It determines how they are mapped to the formal parameters in the subroutine
● We should aim to develop software with
- a clear uncluttered mainline
- Independent subprograms
As long as a subprogram is independent it can be reused in other applications or the same
program.
Pseudocode:
BEGIN SUBPROGRAM DigitalRoot
Input num value
WHILE num>=10:
Set num=SumDigits(num)
ENDWHILE
Display num
END SUBPROGRAM
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ergonomics:
- The study of the relationship between people and their work environment
- Our emphasis - ergonomics & software design
Aims:
To create a work environment/experience that caters to:
- Physical
- Emotional and
- Psychological needs
Ergonomic are highly productive
- Produce better quality products
- Better morale
Types:
Repetitive Strain Injury
- Cause: repetition of the same movement
- Can occur in any part of the body
- Computer users - mainly the wrist, arm, hand and fingers
Treatments
● Wrist and hand braces
○ Wrist kept in a straight position
○ Allows ten
○ don to move freely
● Anti inflammatory drugs eg Aspirin, Cortisone injection into the carpal tunnel
● Surgery (extreme cases)
○ Cut the transverse carpal ligament
○ Larger carpal tunnel
● Workplaces with poor ergonomic practices
○ Increased costs =>workers compensation
○ Lower/lost productivity
○ Staff absenteeism
To avoid injury:
- Variety: Do different things and avoid repetitive tasks
- Autonomy: Allow people to help make the decisions. Employee decides the order of task
completion
- Identity: Tasks should be complete jobs and provide a feeling of accomplishment
- Feedback: Effective communication between workers and management
- Social contact: With co workers
- Achievement: Employees feel contribution is valued
- Training: formal and informal and must be on-going
- Job Demand: too much/little work causes stress. Must be a balance
Monitor:
- Height adjustable
- Larger the monitor use highest resolution
- Should be about an arms rest away
- Characters should be easily readable from an arms length away.
- Glare (artificial or natural light) can cause irritation. Monitors should be perpendicular to
light sources. Screen filters.
Keyboards:
- Detachable
- Forearms parallel to the floor
- Dished keys
- Matt finish to reduce glare
- Numeric keypad for extensive numeric entry.
Mouse:
- Fits the hand
- Same Level as the keyboard
- Use an armrest
- Rest the finger on the button ( not “held” above the button)
- Straight wrist
- Mid range speed
- Dragging kept to minimum
- New designs - use the thumb to operate the primary button
Copyholders:
- Users who perform input from paper based documents
- Eliminate the need to move the neck
- Positioned close to screen at similar distance
Lighting:
- Uniform and bright
- Position monitor perpendicular to windows
- Neutral wall colour
- remove/cover shiny objects
- Diffusers on overhead lights
- Desk lamps
Noise:
- Less than 55 db
- Sound absorbing partitions
- Impact printers
- Located away from work areas
- Contained within soundproof shields
Conditions:
- Air temp: 20-23
- Relative humidity: 30-70%
Ex 1.1 Q 2 and 4
Ergonomics Homework
Question 2: What factors of an office environment can affect the health of a worker? Describe
the way in which each of these factors affect the workers health.
Question 4: Report on the ergonomics of your school computer rooms. What improvements
would you make if you were allowed an unlimited budget?
Ergonomics in Software:
Software must enhance user experience
Critically evaluate user interfaces. They may not be perfect.
User interface should be intuitive. Used with minimal training.
Ease of use
● Good user interface should be easy to use
● Group together logically connected screen elements
● Keep unrelated screen elements separate
● White space
● Frames
● Application should support a variety of skill levels, novice and expert.
● Short cuts and advanced functionality should be available
● Functionality should not be hidden from the user.
Software that’s accessed by communication links/internet are vulnerable to response time lag
It is vital that developers include methods to ensure their products perform satisfactory under
adverse conditions.