0% found this document useful (0 votes)
26 views

Balalo Norbert UNIT 4 PROGRAMMING - Assignment

GBS Digital Technologies UNIT 4 PROGRAMMING - Assignment

Uploaded by

horsmanpaulina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Balalo Norbert UNIT 4 PROGRAMMING - Assignment

GBS Digital Technologies UNIT 4 PROGRAMMING - Assignment

Uploaded by

horsmanpaulina
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

1

unit 4: PROGRAMMING

UNIT 4 ASSIGNMENT

2023 – 2024

Tutor: Kayode Popoola


Jan 2023 Cohort – Group A1 B1
2

STUDENT NAME AND ID Norbert Balalo


NUMBER G58124
Qualification Pearson BTEC Level 4 Higher National Certificate in
Digital Technologies (General)

Academic Year 2023-2024

Unit Number & Name Unit 4: Programming

Unit Leader Marzieh Farahani


Unit Lecturer Marzieh Farahani, Kayode Adenuga, Teza Zoe,
Rajitha Jayasinghe, Hamidreza Bagheri

Assignment Title Understanding core concepts of programming:


algorithms, coding, debugging and paradigms.

Type of Assignment Report and e-Portfolio


Weighting 100%
Issue Date

Summative Submission Date 13.09.2023

Using Summative submission link on Moodle.


Assessor Marzieh Farahani, Kayode Adenuga, Teza Zoe,
Rajitha Jayasinghe, Hamidreza Bagheri

IV name Kayode Adenuga


3

Student Declaration

This is to confirm that this submission is my own work, produced without any

external help except acceptable support from my lecturer. It has not been copied

from any other person’s work (published or unpublished) and has not previously

been submitted for assessment either at GBS or elsewhere. I confirm that I have

read and understood the ‘GBS Academic Good Practice and Academic

Misconduct: Policy and Procedure’ available on Moodle.

I confirm I have read and understood the above Student Declaration.

Student Name (print) Norbert Balalo

Signature Norbert Balalo

13.09.2023
Date
4

Table of Contents
Introduction.................................................................................................................................................5

Task 1: Design Algorithms............................................................................................................................6

The process of turning an algorithm into a working program code.........................................................6

Python Programming Language Benefits.................................................................................................9

Task 2- Programming Paradigms (Procedural, Object Orientated, and Event Driven)...............................10

Procedural Programming.......................................................................................................................10

Object-Oriented Programming..............................................................................................................11

Event-Driven Programming...................................................................................................................12

Task 3 - Implementation, Testing and Evaluation......................................................................................14

Implemented Application......................................................................................................................14

Coding Standard....................................................................................................................................16

Conclusion.................................................................................................................................................17

Reference list.............................................................................................................................................18

Appendix A: Code Listings (Sequence, Selection and Iteration Algorithm)................................................19

Sequence Algorithm..............................................................................................................................19

Selection Algorithm...............................................................................................................................21

Iteration Algorithm................................................................................................................................22

Appendix B: (Assignment Brief Scenario - Procedural, Object-Oriented and Event-Driven)......................24

Procedural Program...............................................................................................................................24

Object-Oriented Program......................................................................................................................26

Event-driven Programs..........................................................................................................................29
5

Introduction

This report documents the implementation of an automated tax calculation program for Kamran

Plastic Factory. Kamran Plastic Factory needs a tax calculation program based on the latest UK

tax rules to not only reduce paperwork but also ensure that the company’s staff are well-

informed about their tax obligations. The report provides a detailed discussion of the

implementation process, which includes a discussion of algorithms, control structures,

programming paradigms, the coding process in Python, the debugging process, and coding

standards. The implementation relies on the PyCharm IDE. The project implements a properly

functioning program that not only calculates taxes but also displays payslips with details such as

the name of the employee, organization name, tax band, income, and net pay.
6

Task 1: Design Algorithms

An algorithm refers to a list of instructions or precise procedures used to solve given problems or

perform specific tasks. Typically, algorithms start with input data, which can be in the form of

numbers, text, images, or other data types depending on the nature of the problem being solved

or the task being performed. Algorithms produce an output, which is the result of the steps

predefined in the algorithm (Gillis, 2022). Algorithms are fundamental in building computer

applications. They are like the building blocks of computer programs. In terms of the relationship

between algorithms and codes, algorithms act as the conceptual blueprint for the codes. This

means that codes mainly translate the concepts provided in algorithms into executable

