You are on page 1of 19

Faculty of Computing and Informatics

Program Representation

Simon H. Muchinenyika
smuchinenyika@nust.na 2021 Semester I

Introduction to Computing
(ITC511S)
Faculty of Computing and Informatics

Contents
1. Introduction 3. Desk-check
• Programming Process • Testing Program’s Logic
• Examples • Solution Walk Through
2. Pseudocode 4. Flowcharts
• Designing Logic • Program Representation
• Sequential Statements • Flowchart Symbols
• Why Pseudocode • Software
Introduction 1/5

Faculty of Computing and Informatics

1. Introduction

• before solving any problem you need to understand what


is required;

• several approaches exists but we’ll discuss one to get you


oiled up;
Introduction 2/5

Faculty of Computing and Informatics

2. General Programming Process


1. Understand the problem;
2. Design the logic;
3. Desk-check your solution;
4. Code your program;
5. Test your program;
6. Implement your solution;
7. Document all steps.

This course focuses on the first three.


Introduction 3/5

Faculty of Computing and Informatics

3. Understanding the Problem


• this requires reading the problem several times in order
to grasp what is required;

• involves identifying the inputs, storage, processes, and


output requirements of a given problem;

• this was covered in Tutorials 1 and 2.


Introduction 4/5

Faculty of Computing and Informatics

4. Example: Understanding the Problem


Write a program that prompts 2 student records to be entered via keyboard.
The program then calculates and displays the average age of the two students.
Note that a student record in this case is defined by:
student = {studentNumber, studentName, studentAge}

Input Processes Outputs


studentRecord1 prompt for studentRecord1 averageAge
studentRecord2 get studentRecord1
prompt for studentRecord2
get studentRecord2
calculate averageAge
display averageAge
Storage Requirements: Both studentRecord1 and studentRecord2 contains
studentNumber and studentName as strings. studentAge is an integer. Lastly,
averageAge is a real number but can be rounded to an integer
Introduction 5/5

Faculty of Computing and Informatics

5. Design the Logic


• decide on how the problem can be solved;

• represent your solution in pseudocode or flowchart;


Pseudocode 1/4

Faculty of Computing and Informatics

6. Pseudocode
• false code where informal instructions are created for human
consumption and not computer
• Example:
Take a small bowl
Add two eggs
Stir
Take a small frying pan
Add oil
Heat oil for 3 minutes
Pour the mixed eggs into pan
Heat for a minute
Serve with bread

• Discussion: Write pseudocode for brushing teeth.


Pseudocode 2/4

Faculty of Computing and Informatics

7. Sequential Statements
• instructions executed in order to completion;
• note that evert statement should be executable;
• below are commonly used verbs in psudocode to define
specific operations:
Verb Example Description
get get number receives number as input from user input
read read reads number as input from a file or d/base
compute compute average a process that computes the average. An
alternative is the verb calculate
display display average outputs average to the screen. An
alternative is the verb print
write write average outputs average to a file or d/base
Pseudocode 3/4

Faculty of Computing and Informatics

8. Slide 4 Example Revisited


Start
prompt for studentRecord1
get studentRecord1
prompt for studentRecord2
get studentRecord2
total = studentRecord1.studentAge + studentRecord2.studentAge
averageAge = total / 2
dispay averageAge
End
Pseudocode 4/4

Faculty of Computing and Informatics

9. Benefits of Pseudocode
• makes reviews easier without examining the code;

• high level errors can be eliminated at an early stage;

• minimises effort on comments;

• above all, pseudocode provides a detailed design that is easy


for programmers to implement.
Desk-checking 1/2

Faculty of Computing and Informatics

10. Desk-checking
• testing a proposed solution is done by walking data through
pseudocode;
• for every data input used, there should be an expected output;
• numbering a solution from the previous slide we get:
Start
1 prompt for studentRecord1
2 get studentRecord1
3 prompt for studentRecord2
4 get studentRecord2
5 total = studentRecord1.studentAge + studentRecord2.studentAge
6 averageAge = total / 2
7 dispay averageAge
End
Desk-checking 2/2

Faculty of Computing and Informatics

11. Walking Data through Pseudocode


• Input data: studentRecord1 = (2121212, “Peter Hainghono”, 19),
studentRecord2 = (2222111, “Tuwi Nawa”, 21)
Expected output: 20
Line No Operation/input Result
1 prompt prompt message
2 (2121212, “Peter Hainghono”, 19)
3 prompt prompt message
4 (2222111, “Tuwi Nawa”, 21)
5 19 + 21 40
6 40 / 2 20
7 display 20 (output)
• take note of the corresponding line numbers with the solution;
Flowcharts 1/4

Faculty of Computing and Informatics

12. Flowcharts
• an alternative to pseudocode;

• pictorial representation of a solution;

• difficult to modify though compared to pseudocode.


Flowcharts 2/4

Faculty of Computing and Informatics

13. Flowchart Example


Problem:
Write a program that prompts 2
student records to be entered via
keyboard. The program then
calculates and displays the
average age of the two students.
Note that a student record in
this case is defined by:

student = {studentNumber,
studentName, studentAge}
Flowcharts 3/4

Faculty of Computing and Informatics

14. Flowchart Symbols

• input or output symbol;

• processing symbol;

• start or stop symbol;


Flowcharts 4/4

Faculty of Computing and Informatics

15. Flowcharts Software


• draw.io: https://www.draw.io

• creately: https://creately.com

• Pencil Project: http://pencil.evolus.vn

• etc.
MAD811S Mobile World

Faculty of Computing and Informatics

16. Further Study


• Flowcharts:
https://www.mindtools.com/pages/article/newTMC_97.htm

• Desk-checking:
https://sites.google.com/a/campioncollege.com/it_eveningschoool/
problem-solving-and-programming/desk-check-guide
13 Storch Street T: +264 61 207 2054
Private Bag 13388 F: +264 61 207 9054
Windhoek E: smuchinenyika@nust.na
NAMIBIA W: www.nust.na

Faculty of Computing and Informatics

Thank You.

You might also like