Flowchart (cont.) 51
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
52
Phase 3 : Implementation/Coding
The pseudocode and flow chart which have been done in the design step
will be converted into a program by using certain programming languages
such as BASIC, JAVA, C or C++.
This step solves the problem by enabling the user to start writing the
programs.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
Phase 3 : Implementation/Coding 53
(cont.)
Coding is the actual process of creating a program in a programming
language.
The coded program is referred to as source code.
Must follow certain rules which are called syntax.
Must then be saved as a program which has the extension ‘.cpp’.
To be executed, the program is converted by the computer into object
code using a special program or translator such as a compiler or interpreter.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
54
Phase 4 : Testing/Debugging
The step for checking and verifying the correctness of the program.
The process of making sure a program is free of errors or ‘bugs’ is called
debugging.
Preliminary debugging begins after the program has been entered into the
computer system.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
55
Phase 5 : Maintenance
Last step in the Program Development Life Cycle (PDLC).
Essentially, every program, if it is to last a long time, requires ongoing
maintenance.
A process of updating software for any changes, corrections, additions,
moving to a different computing platform and others so that it continues to
be useful.
A costly process.
Can be very useful especially on extending the life of a program.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
1.4 Problem solving and 12/14/2022
algorithm design
56
VISUAL PROGRAMMING (Session : 2 2022/2023)
Pseudocode (cont.) 57
Sequential Control Structure 12/14/2022
Question:
Calculate the BMI of a user
Solution:
1.0 BEGIN
2.0 DECLARE double bmi, weight, height
3.0 READ weight, height
4.0 CALCULATE bmi = weight / pow (height, 2)
5.0 DISPLAY bmi
6.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Pseudocode (cont.) 58
Sequential Control Structure 12/14/2022
Question:
Find the area of a circle.
Solution:
1.0 BEGIN
2.0 DECLARE double radius, area; const double pi = 3.142;
3.0 READ radius
4.0 CALCULATE area = pi * pow (radius, 2)
5.0 DISPLAY area
6.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Pseudocode (cont.) 59
Sequential Control Structure 12/14/2022
Question:
Calculate the sum of 3 integer and store the value in total.
Solution:
1.0 BEGIN
2.0 DECLARE int no1, no2, no3, total
3.0 READ no1, no2, no3
4.0 CALCULATE total=no1+no2+no3
5.0 DISPLAY total
6.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Pseudocode (cont.) 60
Selection Control Structure 12/14/2022
Question:
Identify whether a number is a positive or negative number
Solution:
1.0 BEGIN
2.0 DECLARE int num
3.0 READ num
4.0 if(num > 0)
4.1 DISPLAY “positive number”
5.0 else
5.1 DISPLAY “negative number”
6.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
61
Pseudocode (cont.)
Selection Control Structure
Question: Account Balance Service Charge
Less than RM300 RM5
RM300 or more RM2
Input is account balance.
Process is to identify service charge based on account balance value.
Output is service charge. Write pseudocode and draw flowchart for the task.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
Pseudocode (cont.) 62
Solution: 12/14/2022
1.0 BEGIN
2.0 DECLARE double accountBalance, serviceCharge
3.0 READ accountBalance
4.0 if (accountBalance < 300)
4.1 serviceCharge = 5.00
5.0 else
5.1 serviceCharge = 2.00
6.0 DISPLAY serviceCharge
7.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Selection Control Structure
Question:
Design an algorithm that will read two numbers and an integer code from the screen. The value
of the integer code should be 1,2,3 or 4.
If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the
difference (first minus second). If the code is 3, compute the product of the two numbers. If the
code is 4, and the second number is not zero, compute the quotient (first divided by second).
If the code is not equal to 1,2,3, or 4, display an error message.
The program is then to display the two numbers, the integer code and the computed result to
the screen.
12/14/2022 VISUAL PROGRAMMING (Session : 2 2022/2023) 63
VISUAL PROGRAMMING (Session : 2 2022/2023) 64
12/14/2022
VISUAL PROGRAMMING (Session : 2 2022/2023) 65
12/14/2022
PSEUDOCODE
1.0 BEGIN
2.0 DECLARE int input, total, no1, no2, sum, difference, product;
double quotient;
string operation;
3.0 READ no1, no2
4.0 if (input == 1)
4.1 operation = “SUM”
4.2 total = no1 + no2
5.0 else if(input == 2)
5.1 operation = “DIFFERENCE”
5.2 total = no1 – no2
6.0 else if(input == 3)
6.1 operation = “PRODUCT”
6.2 total = no1 * no2
7.0 else if(input == 4)
7.1 operation = “QUOTIENT”
7.2 if(no2 =! 0)
7.2.1 total = no1 / no2
7.3 else
7.3.1 DISPLAY “Second number cannot ZERO”
8.0 else
8.1 DISPLAY “invalid input. Enter 1 – 4 only”
9.0 DISPLAY total
END
12/14/2022 VISUAL PROGRAMMING (Session : 2 2022/2023) 66
67
Pseudocode (cont.)
Selection Control Structure
Question:
Design an algorithm that will prompt an operator for a student’s id and the student’s exam
score out of 100. Your program is then to match the exam score to a letter grade and print
the grade to the screen. Calculate the letter grade as follows:
VISUAL PROGRAMMING (Session : 2 2022/2023) Exam Score Assigned Grade 12/14/2022
90 and above A
B
80 – 89 C
70 – 79 D
60 – 69 F
Below 60
PSEUDOCODE
1.0 BEGIN
2.0 DECLARE string studentID;
int examScore;
char grade;
3.0 READ studentID, examScore
4.0 if (examScore >= 90 && examScore <= 100)
4.1 DISPLAY grade = ‘A’
5.0 else if (examScore >= 80 && examScore <= 89)
5.1 DISPLAY grade = ‘B’
6.0 else if (examScore >= 70 && examScore <=79)
6.1 DISPLAY grade = ‘C’
7.0 else if (examScore >=60 && examScore <= 69)
7.1 DISPLAY grade = ‘D’
8.0 else if (examScore >= 0 && examScore <60)
8.1 DISPLAY grade = ‘F’
9.0 else
9.1 DISPLAY “Invalid exam score enter by the user”
10.0 END
12/14/2022 VISUAL PROGRAMMING (Session : 2 2022/2023) 68
Pseudocode (cont.) 69
Selection Control Structure 12/14/2022
Question:
Design an algorithm that will receive the weight of a parcel and determine the
delivery charge for the parcel. Calculate the charges as follows:
Parcel weight Cost per kg (RM)
(kg)
RM 3.50 per kg
< 2.5 kg RM 2.85 per kg
RM 2.45 per kg
2.5 – 5 kg
> 5 kg
VISUAL PROGRAMMING (Session : 2 2022/2023)
70
Pseudocode (cont.)
Selection Control Structure
Question:
Design an algorithm that will prompt a terminal operator for the price of an article and a
pricing code. Your program is then to calculate a discount rate according to the pricing code
and print to the screen the original price of the article, the discount amount and the new
discounted price. Calculate the pricing code and accompanying discount amount as follows:
Pricing code Discount rate
H 50%
F 40%
T 33%
Q 25%
VISUAL PROGRAMMING (Session : 2 2022/2023) Z 0% 12/14/2022
1.0 BEGIN
2.0 DECLARE char pricingCode;
float price, discountRate, discoutAmount, discountPrice
3.0 READ pricingCode, price
4.0 if(pricingCode == ‘H’)
4.1 discountRate = 0.50
5.0 else if (pricingCode == ‘F’)
5.1 discountRate = 0.40
6.0 else if (pricingCode == ‘T’)
6.1 discountRate = 0.33
7.0 else if (pricingCode == ‘Q’)
7.1 discountRate = 0.25
8.0 else if (pricingCode == ‘Z’)
8.1 discountRate = 0.0
9.0 else
9.1 INVALID “pricing code”
10.0 CALCULATE discoutAmount = discountPrice * discountRate
11.0 DISPLAY discoutAmount
12.0 END VISUAL PROGRAMMING (Session : 2 2022/2023) 71
12/14/2022
Pseudocode (cont.) 72
Repetition Control Structure 12/14/2022
Question:
Get three numbers and find the total sum and average of the three numbers.
Solution:
1.0 BEGIN
2.0 DECLARE int no, sum, count; double avg
3.0 INITIALIZE sum = 0; count = 0
4.0 while (count < 3)
4.1 READ no
4.2 CALCULATE sum += no
4.3 CALCULATE count ++
5.0 CALCULATE avg = sum / count
6.0 DISPLAY sum, avg
7.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Repetition Control Structure 73
Question: 12/14/2022
Display the total and average marks of 20 students in a class.
Solution:
1.0 BEGIN
2.0 DECLARE double mark, total, average;
int student;
3.0 INITIALIZE total = 0, student = 0;
4.0 while (student < 20)
4.1 READ mark
4.2 CALCULATE total += mark;
4.3 CALCULATE student ++
5.0 CALCULATE average = total/student
6.0 DISPLAY total, average
7.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
74
Repetition Control Structure
Question:
Draw a flowchart to determine whether a number is an odd or
even number. A user will enter any number and the system will
display “odd number” if odd number entered, or “even number” if
even number entered. The system will keep asking the user to
enter any number. To stop using the system, user need to enter
zero (0).
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
75
Repetition Control Structure
Question:
Formulate a pseudocode that will calculate a running sum.
A user will enter numbers that will be added to the sum and
when a negative number is encountered, stop adding
numbers and display the final sum.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
Repetition Control Structure 76
Solution: 12/14/2022
1.0 BEGIN
2.0 DECLARE int number, count, sum
3.0 INITIALIZE sum = 0, count = 0
4.0 GET number
5.0 WHILE (number > 0)
5.1 sum += number
5.2 count ++
5.3 GET number
6.0 DISPLAY sum
7.0 END VISUAL PRRAMMING (Session : 2 2022/2023)
Repetition Control Structure 77
Question: 12/14/2022
Get the salary of a 20 employees then find the total salaries of all the employees.
Solution:
1.0 BEGIN
2.0 DECLARE double salary, totalSalary;
int employee
3.0 INITIALIZE totalSalary = 0.0, employee = 0
4.0 while (employee < 20)
4.1 READ salary
4.2 CALCULATE totalSalary += salary
4.3 CALCULATE employee ++
5.0 DISPLAY totalSalary
6.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
78
Repetition Control Structure
Question: 12/14/2022
Get the amount of saving for the first year. Assume that 6% dividend is given every years. Find the amount of
saving after 10 years. Show and display the increment of money in the bank every year from year 1 to 10.
Solution:
1.0 BEGIN
2.0 DECLARE double saving, totalSaving
const double dividend = 0.06
int year
3.0 INITIALIZE year = 1
4.0 READ saving
6.0 DO
6.1 CALCULATE totalSaving = (saving * dividend) + saving
6.2 CALCULATE year ++
6.3 while (year <= 10)
8.0 go to step 6.0
9.0 DISPLAY year, totalSaving
10.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
79
Repetition Control Structure
Question:
Identify whether a number is an odd or even number. Then find and display the sum of all the odd and even numbers. To
stop program, user must enter N.
Solution: 12/14/2022
1.0 BEGIN
2.0 DECLARE int no, sumOdd, sumEven;
char stop
3.0 INITIALIZE sumOdd = 0, sumEven = 0
4.0 READ no
5.0 if (no%2 == 0)
5.1 DISPLAY “Even number”
5.2 sumEven += no;
6.0 else if (no%2 != 0)
6.1 DISPLAY “Odd number”
6.1 sumOdd += no;
7.0 else
7.1 DISPLAY “Invalid input from user”
8.0 READ stop
9.0 while (stop == ‘N’)
9.1 DISPLAY sumEven, sumOdd
10.0 GO TO STEP 4.0
10.0 END
VISUAL PROGRAMMING (Session : 2 2022/2023)
Repetition Control Structure 80
Question: 12/14/2022
Display the square of the numbers of 1 to 20
Solution:
1.0 BEGIN
2.0 DECLARE int power, num
3.0 for (num = 1; num <= 10; num ++)
3.1 CALCULATE power = pow (num, 2)
4.0 GO TO step 3.0
5.0 DISPLAY “num, power”
e
VISUAL PROGRAMMING (Session : 2 2022/2023)
81
Pseudocode (cont.)
Repetition Control Structure 12/14/2022
Question:
Find average temperature
A program is required to prompt the terminal operator for the maximum
and minimum temperature readings on a particular day, accept those
readings as integers, and calculate and display to the screen the average
temperature, calculated (maximum temperature + minimum
temperature)/2
VISUAL PROGRAMMING (Session : 2 2022/2023)
82
Produce pseudocode and flowchart for the program
below:
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
83
Produce pseudocode and flowchart for the program
below:
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
84
Produce pseudocode and flowchart for the program
below:
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
85
Produce pseudocode and flowchart for the program
below:
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
86
Produce pseudocode and flowchart for the program
below:
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022
87
Write a pseudocode to calculate total expenditure for a student.
The program will receive a number of days and a daily expenditure as an input. While number of
days is not exceeding the value enter by the user, they will be able to input daily expenditure.
The program will accumulate the daily expenditure until the repetition process ended. Then,
display total expenditure.
VISUAL PROGRAMMING (Session : 2 2022/2023) 12/14/2022