instructions. Essentially, algorithms guide the problem-solving process while codes offer the

practical means to solution in a given programming language. The process of turning an

algorithm into a working program code takes various steps. These steps are discussed in the

section below.

The process of turning an algorithm into a working program code

Turning an algorithm into working program code takes various steps. These steps include the

following: -

Problem Definition – This step focuses on identifying the problem that needs to be addressed. It

involves gathering the necessary requirements and identifying the aspects that the program

should accomplish (Testing Docs, n.d.). Essentially, the problem definition step helps identify

user needs and information by engaging the necessary stakeholders.

Algorithm Design – Once the problem to be addressed has been defined correctly, the next step

focuses on designing the algorithm. The algorithm design process begins with dividing the larger
7

problem into sub-problems (Testing Docs, n.d.). The next thing to do is to identify and decide on

the most appropriate data structures and controls that will be used in the proposed solution.

Flowcharts can be used in this phase to represent the algorithm.

Write the program – This step focuses on translating the algorithm designed in the previous

step into an actual code (Testing Docs, n.d.). An appropriate programming language that suits the

task is selected and used to implement the proposed program following the logic provided by the

algorithm. The code is written following best practices and standards of coding to ensure that it

is understandable and clear.

Testing and Debugging – After writing the program code, it is fundamental to conduct testing

and debugging. Testing and debugging focus on testing the program to ensure that it works as

expected. The code can be tested in different ways, including using different inputs to determine

if it produces the right outputs and handles errors correctly (Testing Docs, n.d.). Debugging tools

are used during testing to track down and resolve any emerging issues.

Program Documentation – Documentation is essential for maintaining and understanding the

program code. It mainly focuses on writing down the purpose of different parts of code, adding

comments to the code, and documenting the code’s functions and inputs, among other aspects of

the code (Testing Docs, n.d.). With proper documentation, future developers can easily

understand it, identify issues, and make necessary issues.

There are different types of control structures considered when designing algorithms. They

include sequential, selection, and iterative control structures. The sections below discuss the

sequence, selection, and iteration algorithms for a tax calculation application for Kamran Plastic

Factory.
8

Sequence Algorithm – Sequence algorithms, as the name suggests, are executed sequentially.

This means that they are made up of steps executed in order, one after another (Busbee and

Braunschweig, 2018). The instructions/statements are executed without any condition or

branching. Essentially, sequence algorithms do not involve any decision-making. The sequence

algorithm in Appendix A illustrates how sequence algorithms work. It shows that the process of

tax calculation is executed sequentially. It starts with asking for income, then proceeds to

calculate the tax, and finally prints it.

Selection Algorithm – Selection algorithms use selection to determine the steps that should be

executed (Busbee and Braunschweig, 2018). They rely on conditional statements to make

decisions. For instance, selection algorithms use statements such as if, else if, and else to execute

different blocks of code depending on whether the condition is true or false. An example of a

selection algorithm is provided in Appendix A. As evident in the algorithm, flowchart, and code,

Python’s if, elif, and else statements are used to determine the tax band of an employee’s income

and calculate income tax based on the formula for the selected tax band. The example shows the

essence of selection algorithms in decision-making in applications.

Iteration Algorithm – Iteration algorithms rely on iteration/repetition to execute a given set of

steps for as long as a certain condition is met (Busbee and Braunschweig, 2018). In most cases,

iteration algorithms use loop statements, such as for loops and while loops for iteration. An

example of an iteration program is provided in Appendix A. The algorithm provided in

Appendix A, as evident in the flowchart and code, uses a ‘while loop’ to repeat the process of tax

calculation if the user wants to calculate the taxes of additional people.


9

Generally, as evident in Appendix A, the tax calculation program needs a combination of

sequential, iteration, and selection control structures to function. This means these control

structures are not mutually exclusive but are used together in the implementation of programs.

Python Programming Language Benefits

The Python programming language offers a wide range of benefits that make it a suitable

language for the development of a wide range of applications, including the proposed tax

calculation program for Kamran Plastic Factory. One of the key benefits of Python is that it is a

high-level programming language that allows programmers to concentrate on development

without worrying about low-level aspects like memory management (Cutting and Stephen,

2021). Secondly, Python is a cross-platform language. This implies that Python’s code can run

on different platforms, such as Windows, Linux, and MacOS. The third benefit of Python

programming language is its readability and simplicity (Cutting and Stephen, 2021). Beginners

