Balalo Norbert UNIT 4 PROGRAMMING - Assignment
Balalo Norbert UNIT 4 PROGRAMMING - Assignment
unit 4: PROGRAMMING
UNIT 4 ASSIGNMENT
2023 – 2024
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
13.09.2023
Date
4
Table of Contents
Introduction.................................................................................................................................................5
Procedural Programming.......................................................................................................................10
Object-Oriented Programming..............................................................................................................11
Event-Driven Programming...................................................................................................................12
Implemented Application......................................................................................................................14
Coding Standard....................................................................................................................................16
Conclusion.................................................................................................................................................17
Reference list.............................................................................................................................................18
Sequence Algorithm..............................................................................................................................19
Selection Algorithm...............................................................................................................................21
Iteration Algorithm................................................................................................................................22
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
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
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
algorithm into a working program code takes various steps. These steps are discussed in the
section below.
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
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.
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
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 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
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
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
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
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
Appendix A, as evident in the flowchart and code, uses a ‘while loop’ to repeat the process of tax
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.
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
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
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
Driven)
There are different programming paradigms that developers can use in building applications.
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
paradigms.
Procedural Programming
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
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
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
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
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
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.
programmers to create a subclass based on an existing class. Once created, the subclass inherits
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
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,
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
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,
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
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
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
paradigms.
Implemented Application
The final program considered the iteration, selection, and sequence control structures. 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
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 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
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
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
Reference list
(IRJET), 8 (8).
2023)
19
Kumar, S. (2022). Coding Standards and Guidelines. [Online] GeeksforGeeks. Available at:
2023)
Pankaj (2022). Differences between Procedural and Object Oriented Programming. [Online]
Reintech (2023). What is event-driven programming and how is it used in JavaScript? [Online]
Testing Docs. (n.d.). Algorithm Development Process. [Online] Testing Docs. Available at:
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)
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