Programming Assignment PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 100

Higher Nationals

Internal verification of assessment decisions – BTEC (RQF)


INTERNAL VERIFICATION – ASSESSMENT DECISIONS

Programme title Higher National Diploma in Computing

Assessor Internal Verifier

Unit(s)

Assignment title
Vitharana Gamage Gayan Praneeth
Student’s name
List which assessment criteria Pass Merit Distinction
the Assessor has awarded.

INTERNAL VERIFIER CHECKLIST

Do the assessment criteria awarded match


those shown in the assignment brief? Y/N

Is the Pass/Merit/Distinction grade awarded


justified by the assessor’s comments on the Y/N
student work?
Has the work been assessed
Y/N
accurately?
Is the feedback to the student:
Give details:
• Constructive?
• Linked to relevant assessment criteria? Y/N Y/N
• Identifying opportunities for Y/N
improved performance? Y/N
• Agreeing actions?
Does the assessment decision need
Y/N
amending?

Assessor signature Date

Internal Verifier signature Date


Programme Leader signature (if required)
Date
Confirm action completed
Remedial action taken

Give details:

Assessor signature Date

Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID Vitharana Gamage Gayan Praneeth

Unit Title
Assignment Number Assessor
Date Received 1st
Submission Date
submission
Date Received 2nd
Re-submission Date
submission
Assessor Feedback:

LO1. Define basic algorithms to carry out an operation and outline the process of programming an application.

Pass, Merit & Distinction Descripts P1 M1 D1

LO2. Explain the characteristics of procedural, object-orientated and event-driven programming, conduct an analysis of a suita
Integrated Development Environment (IDE).

Pass, Merit & Distinction Descripts P2 M2 D2

LO3. Implement basic algorithms in code using an IDE.

Pass, Merit & Distinction Descripts P3 M3 D3

LO4. Determine the debugging process and explain the importance of a coding standard.
Pass, Merit & Distinction Descripts P4 P5 M4 D4

Grade: Assessor Signature: Date:


Resubmission Feedback:

Grade: Assessor Signature: Date:

Internal Verifier’s Comments:

Signature & Date:

* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and
grades decisions have been agreed at the assessment board.
Assignment Feedback
Formative Feedback: Assessor to Student

Action Plan

Summative feedback

Feedback: Student to Assessor

Assessor Date
signature

Student signature Date


Pearson Higher Nationals in
Computing
Unit 01: Programming
Assignment 01
General Guidelines

1. A Cover page or title page – You should always attach a title page to your assignment. Use
previous page as your cover sheet and make sure all the details are accurately filled.
2. Attach this brief as the first section of your assignment.
3. All the assignments should be prepared using a word processing software.
4. All the assignments should be printed on A4 sized papers. Use single side printing.
5. Allow 1” for top, bottom , right margins and 1.25” for the left margin of each page.
Word Processing Rules

1. The font size should be 12 point, and should be in the style of Time New Roman.
2. Use 1.5 line spacing. Left justify all paragraphs.
3. Ensure that all the headings are consistent in terms of the font size and font style.
4. Use footer function in the word processor to insert Your Name, Subject, Assignment No, and
Page Number on each page. This is useful if individual sheets become detached for any
reason.
5. Use word processing application spell check and grammar check function to help editing your
assignment.
Important Points:

1. It is strictly prohibited to use textboxes to add texts in the assignments, except for the
compulsory information. eg: Figures, tables of comparison etc. Adding text boxes in the body
except for the before mentioned compulsory information will result in rejection of your work.
2. Carefully check the hand in date and the instructions given in the assignment. Late
submissions will not be accepted.
3. Ensure that you give yourself enough time to complete the assignment by the due date.
4. Excuses of any nature will not be accepted for failure to hand in the work on time.
5. You must take responsibility for managing your own time effectively.
6. If you are unable to hand in your assignment on time and have valid reasons such as illness,
you may apply (in writing) for an extension.
7. Failure to achieve at least PASS criteria will result in a REFERRAL grade .
8. Non-submission of work without valid reasons will lead to an automatic RE FERRAL. You will
then be asked to complete an alternative assignment.
9. If you use other people’s work or ideas in your assignment, reference them properly using
HARVARD referencing system to avoid plagiarism. You have to provide both in-text citation
and a reference list.
10. If you are proven to be guilty of plagiarism or any academic misconduct, your grade could be
reduced to A REFERRAL or at worst you could be expelled from the course
Student Declaration

I hereby, declare that I know what plagiarism entails, namely to use another’s work and to present it
as my own without attributing the sources in the correct way. I further understand what it means to
copy another’s work.

1. I know that plagiarism is a punishable offence because it constitutes theft.


2. I understand the plagiarism and copying policy of the Edexcel UK.
3. I know what the consequences will be if I plagiaries or copy another’s work in any of the
assignments for this program.
4. I declare therefore that all work presented by me for every aspects of my program, will be my
own, and where I have made use of another’s work, I will attribute the source in the correct
way.
5. I acknowledge that the attachment of this document signed or not, constitutes a binding
agreement between myself and Edexcel UK.
6. I understand that my assignment will not be considered as submitted if this document is not
attached to the attached.

Student’s Signature: Date:


(Provide E-mail ID) (Provide Submission Date)
Higher National Diploma in Computing
Assignment Brief
Student Name /ID Number V.G.Gayan Praneeth

Unit Number and Title Unit 01: Programming

Academic Year 2021/22

Unit Tutor

Assignment Title Design &Implement a GUI based system using a suitable


Integrated Development Environment

Issue Date

Submission Date

IV Name & Date

Submission Format

This submission will have 3 components

1. Written Report
This submission is in the form of an individual written report. This should be written in a concise, formal
business style using single spacing and font size 12. You are required to make use of headings, paragraphs
and subsections as appropriate, and all work must be supported with research and referenced using the
Harvard referencing system. Please also provide a bibliography using the Harvard referencing system. (The
recommended word count is 1,500–2,000 words for the report excluding annexures)

2. Implemented System (Software)


The student should submit a GUI based system developed using an IDE. The system should connect with a
backend database and should have at least 5 different forms and suitable functionality including insert, edit
and delete of main entities and transaction processing.

3. Presentation
With the submitted system student should do a presentation to demonstrate the system that was
developed. Time allocated is 10 to 15 min. Student may use 5 to 10 PowerPoint slides while doing the
presentation, but live demonstration of the system is required. Evaluator will also check the ability to modify
and debug the system using the IDE.

Unit Learning Outcomes:


LO1. Define basic algorithms to carry out an operation and outline the process of
programming an application.

LO2. Explain the characteristics of procedural, object-orientated and event-driven


programming.

LO3. Implement basic algorithms in code using an IDE.

LO4. Determine the debugging process and explain the importance of a coding
standard
Assignment Brief and Guidance:

Activity 1

A. The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence
relation.

Fn = F n-1 + F n-2

B. Factorial of a non-negative integer, is multiplication of all integers smaller than or equal


to n. For example, factorial of 6 is 6*5*4*3*2*1 which is 720.
n! = n * (n - 1) * …….. 1

Define what an algorithm is and outline the characteristics of a good algorithm. Write the
algorithms to display the Fibonacci series and the factorial value for a given number using
Pseudo code. Determine the steps involved in the process of writing and executing a program
and carry out an analysis of writing the code phase by discussing the potential challenges
faced.
Take a sample number and dry run the above two algorithms. Show the outputs at the end of
each iteration and the final output. Examine what Big-O notation is and explain its role in
evaluating efficiencies of algorithms. Write the Python program code for the above two
algorithms and critically evaluate their efficiencies using Big-O notation.

Activity 2
2.1 Compare and discuss what is meant by a Programming Paradigm and the main
characteristics of Procedural, Object oriented and Event-driven paradigms and the
relationships among them. Write small snippets of code as example for the above three
programming paradigms using a suitable programming language(s) and critically
evaluate the code samples that you have given above in relation to their structure and
the unique characteristics.

Activity 3 and Activity 4 are based on the following Scenario.

Grifindo Toys is a small-scale Toy building company which is located in United Kingdom (UK)
and currently they have 50 employees working at their headquarters. They are looking for a
simple payroll system to calculate the salaries of their employees and you are hired as a
freelance software developer to build their payroll system.
Specifications for the payroll system as follows,

Grifindo Toys Payroll System mainly contains five components and the specifications for the
components are follows,
1. Employee Component.
• Admin should be able to register employee details to the system (including
monthly salary, overtime rates-hourly, allowances).
• Admin should be able to update all employee details in the system (Update and
Delete including monthly salary, overtime rates-hourly, allowances).
• Admin should be able to view individual employee details, view all employees
details, search employees.
2. Salary Component
Admin should be able to input the date range to calculate the salary. Salary cycle begin date and
the end date should be given to calculate the monthly salary. Salary cycle begin date and end
date will be defined in the settings component and if the user enters something else the system
should display an error message.
The admin should be able to enter the no of leaves an employee has taken with number of absent
days, no of holidays for the given date range. If an employee has worked any overtime hours the
admin should be able to enter that also when calculating the Base pay value.
Base Pay need to calculate based on the following points,