and experienced programmers can easily read and understand Python code, thus reducing the

possibility of programming errors. The fourth benefit of Python is that it supports a

comprehensive library that includes modules and packages for various tasks. The availability of

an extensive library reduces the need for developers to write code from scratch, thus saving time

and effort (Cutting and Stephen, 2021). Lastly, Python has a large and active community of

developers. This means that developers can access a wide range of resources that they can use in

the development of software. Generally, the above benefits of the Python programming language

make it one of the languages suitable for the development of the tax calculation program for

Kamran Plastic Factory.


10

Task 2- Programming Paradigms (Procedural, Object Orientated, and Event

Driven)

There are different programming paradigms that developers can use in building applications.

Some of the common paradigms include procedural, object-oriented, and event-driven

paradigms. These paradigms provide the approaches or styles that dictate how programs should

be structured, organized, and executed. While these paradigms may sound different, they are not

mutually exclusive and can be used together to solve a complex problem. The sections below

provide a detailed discussion of procedural, object-oriented, and event-driven programming

paradigms.

Procedural Programming

Procedural programming is a programming paradigm that is based on the concept of calling

procedures (Pankaj, 2022). Procedures are made up of a series of computation steps to be

executed. During the execution of a program based on procedural programming, any procedure

can be called at any given point, including by other procedures, or it can call itself. The

procedural programming paradigm is characterized by various concepts. Some of these concepts

include the following: -


11

Variables to hold data – Procedural programs rely on variables to store and manipulate data.

For instance, in the procedural program code provided in Appendix B, a variable named income

