Programming Assignment: Salary Calculation and Debugging - BTEC HND

Verified

Added on  2022/10/04

|29
|4465
|45
Homework Assignment
AI Summary
This document presents a comprehensive solution for a BTEC HND in Computing programming assignment. The assignment covers the development of an algorithm for salary calculation based on sales figures, including commission rates and total pay. It then explores the differences and similarities between procedural, object-oriented, and event-driven programming paradigms. A Python program is provided to calculate employee salaries, incorporating functions for sales input, commission rate determination, and total pay calculation. The assignment also delves into the debugging process using the Spyder IDE, detailing the debugging features, error handling, and the application of debugging for designing robust applications. Screenshots of the code and debugging process are included to illustrate the concepts. The solution showcases the student's understanding of programming concepts, debugging techniques, and the application of programming paradigms.
Document Page
Running head: BTEC HND in Computing
BTEC HND in Computing
Name of the Student
Name of the University
Author Note
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
1BTEC HND in Computing
LO1
Description of algorithm:
It is a description of the rules and logic that is considered for solving a problem through
programing and for this, the required code is implemented according to this algorithm in the
provided programing language according to the requirements.
Algorithm for the solution for the provided for the commission and total salary calculation
problem;
Start
Declare the global salary variable with the value=32000
Ask input for the operation to be carried out
1 for Calculate salary
Exit for exit the program and stop the execution of the game.
If choice 1
Ask the user to enter sales amount
If sales < 500.00:
Return rate = 0
Else if sales >= 500.00 and sales <= 2000.00:
Return rate = 0.05
Else if sales >= 2000.00 and sales <= 5000.00:
Return Rate = 0.09
Document Page
2BTEC HND in Computing
Else if sales >= 5000.00 and sales <= 10000.
Return Rate = 0.13
Else:
Return Rate = 0.20
Calculate total pay
Pay=(pay*rate)+salary
Print(Total salary , pay)
If choice ==2
Exit program
LO2
Differences and similarities between procedural, object oriented and event driven
programming paradigms:
The programing paradigm refers to the style of programing and it is nothing but an
approach of solving problems while analysing and defining the problem in different way (Liu
and Petersen 2019). There are different programing paradigm, each of them refers to different
problem solving approaches, and therefore there are significant differences between these
programing paradigms, which are described in this context. Some of the important
differences between these programing paradigms are the followings:
Document Page
3BTEC HND in Computing
Event Driven Programming
Paradigm
Procedural Programming Paradigm
Object Oriented
Programming
Paradigm
Graphical user interface is provided
which allows to create the programs.
Character user interface is provided for
writing the commands.
Modules are written
through the commands
that are provided in this
programing paradigm.
Actions, which are defined in the
program, depends on events. These
events are initiated by different
means, which include mouse clicking
and moving, or keyboard strokes.
Commands, which are written in linear
fashion, are executed in linear fashion
as well. Therefore, both deigning and
execution of code follows linear
approach.
Objects and functions
that are considered for
interaction are required
for performing the
specific tasks (Yates
2016).
Proper Attention is provided in
choosing user interface. Therefore,
appropriate selection of the user
interface is an important requirement
in this programing paradigm.
It provides context for executing steps
of the program in proper sequence and
therefore sequential execution of steps
is one of the important features of this
programing paradigm (Liu and Petersen
2019).
It provides attention to
objects or data and it is
considered for increasing
security that allows to
ensure that it is secured
from unauthorized
access so that anyone
who does not have the
authority are not
allowed to access the
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
4BTEC HND in Computing
object or data
Most common languages that are
associated with this paradigm are
Visual Basic and C#.
Most common languages that are
associated with this paradigm are Basic,
Fortran and COBOL.
Most common languages
that are associated with
this paradigm are
Smalltalk, C++ and
JAVA.
The common features a developer can have access to IDLE:
Some of the common features, which develop, could access in IDLE are the followings:
It is coded in 100% python and it integrates the tkinter GUI toolkit
It provides cross-platform facilities and the performance is similar on Windows, Unix,
and macOS
Code input, output and error message are describe in colour
It provides multi-window editor that offers multiple undo, Python colorizing, smart
indent, call tips, auto completion, and other features (Liu and Petersen 2019).
it provides search facility within any window, replace within editor windows, and
search through multiple files (grep)
it provides debugger that offers persistent breakpoints, stepping, and viewing of
global and local namespaces
it provides configuration, browsers, and other dialogs
LO3
Program for calculating the salary of the employees;
Document Page
5BTEC HND in Computing
def main():
print('What would you like to do: ')
print('1.Calculate salary')
print('exit')
while True:
choice = input('Enter a Choice: ')
if choice == "1":
salcalc()
else:
break
def salcalc():
sales = 0.0
commissionRate = 0.0
salary=32000
totpay = 0.0
monthSales = 0.0
sales = getSales()
commissionRate = determineCommissionRate(sales)
totpay = (sales * commissionRate) +salary
print('The pay is $', format(totpay, '.2f'))
Document Page
6BTEC HND in Computing
if totpay < 0:
print('Invalid Input')
def getSales():
monthSales = 0.0
monthSales = input('Enter monthly sales of salesperson\'s: ')
return float(monthSales)
def determineCommissionRate(sales):
rate = 0.0
if sales < 500.00:
rate = 0
elif sales >= 500.00 and sales <= 2000.00:
rate = 0.05
elif sales >= 2000.00 and sales <= 5000.00:
rate = 0.09
elif sales >= 5000.00 and sales <= 10000.:
rate = 0.13
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
7BTEC HND in Computing
else:
rate = 0.20
return rate
Document Page
8BTEC HND in Computing
LO4
The process of debugging and debugging facilities of the chosen IDE:
The IDE chosen for this project is Spyder. The debugging process in Spyder is explained in
details in this context. In Spyder support for debugging is provided through the integration of
enhanced ipdb debugger and this is integrated with the IPython Console. This provides
developers opportunity to view breakpoints along with the flow of execution (Yates 2016).
Not only that, this also allows developers to control breakpoints and execution flow
effectively and that too from the Spyder GUI through the popular and common IPython
commands. Therefore, this is one of the most popular IDEs considered in Python.
Following is the screenshot that is carried out from the IDLE tool on the developed program;
Document Page
9BTEC HND in Computing
Following are the some of the errors that are encountered while developing the program;
Syntax error:
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
10BTEC HND in Computing
While inspecting the code, it is found that after declaring the function, it is important to place
an indent in order to follow the standard coding conventions which is depicted above. The
error is corrected by placing an indent after the declaration of the function.
Another error, found was type-error.
Document Page
11BTEC HND in Computing
In this case, the total salary of 32000 for every employee is assigned to a variable total pay.
The error occurred as the value is quoted with in the single quotes and represented as string.
This variable is then used for addition operation and lead to the error. Removing the single
quote helped to avoid this error.
Name error is another error faced in completing this program.
Due to the misspelling of a previously declared variable at a later point of time in the code
generated the error. Correcting the misspelled variable helped in removing the issue/error.
Lastly the zero division error is encountered. This error occurred due to the erroneous coding
and dividing the total salary by zero while trying to optimize and experiment with the code.
Removing divide by zero step, helped in removing the error. Following is the screenshot.
Debugging process with ipdb:
chevron_up_icon
1 out of 29
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]