Base Pay (Monthly Salary: salary_cycle_date_range, eg: 30 days): Each employee will be paid
monthly
If any employee couldn’t cover salary_cycle_date_range (eg:-30 days) attendance the system
should calculate the no-pay value according to the below mention formula,

No-pay-value = (Total_Salary/salary_cycle_date_range) *No_of_absent_days

Base Pay need to calculate according to the below mentioned formula


Base Pay value = Monthly_Salary + Allowances +
(Over_time_rate*no_of_overtime_hours)
Gross Pay need to calculate according to the below mentioned formula
Gross Pay = Base_Pay_value – (No_pay_value + Base_Pay_value*government_tax_rate)

All the calculated No-pay-value, Base-pay-value and Gross pay value should record in the
database under each employee for each month. This component should generate reports such as
monthly salary report for an employee, overall salary summary for couple of months for an
employee, No-pay-value, base-pay-value, and gross pay value of all the employees for a given
month range.

3. Settings Component
This component should allow the admin to change parameter values such as
i. Date Range for a salary cycle. Eg:- 30 days
ii. Salary cycle begin date
iii. Salary cycle end date
iv. No of leaves for an employee for a year.

Activity 3

Write the complete pseudocode for the salary component of the above system (report generation
is not needed). Use the visual studio IDE (using C#.net) to implement the above three
components. Ideally there should be three separate classes for the above three components and
the developer can decide the methods which need to include in those classes. Design the suitable
database structure for keeping the data of the above system.
Analyze the features of an Integrated Development Environment (IDE) and explain how those
features help in application development. Evaluate the use of the Visual StudioIDE for your
application development contrasted with not using an IDE.
Activity 4
4.1 Design and build a small GUI system for the above scenario and it should be a complete
functional system with all the functions which has described in the above scenario with the
database structure which has designed in activity 3.
4.2 Examine debugging process and the features available in Visual studio IDE for debugging
your code more easily. Evaluate how you used the debugging process to develop more
secure, robust application with examples.
4.3 Explain and outline the coding standards you have used in your application development.
Critically evaluate why a coding standard is necessary for the team as well as for the
individual.
Grading Rubric

Grading Criteria Achieved Feedback

LO1 Define basic algorithms to carry out an operation


and outline the process of programming an
application.

P1 Define an algorithm and outline the process in building an


application

P2 Determine the steps taken from writing code to


execution.

M1 Analyse the process of writing code, including the


potential challenges faced.
D1 Evaluate the implementation of an algorithm in a suitable
language and the relationship between the written algorithm
and the code variant

LO2 Explain the characteristics of procedural, object


orientated and event-driven programming

P3 Discuss what procedural, object orientated and event


driven paradigms are; their characteristics and the
relationship between them.

M2 Compare the procedural, object-orientated and event


driven paradigms used in given source code of an application
D2 Critically evaluate the source code of an application that
implements the procedural, object-orientated and event-
driven paradigms, in terms of the code structure and
characteristics.
LO3 Implement basic algorithms in code using an IDE.

P4 Write a program that implements an algorithm using an


IDE.

M3 Enhance the algorithm written, using the features of the


IDE to manage the development process.
D3 Evaluate the use of an IDE for development of
applications contrasted with not using an IDE.

LO4 Determine the debugging process and explain the


importance of a coding standard

P5 Explain the debugging process and explain the debugging


facilities available in the IDE.

P6 Explain the coding standard you have used in your code.

M4 Examine how the debugging process can be used to help


develop more secure, robust applications.
D4 Evaluate the role and purpose of a coding standard and
why it is necessary in a team as well as for the individual.
Table of Content
1 What is an algorithm? .............................................................................................................. 31

2 Characteristics of a good algorithm. ........................................................................................ 32

2.1 Input ..................................................................................................................................... 32

2.2 Output .................................................................................................................................. 32

2.3 Unambiguity ........................................................................................................................ 32

2.4 Finiteness ............................................................................................................................. 32

2.5 Effectiveness ........................................................................................................................ 32

2.6 Language Independence....................................................................................................... 32

3 The Fibonacci sequence ........................................................................................................... 33

3.1 Understanding the problem .................................................................................................. 33

3.1.1 Input: ........................................................................................................................ 33

3.1.2 The function and the termination of the algorithm .................................................. 33

3.1.3 The output ................................................................................................................ 34

3.2 The flowchart ....................................................................................................................... 34

3.3 The algorithm for the Fibonacci sequence ........................................................................... 35

4 Factorial numbers..................................................................................................................... 36

4.1 Understanding the problem and the input ............................................................................ 36

4.2 The function of the algorithm .............................................................................................. 37

4.3 The output ............................................................................................................................ 37

4.4 The flowchart ....................................................................................................................... 38

4.5 The algorithm for the Factorial Number .............................................................................. 39

5 Pseudocode .............................................................................................................................. 40

5.1 Pseudocode for the Fibonacci sequence .............................................................................. 40

5.2 Pseudocode for the factorial numbers .................................................................................. 40

6 The process of writing a program ............................................................................................ 41

6.1 Defining the problem ........................................................................................................... 41

V.G.Gayan Praneeth Programming Page 22 of 100


6.2 Algorithm design ................................................................................................................. 41

6.3 Coding the program ............................................................................................................. 41

6.4 Testing the program ............................................................................................................. 42

6.5 Documenting the program ................................................................................................... 42

7 Potential challenges faced in the code writing phase............................................................... 43

8 Dry running the algorithms ...................................................................................................... 44

8.1 Fibonacci Numbers .............................................................................................................. 44

8.2 Factorial Number ................................................................................................................. 46

9 The Big-O notation .................................................................................................................. 48

9.1 O(1) Constant time............................................................................................................... 48

9.2 O(n) Linear Time ................................................................................................................. 49

9.3 O(n2) Quadratic Time .......................................................................................................... 49

9.4 O(log n) Logarithmic Time .................................................................................................. 49

9.5 O(n!) Exponential Time ....................................................................................................... 50

10 Coding the algorithms in Python ............................................................................................. 51

10.1 Fibonacci sequence ............................................................................................................ 51

10.2 Factorial values .................................................................................................................. 53

11 Differences in the code and the algorithm, the efficiency of the programs in reference to the
Big-O notation. ........................................................................................................................ 54

11.1 Differences in the algorithm and the code. ........................................................................ 54

11.2 Efficiency with the Big-O notation. ................................................................................... 54

11.2.1 Fibonacci .................................................................................................................. 54

11.2.2 Factorial ................................................................................................................... 54

12 Programming paradigms .......................................................................................................... 55

12.1 Procedural programming ................................................................................................... 56

12.2 Object Oriented Programming ........................................................................................... 57

12.3 Event Driven Programming ............................................................................................... 58

V.G.Gayan Praneeth Programming Page 23 of 100


13 Critical evaluation of programming paradigms. ...................................................................... 61

14 Developing the Griffindo Toys Payroll System....................................................................... 62

14.1 Understanding the requirements of the Client. .................................................................. 62

14.1.1 The employee details ............................................................................................... 62

14.1.2 Payment details ........................................................................................................ 62

14.1.3 Settings..................................................................................................................... 62

14.1.4 Login Information .................................................................................................... 62

14.2 The ER diagram ................................................................................................................. 63

14.3 Creating the database ......................................................................................................... 64

14.3.1 The Employees table ................................................................................................ 64

14.3.2 Salaryinfo Table ....................................................................................................... 64

14.3.3 Settings Table........................................................................................................... 65

14.3.4 Login Table .............................................................................................................. 65

15 Pseudocode of the setting component ...................................................................................... 66

15.1 Pseudocode for the Refresh button .................................................................................... 67

15.2 Pseudocode of the Update button ...................................................................................... 68

16 How an IDE helps programming with its features................................................................... 69

16.1 What is an IDE? ................................................................................................................. 69

16.2 When not to use an IDE? ................................................................................................... 70

16.3 Advantages and Disadvantage of an IDE .......................................................................... 71

16.4 Using Visual Studio to create the program ........................................................................ 71

17 The system ............................................................................................................................... 74

17.1 The login interface ............................................................................................................. 74

17.1.1 The code of the Login Interface ............................................................................... 74

17.2 The dashboard .................................................................................................................... 75

17.2.1 The code of the dashboard ....................................................................................... 75

17.3 The employee component .................................................................................................. 76

V.G.Gayan Praneeth Programming Page 24 of 100


17.3.1 Code for search by ID .............................................................................................. 76

17.3.2 Code for search by NIC ........................................................................................... 77

17.3.3 Code for the Register button .................................................................................... 77

17.3.4 Code for the Update button ...................................................................................... 78

17.3.5 Code for the Delete button ....................................................................................... 78

17.4 The salary Component ....................................................................................................... 79

17.4.1 The Salary calculation class ..................................................................................... 79

17.4.2 Code for the refresh button ...................................................................................... 80

17.4.3 Code for the calculate button ................................................................................... 81

17.4.4 Code for the Pay button ........................................................................................... 81

17.5 The settings component ..................................................................................................... 82

17.6 The reports section ............................................................................................................. 82

17.6.1 Load all employees .................................................................................................. 83

17.6.2 Full Salary history .................................................................................................... 84

17.6.3 Salary history by month ........................................................................................... 84

17.6.4 All salary payments within the date range ............................................................... 85

17.6.5 Search Employee details .......................................................................................... 85

17.6.6 Salary history ........................................................................................................... 86

17.6.7 Employee monthly salary ........................................................................................ 86

17.6.8 Employee Salary History ......................................................................................... 87

17.7 The classes and methods created for the program ............................................................. 88

17.7.1 Connection manager ................................................................................................ 88

17.7.2 Salary calculation ..................................................................................................... 89

17.8 The advantage of using classes and methods ..................................................................... 89

18 Debugging ................................................................................................................................ 91

18.1 Using Breakpoints .............................................................................................................. 91

18.2 Using step into tools........................................................................................................... 92

V.G.Gayan Praneeth Programming Page 25 of 100


18.3 Run to click ........................................................................................................................ 93

18.4 How debugging features were used to develop the program and make it better ............... 94

19 Coding standards used in this program .................................................................................... 95

19.1 Naming conventions .......................................................................................................... 95

19.2 Classes and methods .......................................................................................................... 96

19.3 Using comments................................................................................................................. 97

19.4 How coding standards help the programming process ...................................................... 98

20 References ................................................................................................................................ 99

V.G.Gayan Praneeth Programming Page 26 of 100


Table of Figures
Figure 1: What is an algorithm ...................................................................................................... 31
Figure 2: The Fibonacci Numbers Formula ................................................................................... 33
Figure 3: The flowchart for the Fibonacci sequence ..................................................................... 34
Figure 4: Calculating factorial numbers ........................................................................................ 36
Figure 5: Factorial number calculation explained ......................................................................... 37
Figure 6: The flowchart for the Factorial Numbers ....................................................................... 38
Figure 7: Big-O time complexity ................................................................................................... 48
Figure 8: Python code for Fibonacci sequence .............................................................................. 51
Figure 9: Testing 5 as an input in Fibonacci numbers ................................................................... 51
Figure 10: Testing 10 as an input in Fibonacci numbers ............................................................... 52
Figure 11: Testing 15 as an input in Fibonacci numbers ............................................................... 52
Figure 12: Python code for Factorial numbers .............................................................................. 53
Figure 13: Testing 5 as an input in Factorial numbers .................................................................. 53
Figure 14: Testing Factorial numbers using 10 as an input ........................................................... 53
Figure 15: Common Programming paradigms .............................................................................. 55
Figure 16: Code example for Procedural Programming ................................................................ 56
Figure 17: Sample code executed. Procedural ............................................................................... 56
Figure 18: The class book and various objects (books) are created in this block of code ............. 57
Figure 19: Program execution example for OOP .......................................................................... 58
Figure 20: Sample interface for EDP demonstration ..................................................................... 59
Figure 21: Event driven programming coding example ................................................................ 59
Figure 22: Running the EPD demonstration program ................................................................... 60
Figure 23: Entity Relationship diagram of Griffindo Toys Payroll system ................................... 63
Figure 24: Creating the Employees table ....................................................................................... 64
Figure 25: Creating the Salaryinfo table ........................................................................................ 64
Figure 26: Creating the settings table ............................................................................................ 65
Figure 27: Creating the Login table ............................................................................................... 65
Figure 28: The settings component ................................................................................................ 66
Figure 29: IDEs and their languages .............................................................................................. 69
Figure 30: The server explorer and the Solution explorer ............................................................. 71
Figure 31: The toolbox and the events tab ..................................................................................... 72
Figure 32: Visual Studio Suggesting a code .................................................................................. 72
Figure 33: Visual studio showing potential fixes .......................................................................... 73

V.G.Gayan Praneeth Programming Page 27 of 100


Figure 34: The login page .............................................................................................................. 74
Figure 35: Logging in .................................................................................................................... 74
Figure 36: The code of the Login Interface ................................................................................... 74
Figure 37: The Dashboard ............................................................................................................. 75
Figure 38: The code of the dashboard............................................................................................ 75
Figure 39: Employee management interface ................................................................................. 76
Figure 40: Search by ID button code ............................................................................................. 76
Figure 41: Search by NIC button code .......................................................................................... 77
Figure 42: The code of the register button ..................................................................................... 77
Figure 43: Code for the Update button .......................................................................................... 78
Figure 44: Code for the delete button ............................................................................................ 78
Figure 45: Salary component ......................................................................................................... 79
Figure 46: The Salary Calculation class ........................................................................................ 80
Figure 47:Code for the refresh button ............................................................................................ 80
Figure 48: Code for the Calculate button ....................................................................................... 81
Figure 49: The code for the Pay button ......................................................................................... 81
Figure 50: Settings Component ..................................................................................................... 82
Figure 51:Reports Section.............................................................................................................. 83
Figure 52: Code for load all employees ......................................................................................... 83
Figure 53: Code for Loading full salary history ............................................................................ 84
Figure 54: Code for Salary history by month ................................................................................ 84
Figure 55: Code for All salary payments within the date range .................................................... 85
Figure 56: Code for Search all employee details ........................................................................... 85
Figure 57: Code for Salary history................................................................................................. 86
Figure 58: Code for Employee monthly salary .............................................................................. 86
Figure 59: Code for Employee Salary History .............................................................................. 87
Figure 60: The method Get Connection and its values .................................................................. 88
Figure 61: The connection string has been added to App Config to be used in the class.............. 88
Figure 62: Salary Calculation class and the methods inside .......................................................... 89
Figure 63: Using the GetConeection method................................................................................. 90
Figure 64: Using the methods of Salary Calculation to calculate salary ....................................... 90
Figure 65: Setting a breakpoint ...................................................................................................... 91
Figure 66: The step into tools ........................................................................................................ 92
Figure 67: Step into tools magnified .............................................................................................. 92

V.G.Gayan Praneeth Programming Page 28 of 100


Figure 68; Debugger showing current values of a selected line .................................................... 93
Figure 69: Run to Click.................................................................................................................. 93
Figure 70: Using the debugger to see the current values of variables ........................................... 94
Figure 71: Naming buttons ............................................................................................................ 95
Figure 72: Named textboxes and the button makes the code easy to understand .......................... 95
Figure 73: Methods relating to calculations................................................................................... 96
Figure 74: Method relating to connections .................................................................................... 96
Figure 75: Using comments ........................................................................................................... 97
Figure 76: Using Comments .......................................................................................................... 97

V.G.Gayan Praneeth Programming Page 29 of 100


Table of Tables
Table 1: Fibonacci numbers dry run .............................................................................................. 45
Table 2: Factorial numbers dry run ................................................................................................ 47
Table 3: Advantages and disadvantages of Procedural programming ........................................... 57
Table 4: Events list and actions of those events ............................................................................ 60
Table 5: Advantages and Disadvantages of an IDE....................................................................... 71

V.G.Gayan Praneeth Programming Page 30 of 100


1 What is an algorithm?
An algorithm is a set of instructions which would be executed one by one with the ultimate
goal of solving a problem. It can also be described as a type of procedure which can be used
for the performing a computation or as a means to solve a problem. (Gillis, 2022)
In the fields of IT, mathematical and computer sciences, algorithms are commonly used for
problem solving purposes. Usually, algorithms start with an initial input and if the input is
expected, the algorithm proceeds in providing an output.
These can be articulated in programming languages, natural languages, flowcharts,
pseudocode and control tables. Even though programming languages are the most common
use cases for algorithms, there are instances of algorithms being used in natural languages as
well but the ambiguity of them can be very high.

Figure 1: What is an algorithm

V.G.Gayan Praneeth Programming Page 31 of 100


2 Characteristics of a good algorithm.
Algorithms should have a number of characteristics to make them good algorithms. Having
most or all of them would enable the algorithm to solve the problem effectively and efficiently
(Upadhyay, 2022). These are,
2.1 Input
As the algorithm starts with an initial input, it should have 0 or more well defined inputs.
Having precision over the required kind of data as the input is essential to have a valid input
for an algorithm.
2.2 Output
Similar to the input, the output should also be well defined, and it should match with the
desired output. The creator or user of the algorithm should have an understanding about the
type of the output as well as the knowledge of cases where there will be no output as well.
2.3 Unambiguity
The algorithm and its functions as well as the intended use should be clear and unambiguous.
In simple terms, the steps of the algorithm should be straightforward and maintain clarity.
2.4 Finiteness
The steps of the algorithm should be limited and finite. This means the algorithm should have
a countable number of steps or instructions. Needless to say that if the algorithm has an
infinite amount of steps, it would never give an output.
2.5 Effectiveness
An effective algorithm should have absolute necessary steps. All steps should have their
intended use or a specific reason to remain in the algorithm. There should be no unnecessary
steps in the algorithm which would lead to wastage of time and resources.
2.6 Language Independence
Even though most algorithms are aimed at running in a computer software, in the form of a
code in a programming language, it should not be biased to one programming language. A
good algorithm should be able to be implemented into any programming language.

V.G.Gayan Praneeth Programming Page 32 of 100


3 The Fibonacci sequence
Named after an Italian mathematician, Leonardo Pacino, who lived between 1170 to 1250AD,
the Fibonacci numbers are a sequence of numbers that starts with 0, and 1. Afterwards, the
next umber of the sequence is created by adding the two previous numbers together.
It can be defines using the following formula,

Figure 2: The Fibonacci Numbers Formula

3.1 Understanding the problem


To create an algorithm that can output the “n” number of Fibonacci numbers, the input, the
process and the output needs to be clearly defined.
3.1.1 Input:
The input should be the needed number of Fibonacci instances. This can be the ‘n’ number of
instances. For example, if we need the 5th number in the sequence, the ‘n’ should be 5. So,
the result of that would be
(n1) 0 The first two numbers are always 0 and 1
(n2) 1 The next number is the total of the previous two numbers.
(n3) 0+1 = 1 This needs to continue until the ‘n’ number reaches 5
(n4) 1+1 = 2
(n5) 1+2 = 3 The 5th number in the sequence is 3.

3.1.2 The function and the termination of the algorithm


The algorithm should start with the first number, second number and the needed numbers in
the sequence (n). The process of adding the two previous numbers should continue until the
n number reaches the desired number from 0. Therefore, there should be a counting
mechanism to count how many times the formula has been executed.

V.G.Gayan Praneeth Programming Page 33 of 100


3.1.3 The output
At the point here the n reaches the desired number, the algorithm should stop displaying the
numbers on the screen.

3.2 The flowchart


To understand the sequence easily, the following flowchart can be used.

Figure 3: The flowchart for the Fibonacci sequence

V.G.Gayan Praneeth Programming Page 34 of 100


3.3 The algorithm for the Fibonacci sequence

Step 1: Get the input for the number (N) of instances needed on the Fibonacci sequence

Step 2: Define integers and values for the counter (C = 0), First Number (F1 = 0), the
Second number (F2 = 1) and the Next number (Next = 0)

Step 3: Output the first default values 0 and 1

Step 4: Check the counter (C) is less than the Input number (num) if so, go to next step. If
not, End the programme. Since the first two numbers are already displayed, who instances
have been removed from the number

Step 5: Set the Value of Next to the sum of F1 and F2

Step 6: Output the value of Next

Step 7: Add one to the counter.


Change the value of F2 to the value of Next
Change the value of F1 to the value of F2

Step 8: Go back to step 4

V.G.Gayan Praneeth Programming Page 35 of 100


4 Factorial numbers
Factorial numbers are a multiplication of all digits of integers smaller than or equal to the
selected number. As an example, the factorial of 5 is 120.
Factorial of 5 = 5*4*3*2*1 = 120

Figure 4: Calculating factorial numbers

4.1 Understanding the problem and the input


The algorithm should get an initial number, which would also be the input and multiply to it
each digit deducted by 1 in a descending order. In this case, a counter is needed to find out
whether the number has reached the end of the sequence and another instance to store a value
of a previous two multiplications.

V.G.Gayan Praneeth Programming Page 36 of 100


4.2 The function of the algorithm
As the input is the determinant of the counter and the multiplier, the sequence needs to go on
until the multiplier and the counter are equal to one another.

Figure 5: Factorial number calculation explained

4.3 The output


As mentioned above, as the counter and the multiplier become equal, the algorithm should
display the stored value and terminate the sequence.

V.G.Gayan Praneeth Programming Page 37 of 100


4.4 The flowchart

Figure 6: The flowchart for the Factorial Numbers

V.G.Gayan Praneeth Programming Page 38 of 100


4.5 The algorithm for the Factorial Number

Step 1: Input the number than needs to be shown in the factorial (Num)

Step 2: Define the counter (C=1) and the multiplier (M=1)

Step 3: Check whether the Counter is lower or equal to the Input Number. If not, Output the
Value of M and End the programme. If so, go to the next step.

Step 4: Make the calculation and define the new value of M multiplied by the counter.
(M = M*C)
Step 5: Increment the counter by 1. (C = C+1)

Step 6: Go back to Step 3

V.G.Gayan Praneeth Programming Page 39 of 100


5 Pseudocode
Pseudocode is a way of writing a code in a way that people who are unfamiliar with coding
would understand the programme or the algorithm. This can also be defined as writing a code
or an algorithm in a style closer to a natural language rather than in complete tech references.
(Ubah, 2021)
Writing a programme or an algorithm in pseudocode now only allows the programmer to
express their proceedings to anyone with relative ease, it also acts as a supporting structure
to write the code based on the algorithm.
5.1 Pseudocode for the Fibonacci sequence
Start
Input n ("Please enter the number of instances you need ")
define variables int f1=0, f2=1, Next = 0, c=0
print ("The Fibonacci sequence is ")
Print the first two numbers f1 and f2
while the counter(c) is less than input (number - 2)
next = f1 + f2
print (Next)
f1 = f2
f2 = Next
increment counter by 1
End

5.2 Pseudocode for the factorial numbers


Start
Input num ("Please input our number ")
define variables m =1, c=1
if the counter(c) is not lower or equal than input (number)
m = m*c
increment counter by 1
else
output m
End

V.G.Gayan Praneeth Programming Page 40 of 100


6 The process of writing a program
A computer program is conceptualized to complete an intended task or to solve a designated
problem. To get a viable solution to the problem or to get the desired task completed
successfully, writing a programme cannot be done haphazardly. It has to have some organized
and strategized process to make it successful. Therefore, the steps to write a successful
program is as follows (The University of Rhode Island, n.d.).

6.1 Defining the problem


At the end of the day, finding the solution for the problem is the reason why someone hires a
software engineer. So, the most important task comes even before a single line of code is
written. It is to understand the problem which needs the solution. The programmes should be
aware of the input, the process which needs to drive and manipulate the input and the output.
This process of understanding the Input, Process and Output is called the IPO method.

6.2 Algorithm design


Also known as planning the solution, this step requires utilizing flowcharts and pseudocodes
to get a clear and detailed idea about the prepared solution. As mentioned above in previous
topics, having the algorithm as a visual representation in a flowchart clearly helps in tweaking
the algorithm to fit the need perfectly.
Apart form the algorithm, the programmer could also use pseudocodes to get the algorithmic
idea in a more natural language setting. This allows the algorithm to be understood by people
who have no programming experience and contribute their viewpoints and experiences to
create a better product.

6.3 Coding the program


After understanding the problem and creating a viable solution for it using flowcharts and
pseudocode, then comes the phase where the coding process begins. For this, a programming
language such as c#, python, java or others can be used. These have functions and methods
to implement the logical bast created in the planning process into the programme.
Though most programming languages have basic characteristics similar to the spoken
language, they are less ambiguous and more precise thanks to the syntaxes the language has.
The programmer has to be thoroughly aware about the syntaxes and other specificities in
order to yield the maximum potential of the programming language.

V.G.Gayan Praneeth Programming Page 41 of 100


6.4 Testing the program
In reality, it is rare to see a program running smoothly and as expected just after it emerges
out of the coding process. Errors and bugs are abundant, and they needed to be sought out
because they can impede the performance of the program. Furthermore, finding bugs and
fixing them allows the programmer to remove the said weaknesses and make their program
more reliable and efficient. Furthermore, after a testing process, the programmer might get
insight about how to further develop the program to maximize performance and efficiency.
There are many ways to find the errors in a program and some of them can be debugging,
desk checking and translating.
Since most programming IDEs have inbuilt debugging tools and text editors, most
programmers use these to find the logical errors, syntax errors and other imperfections in their
code. Sometimes testing can be a tedious time-consuming task. But done systematically, it
could generate productive results.

6.5 Documenting the program


Documentation means maintaining detailed descriptions, blueprints, and other relevant facts
about a program in written media. As a program is a complicated construction, documenting
helps the related parties who are in the user and development sides of the program to
understand its functions, uses and everything else the need to know.
Programming languages have a designated comment feature for this, and these help the
programmer to keep notes about the program as they code. All the prior preparation such as
the algorithm, the flowchart and the pseudocode also fall into the category of documentation.
Having a clear documenting process throughout the planning, coding and testing processes
and all other steps of the programming life cycle enables the programmer to make
improvements to the program easily and if there is a team of developers involved in the
process, everyone can have a complete idea about the program, and it helps to add efficiency
to the team dynamic.

V.G.Gayan Praneeth Programming Page 42 of 100


7 Potential challenges faced in the code writing phase

Writing code is a systematic and strategic process which needs more preparation time than
the actual coding itself. If the programmer is fully equipped with all the information he needs,
coding the program would face less challenges and hindrances.
Therefore, breaking down the problem from an abstract idea to a specific definition is one of
the important steps in the process. By doing this, the programmer can have a clear vision as
to what he needs to do to solve the problem. If this step fails, the entire process can be faulty.
After the problem is thoroughly broken down and the algorithm is created, using an actual
programming language is the next part of the puzzle which needs to be taken care of. Though
most programming languages are similar to natural language, they are not completely similar
and can have differences with various methods and syntaxes. Translating the algorithm into
the proper programming language can be challenging especially when the problem is
complicated and has a lot of intricacies within.
As each programming language has its way of writing, the actual coding lines can differ from
the algorithm and pseudocode which were prepared beforehand leading to complications.
Sometimes, there can be easier ways to achieve the desired goal and the programmer might
not be aware of this.
Apart from these internal factors, there are a number of external factors that could come into
play when writing code. The resources the programmer has, i.e., the processing capabilities
of the system they use can have a direct effect on the programming phase. The timeline can
also pose a challenge because most of the time, programmers have to work under tight
deadlines and this might be negatively affecting the coding process.

V.G.Gayan Praneeth Programming Page 43 of 100


8 Dry running the algorithms
8.1 Fibonacci Numbers
The 5th number of the Fibonacci numbers is 3
0,1,1,2,3
Step 1: Get the Step 2: Define Step 3: Output Step 4: Check Step 5: Set the Step 6: Output Step 7: A dd Step 8: Go
input for the integers and the first the counter (C) Value of Next the value of one to the back to step
number (N) of values for the default values is less than the to the sum of Next counter. 4
instances counter 0 and 1 Input number F1 and F2 Change the
needed on the (C = 0), (num) if yes, go value of F2
Fibonacci First Number to next step. If to the value
sequence (F1 = 0), no, End the of Next
Second programme. Change the
number Since the first value of F1
(F2 = 1) and two numbers are to the value
the Next already of F2
number displayed, who
(Next = 0) instances have
been removed
from the number

Input 5 C=0 Print 0 C< N-2 Next = F1 + F2 Print value of C=C+1


N=5 F1 = 0 Print 1 0<5-2 Next = 0 + 1 Next C=0+1
F2 = 1 0<3 Next = 1 Next = 1 C=1
Next = 0 Yes Print 1
F2 = Next
F2 = 1

F1 = F2
F1 = 1

V.G.Gayan Praneeth Programming Page 44 of 100


C< N-2 Next = F1 + F2 Print value of C=C+1
1<5-2 Next = 1 + 1 Next C=1+1
1<3 Next = 2 Next = 2 C=2
Yes
Print 2 F2 = Next
F2 = 2

F1 = F2
F1 = 1
C< N-2 Next = F1 + F2 Print value of C=C+1
2<5-2 Next = 2+ 1 Next C=2+1
2<3 Next = 3 Next = 3 C=3
Yes
Print 3 F2 = Next
F2 = 3

F1 = F2
F1 = 2
C< N-2
3<5-2
3<3
No

End the Program

At the end of the run, the program has output the following values. There are 5 numbers and the 5th one is 3.
0
1
1
2
3
Table 1: Fibonacci numbers dry run

V.G.Gayan Praneeth Programming Page 45 of 100


8.2 Factorial Number
The factorial value of 5 is 5*4*3*2*1 = 120
The algorithm should produce the value 120 at the end of the run.
Step 1: Input the Step 2: Define the Step 3: Check Print the value Step 4: Make Step 5: Step 6: Go
number than needs to counter (C=1) and whether the of M if the the calculation Increment the back to
be shown in the the multiplier Counter is lower logical check and define the counter by 1. Step 3
factorial (Num) (M=1) or equal to the does not meet new value of M (C = C+1)
multiplier. If not, the parameters. multiplied by
Output the Value the counter.
of M and End the (M = M*C)
programme. If so,
go to the next
step.

Input ‘5’ C = 1 , M =1 C<=Num Skip C = 1, M = 1 C = C+1


Num = 5 1<=5 M = C*M C = 1+1
(The condition M = 1*1 C=2
meets and goes to M=1
the next step)
C<= Num Skip C = 2, M = 1 C = C+1
2<=5 M = C*M C = 2+1
(The condition M = 2*1 C=3
meets and goes to M=2
the next step)

C<= Num Skip C = 3, M = 2 C = C+1


3<=5 M = C*M C = 3+1
(The condition M = 3*2 C=4
meets and goes to M=6
the next step)

V.G.Gayan Praneeth Programming Page 46 of 100


C<= Num Skip C = 4, M = 6 C = C+1
4<=5 M = C*M C = 4+1
(The condition M = 4*6 C=5
meets and goes to M = 24
the next step)
C<= Num Skip C = 5, M = 24 C = C+1
5<=5 M = C*M C = 5+1
(The condition M = 5*24 C=6
meets and goes to M = 120
the next step)
C<=M Print 120
6<=5
The condition no
longer meets the
parameter.
Printing M.
End Program
Table 2: Factorial numbers dry run

V.G.Gayan Praneeth Programming Page 47 of 100


9 The Big-O notation
The big-O notation is a method to calculate the efficiency of an algorithm depending on a
number of variables such as space or time. For this explanation, the time complexity of the
big-O notation is considered (Lovett, 2020).

Figure 7: Big-O time complexity

In this graph, the horizontal axis represents the size of the input, and the vertical axis
represents the time the program takes to process the input. If the curve is close to parallel to
the horizontal axis, it means the algorithm, or the program takes the same amount of time to
process any amount of input. If the curve is parallel to the vertical axis, this means the
algorithm will take exponential time to process the input. So, Big-O notation states that the
less time it takes an algorithm to run a process, the better its runtime complexity value is.
As described in the above graph, there are several Big-O cases that can be seen in an
algorithm.

9.1 O(1) Constant time


This means the algorithm will run in the same amount of the time even if the input changes
in size. In real world, of a truck takes an hour to deliver 1kg of good to a destination, it would
also take the truck 1 hour to deliver 100kg of good to the same destination.
In programming, this means if the program would take 1 second to process 1 input, it would
also take 1 second to process 100 inputs. The program will take the same amount of time to
find the 1st value of an array or the 100th value on an array.
In programming, math operations, returning a value from a function, accessing an array using
an index are constant.

V.G.Gayan Praneeth Programming Page 48 of 100


9.2 O(n) Linear Time
Linear complexity means as the input increases, the runtime also increases in the same pace.
For example, in real world, if a worker takes 1 minute to stick a stamp on one envelope, it
will take him 100 seconds to stick 100 stamps on 100 envelopes.
When a programme runs through the items in an array, for example, printing each value of an
array, the time it takes to print the items would increase when the number of items of the array
increases.

9.3 O(n2) Quadratic Time


Quadratic time Big-O programs increase the time to process the input by the squared number
of its inputs.
This can also be seen in arrays where there is a calculation factor set to calculate each and
every value with each and every other value.
If an array has the numbers [1,2,3,4] , to get additions of all these will have 16 instances. If
one calculations would take one second, the calculation would take 42 = 16 seconds. However,
if the array has 5 values, [1,2,3,4,5] there would be 52 = 25 instances taking 25 seconds.
Similarly, if an array has values from 1 to 10000, [1,2,3,4……10000] the time it would take
to complete the calculation would be 100002 = 100000000 seconds.

9.4 O(log n) Logarithmic Time


In logarithmic time, as the input increases exponentially, the runtime slightly increases as a
proportion to the size of the input.
In real life, if a person is looking for a NIC number of a person born in April 1990, in an
incrementally stacked range of NIC numbers form people born in 1950 to 2020, the search
can completely ignore the NIC numbers starting from 50 to 89 and start searching form 90
because people born in 1990 would have 90 or 1990 as the first digits of their NIC Sri Lankan
NIC numbers have the year of birth in the first two digits and the number of days in the year
to the person’s birthday is shown in the next 3 digits. After the first search is done, the same
process can be followed with the rest of the numbers in and NIC to ignore the first months
and find the required month.

V.G.Gayan Praneeth Programming Page 49 of 100


9.5 O(n!) Exponential Time
This represents the factorial of an input to process an algorithm. Simply put, if there is 1 input,
it takes 1*1 = 1 seconds to complete the algorithm. 2 inputs would take 2*1 = 2 seconds, 3
inputs would take 3*2*1= 6 seconds and so on.

V.G.Gayan Praneeth Programming Page 50 of 100


10 Coding the algorithms in Python
10.1 Fibonacci sequence
n = int(input("Please enter the number of instances you need "))

f1 = 0
f2 = 1
Next = 0
c = 0
print("Fibonacci sequence:")
print("0")
print("1")

while c < n-2:


Next = f1 + f2
print(Next)
f1 = f2
f2 = Next
c = c + 1
Figure 8: Python code for Fibonacci sequence

Figure 9: Testing 5 as an input in Fibonacci numbers

V.G.Gayan Praneeth Programming Page 51 of 100


Figure 10: Testing 10 as an input in Fibonacci numbers

Figure 11: Testing 15 as an input in Fibonacci numbers

V.G.Gayan Praneeth Programming Page 52 of 100


10.2 Factorial values
num = int(input("Please input your number "))
m = 1

for c in range(1, num+1):


m = m * c

print("The factorial of your number is : ", end="")


print(m)
Figure 12: Python code for Factorial numbers

Figure 13: Testing 5 as an input in Factorial numbers

Figure 14: Testing Factorial numbers using 10 as an input

V.G.Gayan Praneeth Programming Page 53 of 100


11 Differences in the code and the algorithm, the efficiency of the programs in reference to
the Big-O notation.
11.1 Differences in the algorithm and the code.
When it comes to coding, the Fibonacci numbers algorithm could be implemented into the
code in the same way and using almost all the steps described in the algorithm.
However, when it comes to the factorial value, using a ‘for loop’ can reduce some steps and
assign the increment of the counter in one method.
11.2 Efficiency with the Big-O notation.
Both algorithms increase the number of instances they must process depending on the input
value. Therefore, both algorithms have an increasing number of processing steps depending
on the input.
11.2.1 Fibonacci
The Fibonacci numbers have a 1 to 1 increasing ratio against the input. The higher the input
gets one by one, the number of loops the program should run increases by one. If the program
gets 5 as an input, the program loop has to run 3 times (Because the first two numbers are
already printed.). If the input is six, the loop runs 4 times, so, if it is 100, the loop would run
98 times. Therefore, the Fibonacci sequence has a linear Big-O value, which is O(1).
11.2.2 Factorial
The factorial numbers have a squaring effect when it comes to increasing input. As mentioned
in the example describing O(n2), the higher the input gets, the number of times the loop needs
to run gets squared as in 2 inputs, 4 loops and 4 inputs, 16 loops. Therefore, the Big-O notation
of the Factorial numbers can be given as Quadratic time, O(n2).

V.G.Gayan Praneeth Programming Page 54 of 100


12 Programming paradigms
The programing paradigm is the approach that a programmer takes to solve a problem. The
tools and the methods that a programmer uses to solve a problem also fall into the
programming paradigm. In other words, a programming paradigm is how a program, or a
certain programming language is organized. When trying to solve a problem, it could have a
certain programming paradigm that could effectively solve the problem than others.
Even though a programmer can take a desired approach with a programming language, it does
not mean that a programming language is not a programming paradigm. And the are not
always designed to be used with a definite paradigm. There can be extensive features in a
programming language to support a distinct programming paradigm but in the present, most
programming languages support a multiple or programming paradigms. (Cocca, 2022)

Figure 15: Common Programming paradigms

Programming paradigms fall into two main categories. The imperative and the Declarative
programming paradigms.
Imperative programming paradigms has a step-by-step approach to solve a problem executing
from top to bottom. Being one of the earliest programming paradigms, achieving the goal is
its focus. These languages are simple to implement, and they contain variables and loops.
Some of the main programming paradigms within imperative programming paradigm are, the
Procedural Programming Paradigm, the Object-Oriented Programming paradigm and the
event driven programming paradigm.

V.G.Gayan Praneeth Programming Page 55 of 100


12.1 Procedural programming
Procedural programming takes a step-by-step approach to tell the computer what to do. As
this is a subset of the imperative programming approach it has many similarities with it. It is
a newer form of imperative programming which has some added features known as
procedures, or subroutines. Subdividing a program promotes modularity and helps to organize
the code in an improved way.

def Sum(list_of_numbers):
total = 0
for x in list_of_numbers:
total += x
return total

first_list = [10, 370, 50, 70]


second_list = [18, 26, 33, 13]

print(Sum(first_list))
print(Sum(second_list))
Figure 16: Code example for Procedural Programming

In the above example, a simple code has been provided to calculate the sum of a list of
numbers. The program runs line b line and then outputs the results. The first_list should output
500 as the total and the second_list should output 75 as the total.

Figure 17: Sample code executed. Procedural

V.G.Gayan Praneeth Programming Page 56 of 100


Advantages Disadvantages
Can be used as a general-purpose The data protection of this is limited
programming setup
The code can be reused Writing them can be difficult
The source code is portable. Would not be suitable for real world objects
Table 3: Advantages and disadvantages of Procedural programming

12.2 Object Oriented Programming


An object is a real-world entity. Objects have qualities and actions. Similarly, object-oriented
programming allows the programmer to create a real-world entity within the code with
attributes and methods. For example, if a programmer needs to create a DBMS for a library,
the program would be handling books. So, Object oriented programming lets the programmer
to create books inside the code. To do this, the programme should create a class ideally called
‘books’ and define the attributes of the book into the program such as author and genre. Then
the program understands and allows various data of books to be stored into the code. These
can be called later for various purposes.

# class Book has been defined here


# a book can have a name and an author
class Book:
def __init__(self, name, author):
self.name = name
self.author = author
# creating a string to print the details of books as 'info'
def info(self):
print("% s is written by % s" % (self.name, self.author))

# Objects of class Book are defined here


# the names and authors are given
Books = [Book("Harry Potter", "J K Rowling"),
Book("Count of Monte Cristo", "Alexandre Dumas"),
Book("Lord of the Rings", "J R R Tolkein")]

# Printing out the info of books


for Book in Books:
Book.info()
Figure 18: The class book and various objects (books) are created in this block of code

When the above code is executed, the names and authors of the books should be printed in
the screen.

V.G.Gayan Praneeth Programming Page 57 of 100


Figure 19: Program execution example for OOP

Advantages Disadvantages
The code can be reused in similar conditions Can be slower than procedural programs
and situations
Can relate to real world entities making the Can contain more lines of code making it
coding process productive complicated.
Easily upgradable and scalable If done without proper standards, can cause
a lot of issues.
Modularity and ease of troubleshooting Has a steep learning cure and takes time
getting used to

12.3 Event Driven Programming


Event driven programming is commonly used in most GUI based applications and it is one of
the most popular programming paradigms of all. In event driven programming, a series of
logic are prepared and each of these logics or actions will be driven by triggering them with
a pre-defined action. In visual studio windows forms applications, this can be seen in almost
everywhere within the code.

V.G.Gayan Praneeth Programming Page 58 of 100


For example, in the form below, there are a few elements and each of them can be
programmed to react on a selected event or a trigger.

Figure 20: Sample interface for EDP demonstration

In the code, each element is waiting for a specific action to happen in order to run the
designated code.

Figure 21: Event driven programming coding example

V.G.Gayan Praneeth Programming Page 59 of 100


In this code, the various elements would perform the blow tasks upon the given event.
Element Event Action
Text box 1 The form loads Display “welcome” as the
text
Text box 1 Double click text box Chane the colour to Teal
Button 1 Single click Show message box “You
just clicked me”
DateTimePicker 1 Mouse hover Change the date to the
system date and time.
Table 4: Events list and actions of those events

Figure 22: Running the EPD demonstration program

Advantages Disadvantages
Event driven programs can be flexible in Because the blocks of code arrange
terms of changing something. As one themselves as the programmer codes them,
event-based code would not necessarily the flow of the program can be less logical
affect another most of the time. and obvious.
Suitable for GUI interfaces with buttons, Troubleshooting can be cumbersome and
text boxes and other elements. time consuming.
Can easily pinpoint the code or the part of Having a lot of forms, classes buttons and
the program designated to a specific other elements can make it confusing
object.
Enables the programmes to be complex These types of programmes can consume
and more interactive. more resources and the program can be
slower.

V.G.Gayan Praneeth Programming Page 60 of 100


13 Critical evaluation of programming paradigms.
As described in the above topics, the programming paradigm is the method which the
programmer uses to find a solution to the problems which he has been tasked to solve. As
described above, since procedural programming is based the earliest programming paradigms
ever invented, and OOP and EDP are improvements made to the procedural programming
paradigm, all the three programming paradigms have similar shared characteristics.
Though all of them have their advantages and disadvantages, it is unlikely that in a real-world
condition, an application could be programmed using just one programming paradigm. Of
course, it can be done in var simple applications but achieving effective results in a complicate
application with just one paradigm can be unrealistic. One could argue that OOP or EDP can
be used to solve almost all programming problem scenarios on their own but if looked into
more closely, it can be observed that these have the characteristics of other programming
characteristics within themselves too.
As explained above each programming language has integrated features catered for most if
not all programming paradigms because solving a complex problem would require more than
one approach or paradigm. Therefore, using man programming paradigms depending on the
nature of the problem would help the programmer to create the best solution for the problem
at hand.
To achieve this, the programmer should be completely aware of the programming paradigms
and how the are used in the respective programming language. Furthermore, as programming
is mostly a task that requires teamwork and collaboration, having a properly accepted method,
approach or a paradigm would make it easy on others in the team to understand, evaluate and
troubleshoot each other’s work as well.

V.G.Gayan Praneeth Programming Page 61 of 100


14 Developing the Griffindo Toys Payroll System
14.1 Understanding the requirements of the Client.
14.1.1 The employee details
The client needs to search, register, update and delete employees using the system. This
requires a table for employees within the database and appropriate buttons in the Employee
Component of the system.
14.1.2 Payment details
A table is needed to store salary payout details. The salary component needs to calculate the
monthly salaries of the employees and needs to store them to later get various reports about
payments made to employees.
14.1.3 Settings
The settings component can determine the salary cycle begin date, end date, number of dates
for the cycle and number of annual leaves for the employee. A table is needed to save the
settings of the application.
14.1.4 Login Information
Since the app needs to have a login mechanism, the login data should be kept in a separate
table.

V.G.Gayan Praneeth Programming Page 62 of 100


14.2 The ER diagram

Figure 23: Entity Relationship diagram of Griffindo Toys Payroll system

V.G.Gayan Praneeth Programming Page 63 of 100


14.3 Creating the database
Based on the above ER diagram, the database for the proposed system would have 4 tables.
14.3.1 The Employees table

Figure 24: Creating the Employees table


14.3.2 Salaryinfo Table

Figure 25: Creating the Salaryinfo table

V.G.Gayan Praneeth Programming Page 64 of 100


14.3.3 Settings Table

Figure 26: Creating the settings table

14.3.4 Login Table

Figure 27: Creating the Login table

V.G.Gayan Praneeth Programming Page 65 of 100


15 Pseudocode of the setting component
The settings component has two buttons. Refresh and Update. There are two Date time pickers
and two text boxes to display salary cycle and the number of annual leaves.
The user can select the StartDate and enter the SalaryCycle days the press the update button.
The system will automatically calculate the end date based on the StartDate and the Salary
Cycle days and save the data to the database. The user can also enter the number of Annual
leaves in the provided text box.
The refresh button shows the current settings of the program.

Figure 28: The settings component

V.G.Gayan Praneeth Programming Page 66 of 100


15.1 Pseudocode for the Refresh button
Start
Set up command to connect to the database
Set up database command to get all form the settings table
Define variable for the StartDate value of the date time picker
Use a try catch loop
Open connection
Define SQL reader to read the results of the SQL command
If the SQL reader has data

Show the “StartDate” value form the DB in the StartDate DTpicker


Show the “SalaryCycle” value form the DB in the SalaryCycle textbox
Show the “AnnualLeaves” value form the DB in the Annualleaves textbox
Get the SalaryCylce value and add it to the Startdate to get EndDate
Show the EndDate value in the EndDate DTpicker

Else

Show message box “No matching data”

Catch the exception and show an error message

End

V.G.Gayan Praneeth Programming Page 67 of 100


15.2 Pseudocode of the Update button
Start
Define variable for the StartDate, Annual leaves and SalaryCycle
Set up command to connect to the database
Set up database command to insert the data into SQL table
Use a try catch loop
Open connection
Execute the command
Close Connection
Show message box: “New settings configures Successfully”
Perform a click on the refresh button to show the new settings
Catch the exception and show an error message
End

V.G.Gayan Praneeth Programming Page 68 of 100


16 How an IDE helps programming with its features
16.1 What is an IDE?
IDE stands for Integrated Development Environment. It is a software designed to make other
programmes using one or many programming languages. Microsoft Visual Studio, Android
Studio, Arduino IDE are some examples for various Integrated Development Environments.

Figure 29: IDEs and their languages

V.G.Gayan Praneeth Programming Page 69 of 100


Most IDEs contain certain tools to make the programming process efficient.
• Code editor
Though all code can be written in a text editor, the integrated code editor in an IDE has
a few differences than a typical text editor. These are optimized to the selected
programming language and provides suggestions, auto corrections and help tips to
make the writing process more efficient for programmers. Without a code editor,
writing code can be a tricky task because depending on the language, there can be
indentations, case sensitivity, using colons symbols which can lead to errors if written
wrong.
• Compiler
The transformation of the source code from human readable language to a machine-
readable language is handled by the compiler.
• Debugger
The process of debugging can be a tedious and time-consuming task during the testing
phase of a programme. The debuggers integrated to an IDE provides help and other
tools necessary to make the debugging process easy.
• Automation Tools
These tools provide automation various common and repetitive tasks for the developer
saving effort and time.
All these tools and features provide real time support for the programmer to make the coding
process efficient and simple.

16.2 When not to use an IDE?


If a programmer is in the beginner stage of their programming career or at the beginning of
learning programming, using an IDE could prevent the user from getting to know the basics
of the language because the IDE suggests, corrects and helps the programmer as they type the
code. Many educators suggest that beginners should not use an IDE at least until they have a
basic sense about the common mistakes that can happen during coding.

V.G.Gayan Praneeth Programming Page 70 of 100


16.3 Advantages and Disadvantage of an IDE
Advantages Disadvantages
The support structure reduces effort and Might not be suitable for beginners with
time. little to no coding experience.
Can manage code blocks easily. Maximizing the use of an IDE has a steep
learning curve and takes time.
The tools and resources are displayed No matter what features an IDE has, it
graphically providing ease of use. would not fix badly written code or badly
planned programmers.
Promotes collaboration with a team because Some IDEs require considerable processing
IDEs help the programmer to stick to the power which limits them to be used in low
coding conventions and standards. performance computers.
Table 5: Advantages and Disadvantages of an IDE

16.4 Using Visual Studio to create the program


Visual studio 2022 is the latest version of Microsoft’s software development IDE and using
it has made the programming process easy and efficient.
First of all, the IDE has native support for a large number of programming languages and the
programmer could download and install the modules the want using the Visual Studio
Installer. If there is a need to add more languages or modules, the user can always add them
later. The initial download and the feature additions are completely free for all users.
The program has a number of navigation panels such as the database explorer which helps to
navigate to all connected data sources while the solution explorer helps to navigate to the
various forms classes and other configuration files. These made the programming part easy
because navigating through a lot of forms can be rather confusing without it.

Figure 30: The server explorer and the Solution explorer

V.G.Gayan Praneeth Programming Page 71 of 100


The application creating process is made easier with the toolbox which has a number of useful
tools and services that can be dragged into forms and the use of alignment tools make the
designing of the interface easy.
The properties panel lets the user customize the items in the application in many ways and
the events tab helps to code various aspects into the events shown in the events tab.

Figure 31: The toolbox and the events tab

While writing the code, it not only provides suggestions, it detects errors and provides tips to
correct the errors while coding.

Figure 32: Visual Studio Suggesting a code

V.G.Gayan Praneeth Programming Page 72 of 100


Figure 33: Visual studio showing potential fixes

Using visual studio made the programming process easy and somewhat enjoyable. If there
was no IDE available to create this project, it would take much more time and a huge amount
of effort to perform all these automated actions manually and it would be close to impossible.

V.G.Gayan Praneeth Programming Page 73 of 100


17 The system
17.1 The login interface

Figure 34: The login page

Figure 35: Logging in

17.1.1 The code of the Login Interface

Figure 36: The code of the Login Interface

V.G.Gayan Praneeth Programming Page 74 of 100


17.2 The dashboard

Figure 37: The Dashboard

17.2.1 The code of the dashboard

Figure 38: The code of the dashboard

V.G.Gayan Praneeth Programming Page 75 of 100


17.3 The employee component

Figure 39: Employee management interface

There are two search buttons in this segment. The user can enter a Employee ID and search it
using the Search by ID button or the user can enter the NIC of the employee and search their
information using the search by NIC button.

17.3.1 Code for search by ID

Figure 40: Search by ID button code

V.G.Gayan Praneeth Programming Page 76 of 100


17.3.2 Code for search by NIC

Figure 41: Search by NIC button code

This interface also has a CRUD operation where the user can Create, Read, Update and Delete
entries. Input the necessary data into the text boxes and pressing the desired button will
execute the desired task.

17.3.3 Code for the Register button

Figure 42: The code of the register button

V.G.Gayan Praneeth Programming Page 77 of 100


17.3.4 Code for the Update button

Figure 43: Code for the Update button

17.3.5 Code for the Delete button

Figure 44: Code for the delete button

V.G.Gayan Praneeth Programming Page 78 of 100


17.4 The salary Component

Figure 45: Salary component

The salary component automatically fills the salary cycle information segment grabbing the
data from the database as the program loads. Or the user can click the refresh button to refresh
the data. The Settings button would take the user to the settings interface if there is a need to
change the settings.
The text fields for absent days, OT Hours and Gov Tax rate should be filled as per the
instructions shown in the interface. The other fields: the No Pay value, Base pay value, OT
payable and Gross salary will be filled once the user presses the Calculate button. These fields
will not take inputs from the user.
The Pay button records all the data from this interface into the SalaryInfo table in the database.

17.4.1 The Salary calculation class


All the formulas needed to calculate the various salary components have been created as
methods in the Salary Calculations Class. This would be explained later in the Classes used
chapter.

V.G.Gayan Praneeth Programming Page 79 of 100


Figure 46: The Salary Calculation class

17.4.2 Code for the refresh button

Figure 47:Code for the refresh button

V.G.Gayan Praneeth Programming Page 80 of 100


17.4.3 Code for the calculate button

Figure 48: Code for the Calculate button

17.4.4 Code for the Pay button

Figure 49: The code for the Pay button

V.G.Gayan Praneeth Programming Page 81 of 100


17.5 The settings component

Figure 50: Settings Component

17.6 The reports section


Disclaimer: as visual studio 2022 was used to create this application, when creating reports
interface a problem was encountered. As Visual studio 2022 no longer natively supports
reports feature, it had to be added via a NuGet package. However, it resulted in many errors.
Therefore, this interface was created with a DataGrid View to generate all the required reports
for the user.

V.G.Gayan Praneeth Programming Page 82 of 100


Figure 51:Reports Section

The report section generates reports on a numerous user defined conditions and the buttons
and their function is mentioned below.
17.6.1 Load all employees
This button loads the complete information of all the employees in the company database.

Figure 52: Code for load all employees

V.G.Gayan Praneeth Programming Page 83 of 100


17.6.2 Full Salary history
This button loads the complete information of all payments done for all the employees in the
company database so far.

Figure 53: Code for Loading full salary history

17.6.3 Salary history by month


The user has to select a month form the dropdown list above this button and pressing this
would show all payments done to all employees in the selected month.

Figure 54: Code for Salary history by month

V.G.Gayan Praneeth Programming Page 84 of 100


17.6.4 All salary payments within the date range
After selecting a start date and an end date, the user can view all salary payments done to all
employees between he given date range.

Figure 55: Code for All salary payments within the date range

17.6.5 Search Employee details


After entering an Employee ID, the user can view the details of the specified employee.

Figure 56: Code for Search all employee details

V.G.Gayan Praneeth Programming Page 85 of 100


17.6.6 Salary history
After entering an Employee ID, the user can view the all the payment details of the specified
employee.

Figure 57: Code for Salary history

17.6.7 Employee monthly salary


After entering an Employee ID and the month from the dropdown list, the user can view the
all the payment details of the specified employee for the selected month.

Figure 58: Code for Employee monthly salary

V.G.Gayan Praneeth Programming Page 86 of 100


17.6.8 Employee Salary History
After entering an Employee ID and a start date and an end date form the date time pickers,
the user can view the all the payment details of the specified employee within the specified
date range.

Figure 59: Code for Employee Salary History

V.G.Gayan Praneeth Programming Page 87 of 100


17.7 The classes and methods created for the program
17.7.1 Connection manager
The connection manager class has the SQL connection data and the connection string in a
method called ‘GetConnection’. This method returns the connection string as the output of
the method.

Figure 60: The method Get Connection and its values


In order to do this, the connection string has to be added to the App.Config as shown below.

Figure 61: The connection string has been added to App Config to be used in the class

V.G.Gayan Praneeth Programming Page 88 of 100


17.7.2 Salary calculation
Salary calculation class has all the salary calculation equations as methods. So that in the
code, it is easy to call the methos and enter the required values rather than typing the equations
all over the code.

Figure 62: Salary Calculation class and the methods inside

17.8 The advantage of using classes and methods


Using classes and methods gives the programmer the ability to call the methods inside the
code and keep the code easy understand, manage and to write. For example, rather than typing
the connection string everywhere when a connection needs to be established, it is better to
call the ‘GetConnection’ method, which returns the connection string.
Furthermore, this provides the opportunity to store more than one connection strings into
different methods and to call them whenever needed without fiddling for the connections
stings all the time.
The most important advantage of using classes and methods is that, if there is ever a need to
change a value, for example a connection string, simply changing it in the method would
apply the changes to the whole code. If there were no methods of classes involved, the whole
code needs to be changed one instance by one instance leading for the chance to have errors.

V.G.Gayan Praneeth Programming Page 89 of 100


Figure 63: Using the GetConeection method

Figure 64: Using the methods of Salary Calculation to calculate salary

V.G.Gayan Praneeth Programming Page 90 of 100


18 Debugging
A bug is an error or a piece of code that causes problems and misbehaviours in an application.
The process of debugging involves finding the bugs and removing them so that he computer
program could run the way it is supposed to run. Finding a bug inside multiple lines of code
can be a challenging task especially if the code has complicated functions and a considerable
number of lines. Fortunately, debugging tools let the programmer to run the program in a
controlled environment and provides the opportunity to check the code line by line in order
to find and fix the bug. (Amazon Web Services, 2022)
Visual studio 2022 has several debugging tools to make the debugging process efficient and
manageable.
18.1 Using Breakpoints
Using breakpoints would stop the app running in debugger mode and allow to see the code
where the breakpoint it set. Using the navigation tools described below, the programmer can
see the runtime status of the possible code where the breakpoint is set. The breakpoint offers
a number of options such as Conditional breakpoint, Temporary breakpoint and more.

Figure 65: Setting a breakpoint

V.G.Gayan Praneeth Programming Page 91 of 100


18.2 Using step into tools
The step into tools enables the programmer to go over the code line by line and to see the
values and attributes of the variables and other information about the code which is running
at the moment. This feature can be used by pressing the F11 key or after the program is paused
with a breakpoint.

Figure 66: The step into tools

Figure 67: Step into tools magnified

These tools can go from line to line as needed and, on the bottom right of the screen, the
current values related to that particular line is displayed.

V.G.Gayan Praneeth Programming Page 92 of 100


Figure 68; Debugger showing current values of a selected line

18.3 Run to click


While debugging, the run to click feature can run the programme to where the mouse is
clicked in the code. To do this, the mouse has to be hovered on a line of code until a green
coloured run button appears as shown blow. Clicking it would run the code up to that point.

Figure 69: Run to Click

V.G.Gayan Praneeth Programming Page 93 of 100


18.4 How debugging features were used to develop the program and make it better
As this program had a lot of SQL commands, text fields and variables, especially for the
search and insert features, there were many instances where these variables needed to be
checked. Because, if the data type of the variable does not match the data type of the returning
from an SQL command, the program would run into an error. When there were more than
one variable with a large number of data types and so many outputs to send data to, such as
DataGrid views, text boxes, Datetime pickers and so on, running the debugger with a
breakpoint and stepping over the lines of code one by one helped immensely to find out what
data types are returning and into what they should be converted into.

Figure 70: Using the debugger to see the current values of variables

While coding, visual studio provides an error count so that the programmer can correct errors
even before they run the programme. However Visual Studio debugger allows editing the
code while the debugger is running and to reload the application making the debugging
process more efficient.
The debugger is visual studio is a powerful tool that allows the programmer to debug their
code within the same environment and to remove the bugs in the program resulting in a more
robust and secure application.

V.G.Gayan Praneeth Programming Page 94 of 100


19 Coding standards used in this program
19.1 Naming conventions
In this program, buttons, text boxes, date time pickers and even DataGrid views have been
renamed to match their intended function. This allows them to be easily recognized while
coding and the code to be more readable and understandable. Furthermore, to name the items
in the forms, camelCase has been used. It starts with a simple letter and the subsequent words
in the name gets capital letters with no spaces in between. Here are some instances of naming
items.
Buttons – btn<text> btnID, btnSearch, btnRefresh
Text boxes – txt<name> txtID, txtFname, txtLname

Figure 71: Naming buttons

Figure 72: Named textboxes and the button makes the code easy to understand

V.G.Gayan Praneeth Programming Page 95 of 100


19.2 Classes and methods
As described above in the classes used section, classes and methods help to make the code
more uncluttered and it allows for future modifications if any. Separate classes should be
created to separate functions to avoid complications.
Naming methods should be done in Pascal Case where all the first letters in all words should
be capitals and there are no spaces in between words.

Figure 73: Methods relating to calculations

Figure 74: Method relating to connections

V.G.Gayan Praneeth Programming Page 96 of 100


19.3 Using comments
Adding comments to the codes as it is being written is a way keep track of what code has been
used to perform what task. This will help another person to understand the reason for the
various aspects of the coding lines.

Figure 75: Using comments

Figure 76: Using Comments

V.G.Gayan Praneeth Programming Page 97 of 100


19.4 How coding standards help the programming process
Having a proper standard in the way a programmer writes code has a few benefits for
themselves and for others.
First, having any sort of standard means that the code has order, clarity and a specified
methodology as to how it should be written. As a programmer, having these qualities in their
code will make the code more readable and manageable. If a programmer is simultaneously
working of a few projects, having proper naming techniques, and commenting habits will
allow the programmer to jump iFn and carry on from the point where they have left off.
Getting used to a standard will improve the coding abilities and if the programmer is working
in a corporate environment, it would give them credibility as a person who is able to write
clear and understandable code.
The advantages of having a coding standard amplifies when the programmer is working with
a team. If all members of the team are adhering to the same or similar coding ethics, each of
them will be able to review and improve each other’s work without many complications.
Furthermore, having a proper coding standard would be a required trait especially if there are
a few people procedurally developing various aspects and various phases of the program.
Furthermore, coding standards ensure the security of the project, and it reduces the number
of potential errors that could occur. It minimizes complexities, makes it easier to find bugs
and makes it easier to fix them. Coding standards also contribute to smooth running of an
application while reducing cost.

V.G.Gayan Praneeth Programming Page 98 of 100


20 References
Amazon Web Services, 2022. What is Debugging?. [Online]
Available at: https://aws.amazon.com/what-is/debugging/
[Accessed 12 12 2022].
Cocca, G., 2022. Programming Paradigms – Paradigm Examples for Beginners.
[Online]
Available at: https://www.freecodecamp.org/news/an-introduction-to-programming-
paradigms/#what-is-a-programming-paradigm
[Accessed 12 12 2022].
Gillis, A. S., 2022. TechTarget.com. [Online]
Available at: https://www.techtarget.com/whatis/definition/algorithm
[Accessed 12 12 2022].
Lovett, P., 2020. Big-O Notation: A simple explanation with examples. [Online]
Available at: https://www.linkedin.com/pulse/big-o-notation-simple-explanation-
examples-pamela-
lovett#:~:text=So%20what%20is%20Big%2DO,running%20time%20of%20an%20a
lgorithm.
[Accessed 12 12 2022].
The University of Rhode Island, n.d. What is progamming?. [Online]
Available at:
https://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm
[Accessed 12 12 2022].
Ubah, K., 2021. What is Pseudocode? How to Use Pseudocode to Solve Coding
Problems. [Online]
Available at: https://www.freecodecamp.org/news/what-is-pseudocode-in-
programming/
[Accessed 12 12 2022].
Upadhyay, S., 2022. What Is An Algorithm? Characteristics, Types and How to write it.
[Online]
Available at: https://www.simplilearn.com/tutorials/data-structure-tutorial/what-is-
an-
algorithm#:~:text=Unambiguity%2C%20fineness%2C%20effectiveness%2C%20an
d,the%20characteristics%20of%20an%20algorithm.
[Accessed 10 12 2022].

V.G.Gayan Praneeth Programming Page 99 of 100


V.G.Gayan Praneeth Programming Page 100 of 100

You might also like