is provided. The variable is initialized as income = float (input("Enter your annual income in

pounds: ")), to store the annual income of the employee for tax calculation.

Process to calculate – In order to calculate, a procedure can be defined to carry out the

necessary calculations. For instance, in the procedural code provided in Appendix B, conditional

statements are included in the calculate_income_method () definition to guide the tax calculation

process. Input and Output – Input and output help facilitate interaction between the user and

the program. The procedural code provided in Appendix B shows various inputs and inputs. An

example of an input is the income input (input ("Enter your annual income in pounds: ")). An

example of output in the code is print(f"Your income tax is: £{income_tax:.2f}"), which prints

the output of the tax calculation process.

How to make decisions – Decision-making relies on conditional statements such as if, elif, and

else. In the procedural code provided in Appendix B, these statements are used to determine the

appropriate rate of tax band based on employee income.

Loops – In procedural programming, loops are used to handle repetitive tasks. For instance, in

the tax calculation code in Appendix B, a while loop is used to repeat the process of tax

calculation if the user wants to calculate the taxes of additional people.

Functions – Functions are useful in procedural programming. The procedural tax calculation

code in Appendix B defines and uses a function called calculate_income_tax (). This function

contains the code that calculates income tax based on the provided annual income.

Object-Oriented Programming
12

Object-oriented programming is based on the concept of objects, which are instances of classes.

The Python programming language supports object-oriented programming. This means that a

Python program can be designed using objects (Pankaj, 2022). Other important concepts

supported in object-oriented programming are encapsulation, inheritance, polymorphism, and

abstraction. The sections below discuss these concepts.

Class / Objects – In object-oriented programming, classes are a blueprint/template that defines

the structure and behavior of objects. The object-oriented code provided in Appendix B shows a

class Tax Calculator. The class specifies the functions and attributes that the objects of the class

should have.

Inheritance – Inheritance refers to a mechanism in object-oriented programming that allows

programmers to create a subclass based on an existing class. Once created, the subclass inherits

the attributes and methods of the superclass (Pankaj, 2022).

Abstraction – Abstraction hides the complex implementation details of a programming language

from the user. A user is only shown the necessary features. For instance, when creating the Tax

Calculator class in the OOP code in Appendix B, the programmer did not need to know the

implementation details of the class.

Encapsulation – Encapsulation is the bundling of data and methods into a single unit. In the

OOP code provided in Appendix B, encapsulation is evident in the usage of the class

TaxCalculator. The class encapsulates all other details of the code, including methods and data,

into a single entity.

Polymorphism – Polymorphism is the practice where the objects of different classes can be

treated as objects of a common superclass. In Python, polymorphism can be achieved using the
13

method overriding strategy whereby a subclass provides its own implementations of methods

that have already been defined in the superclass.

Event-Driven Programming

Event-driven programming plays a critical role in the development of applications. Events are

mainly occurrences that trigger specific actions or responses within an application. They include

interactions like keyboard presses, mouse clicks, or button presses, among others (Reintech,

2023). An example of an event-driven program is provided in Appendix B. The example shows

the implementation of a keypress whereby a user can click the escape key to exit the tax

calculation application.

The discussion above on procedural, object-oriented, and event-driven programming shows that

the three paradigms are not mutually exclusive. They work together to implement a functioning

application. This is evident in the Object-Oriented code provided in Appendix B. The code

provided in the object-oriented programming section is the final code for the application. It

shows elements of procedural, object-oriented, and event-driven programming. The elements of

the procedural paradigm evident in the code include functions such as calculate_income_tax (),

display_tax_band, run (), and on_key_press (), variables like income, organization, and name,

while loops, inputs, and outputs, and decision-making statements. In terms of the object-oriented

paradigm, the code contains a TaxCalculator class that encapsulates other aspects of the code,

such as methods and variables. In terms of event-driven programming, the program implements a

key press event, such that users can click the escape key to exit the application. Generally,

although the procedural, object-oriented, and event-driven paradigms are different, they are

implemented together to achieve a properly functioning application. The implemented Tax

Calculation project, as evident in Appendix B, was able to function as expected. A user is able to
14

enter a name, organization, and income, then the application automatically calculates the tax and

displays a pay slip with details such as name, organization, annual income, tax band, income tax,

and net pay. Users can also choose to add details of another user or exit the application. The

application demonstrates the functionality of procedural, object-oriented, and event-driven

paradigms.

Task 3 - Implementation, Testing and Evaluation

Implemented Application

The final program considered the iteration, selection, and sequence control structures. The

program also implemented procedural, object-oriented, and event-driven paradigms. The

algorithm, code, and flowchart for the program are provided in the OOP section of Appendix B.

The program was developed using the PyCharm IDE. The requirement was to implement an

application with various features. Mainly, the application should be able to calculate tax based on

the recent tax calculation rules from the UK government. The application should welcome the

user, ask for the full name of the employee, and organization, enter and read income, and

calculate income tax. The application should print a payslip showing the employee's data, tax

band, income tax, and net pay. A user should be able to add another employee or stop the

program. If the user chooses to exit, the program should thank the user. The implemented

program contains all these features. The test results are shown in the figure below.
15

As seen in the figure above, the application welcomes the user. It asks users to provide a name,

the organization they work for, and annual income. The application then calculates the tax

automatically and displays a payslip. As required, the payslip contains details such as the name

of the employee, organization name, tax band, income, and net pay. The application also asks the

user if they want to calculate the tax for another person. If so, the process repeats. If not, the

application shows a thank you message and stops.

Use of IDE and Debugging Process

As mentioned earlier, this project used the PyCharm IDE. Using an IDE for application

development offers a wide range of benefits compared to not using an IDE. For instance, the

PyCharm IDE offered features such as code completion, syntax highlighting, and error checking,

which made the development process easier and more efficient. PyCharm also offers an

integrated terminal, which was useful during the installation of ‘pynput’ to support the keypress

feature. Such tools are not available in other development tools, such as text editors. In terms of
16

debugging, PyCharm provides a debugging feature that is used to debug an application.

Debugging helps identify and fix errors in a source code. For instance, when working on the tax

calculation program, I encountered an error saying that the name ‘self’ is not defined. In order to

understand the issue and address the problem, the debug feature is PyCharm was very helpful.

The process of debugging started with setting a breakpoint in the code and running the debugger.

After entering a sample name in the debugger console, the debugger’s Threads and Variables, as

shown in the figure below, displayed enough information to trace and fix the problem. This

shows that debugging is a very helpful process in program development. It eases the process of

identifying and fixing errors, thus leading to the development of secure and robust applications.

Coding Standard

Coding standards are coding conventions or rules followed when writing source code for

software programs. The benefit of having a coding standard is that it ensures that the written
17

source code follows a consistent style, is readable, and that it is easy to maintain (Kumar, 2022).

Additionally, using a coding standard makes debugging easier. The source for the tax calculation

program followed the PEP 8 standard, which is a coding standard for Python programming. The

standard specifies the style conventions, such as indentation and variable naming, which can

used in Python programming. The PyCharm enforced some of these conventions, such as the

indentation style defined in PEP 8.

Conclusion

Algorithms play critical roles in software development. They provide blueprints for writing

codes. Essentially, algorithms guide the problem-solving process in software development. This

project relied on an algorithm to develop an application to calculate tax and display payslips. The

application was based on the procedural, object-oriented, and event-driven paradigms. A

properly working and tested application was implemented and discussed in this paper. The use of

the PyCharm IDE made the development easier. The IDE offered features such as code

completion, syntax highlighting, and error checking, which improved the development process.

The software development relied on the PEP 8 coding standard, which is a standard supported by

Python, and enforced by the PyCharm IDE. Generally, the development process was easier and a

properly functioning application was produced.


18

Reference list

Busbee, K. and Braunschweig, D. (2018). Structured Programming. [online] Rebus Community.

Available at: https://press.rebus.community/programmingfundamentals/chapter/structured-

programming/ (Accessed: 10 September 2023)

Cutting, V. and Stephen, N. (2021). A Review on using Python as a Preferred Programming

Language for Beginners. International Research Journal of Engineering and Technology

(IRJET), 8 (8).

Gillis, A. (2022). What is an algorithm? - Definition from WhatIs.com. [online] WhatIs.com.

Available at: https://www.techtarget.com/whatis/definition/algorithm (Accessed: 10 September

2023)
19

Kumar, S. (2022). Coding Standards and Guidelines. [Online] GeeksforGeeks. Available at:

https://www.geeksforgeeks.org/coding-standards-and-guidelines/ (Accessed: 10 September

2023)

