IPRG5111_Lecture 5S_2024
IPRG5111_Lecture 5S_2024
png)
HMAW – IPRG5111
Introduction to Programming Logic
Lecture 5
Objectives
• Chapter 3: Lecture 4
• Spaghetti code
• Working with logical structures
• Chapter 4
• Sequential Logic
Lecture 5
• Group Activity
• Practical
Chapter 3 - Logic Structures
The disadvantages of unstructured spaghetti code
Spaghetti code is a term used for any source code that is hard to
understand. It has no defined structure.
The Disadvantages of Unstructured
Spaghetti Code
• Spaghetti code
– Logically incorrect (snarled) program statements
– Often a complicated mess
– Programs often work but are difficult to read and maintain
– Confusing and prone to error
• Unstructured programs
– Do not follow the rules of structured logic
• Structured programs
– Follow the rules of structured logic
Basic prevention steps that could and should be taken:
• Comments
Comments will not only help the programmer, but also others that are reading
through the code. Provides clarity where needed.
• Single-alternative ifs
STEP 2:
Detail the actual design elements of the program, namely: program flow (how the program
works).
You are to create the following in your group:
•IPO table (part 2)
•A flowchart (part 3)
•Pseudocode (part 4)
start
output “Please enter in a number“
input myNumber
set myAnswer = myNumber / 2
output myAnswer
stop
Exercise 2
2. Draw a flowchart and write pseudocode to represent the logic of a
program that allows the user to enter two values. The program outputs
the product of the two values.
3. Draw a flowchart or
Exercise 3
& write pseudocode to represent the logic of a program
that allows the user to enter a value for hours worked in a day. The program
calculates the hours worked in a five-day week and the hours worked in a 252-
day work year. The program outputs all the results.
Pseudocode
start
input hoursWorkedDay
set hoursWorkedWeek = hoursWorkedDay * 5
set hoursWorkedYear = hoursWorkedDay * 25
output hoursWorkedWeek
output hoursWorkedYear
stop
Exercise 4
&
Working with Variables
Example:
Example:
Example:
The current 3-character prefixes
that will be used with the names
of variables. This could serve as
an extra classification of the
variable.
output fltSemesterMark
stop
Practical's
STEP 1: Create a folder on your drive
STEP 2: OPEN NOTEPAD
Practical's
STEP 1: Create a folder on your drive
STEP 2: OPEN NOTEPAD
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index - [Name of Program]</title>
</head>
<body>
<h1>Index - [Name of the program]</h1>
<h4>
The following webpage will execute the script file named
"code1".
</h4>
<script src="js/code1.js"></script>
</body>
</html>
Practical's
STEP 3: Type the code below in NOTEPAD
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Index - [Name of Program]</title>
</head>
<body>
<h1>Index - [Name of the program]</h1>
<h4>
The following webpage will execute the script file named
"code1".
</h4>
<script src="js/code1.js"></script>
</body>
</html>
Practical's
STEP 3: Saving the doc
Practical's
STEP 3: Saving the doc
Practical's
STEP 4: Open a NEW NOTEPAD and type the following
Before
Practical's
STEP 12: Paste the link, see below:
After
Practical's
STEP 12: Save and close testcode and then double click on the file testcode
Practical's
STEP 12: Save and close testcode and then double click on the file testcode