Pankaj (2022). Differences between Procedural and Object Oriented Programming. [Online]

GeeksforGeeks. Available at: https://www.geeksforgeeks.org/differences-between-procedural-

and-object-oriented-programming/ (Accessed: 10 September 2023)

Reintech (2023). What is event-driven programming and how is it used in JavaScript? [Online]

Reintech Media. Available at: https://reintech.io/blog/what-is-event-driven-programming-in-

javascript (Accessed: 10 September 2023)

Testing Docs. (n.d.). Algorithm Development Process. [Online] Testing Docs. Available at:

https://www.testingdocs.com/algorithm-development-steps/ (Accessed: 10 September 2023)

Appendix A: Code Listings (Sequence, Selection and Iteration


Algorithm)

Sequence Algorithm
 Algorithm (sequence)

1. Start
2. Ask the User to Enter the Income
3. Calculate Tax Using the Defined Tax Calculation Formula
4. Print Tax
5. Stop

 Flow-chart
20

 Code (Optional)
21

Selection Algorithm
 Algorithm (selection)
1. Start
2. Ask the User to Enter the Income
3. If Income <= 12570, set Tax as 0
4. If Income ranges between 12571 and 50270, set Tax as Tax = (income - 12570) * 0.20
5. If Income ranges between 50271 and 125140, set Tax as Tax = (50270 - 12570) * 0.20 + (income -
50270) * 0.40
6. If Income is higher than 125140, set Tax as Tax = (50270 - 12570) * 0.20 + (125140 - 50270) *
0.40 + (income - 125140) * 0.45
7. Display Tax
22

8. Stop

 Flow-chart

 Code (Optional)

Iteration Algorithm
 Algorithm (Iteration)
1. Start
23

2. Enter the while loop as long as the user wants to calculate the tax of another employee.
3. Display option to enter details of employee
4. End

 Flow-chart

 Code (Optional)

Appendix B: (Assignment Brief Scenario - Procedural, Object-


Oriented and Event-Driven)
Procedural Program
 Algorithm
24

1. Start
2. Ask the user to enter the income
3. Validate the income to ensure it's non-negative and numeric
4. Calculate Tax
5. Display Tax
6. Ask whether to calculate tax for another person. If yes, repeat the process. If not, exit the
application.
7. Stop
 Flow-chart

 Code
25

 Testing

Object-Oriented Program
 Algorithm
26

1. Start
2. Welcome User
3. Enter name, Organization, and Annual Income In Pounds
4. Validate Income to ensure it's numeric and non-negative
5. Calculate Tax
6. Print Payslip with name, organization, annual income, tax band, income tax, and net pay.
7. Ask whether to calculate another person's tax. If yes repeat the process. If no, exit and print a
bye message.
8. Can also exit by clicking the escape key
9. Stop
 Flow-chart

 Code
27
28

 Testing
29

Event-driven Programs
 Algorithm

1. Start
2. If the user clicks the escape key, exit
3. Stop
 Flow-chart

 Code

 Testing
30

You might also like