KEMBAR78
7048-1712772218517-Unit-01 Programming Assignment - 2024 | PDF | Time Complexity | Computer Programming
0% found this document useful (0 votes)
59 views73 pages

7048-1712772218517-Unit-01 Programming Assignment - 2024

The document is a feedback form for a summative assignment in Unit 01 - Programming for student S A D Sakuntha Sankalpa, detailing learning outcomes, assessment criteria, and important submission guidelines. It emphasizes the significance of original work, proper referencing, and the consequences of plagiarism. The assignment involves developing a leave management system for Grifindo Lanka Toys, requiring knowledge of algorithms, programming paradigms, and the use of an Integrated Development Environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views73 pages

7048-1712772218517-Unit-01 Programming Assignment - 2024

The document is a feedback form for a summative assignment in Unit 01 - Programming for student S A D Sakuntha Sankalpa, detailing learning outcomes, assessment criteria, and important submission guidelines. It emphasizes the significance of original work, proper referencing, and the consequences of plagiarism. The assignment involves developing a leave management system for Grifindo Lanka Toys, requiring knowledge of algorithms, programming paradigms, and the use of an Integrated Development Environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 73

Higher Nationals - Summative Assignment Feedback Form

Student Name/ID S A D Sakuntha Sankalpa/E208856


Unit Title Unit 01 – Programming
Assignment 1 Assessor Lasanthika Jayasekara
Number
31/08/2024 Date
Submission Date
Received 1st
submission
20/01/2025 Date Received
Re-submission
Date 2nd
submission

Assessor Feedback:

LO1. Define basic algorithms to carry out an operation and outline the process of programming an
applicate
Pass, Merit & Distinction Descripts P1 P2 M1 D1

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

Pass, Merit & Distinction Descripts P3 M2 D2

LO3. Implement basic algorithms in code using an IDE.

Pass, Merit & Distinction Descripts P4 M3 D3

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

* 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.

Page | 1
Sakuntha Sankalpa Programming – 01
Assessor Feedback:

Grade: Assessor Signature: Date:


Resubmission Feedback:
 Please note resubmission feedback is focused only on the resubmitted work

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.

BTEC HN Summative Assignment Feedback Form


Issue Date: June 2021 Owner: HN QD
DCL1 Public (Unclassified) Version 1.0

Page | 2
Sakuntha Sankalpa Programming – 01
Important Points:

1. It is strictly prohibited to use textboxes to add texts in the assignments,


except for the compulsory information. e.g: 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. Avoid using page borders in your assignment body.
3. Carefully check the hand in date and the instructions given in the
assignment. Late submissions will not be accepted.
4. Ensure that you give yourself enough time to complete the assignment by the due
date.
5. Excuses of any nature will not be accepted for failure to hand in the work on time.
6. You must take responsibility for managing your own time effectively.
7. 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.
8. Failure to achieve at least PASS criteria will result in a REFERRAL grade.
9. Non-submission of work without valid reasons will lead to an automatic RE
FERRAL. You will then be asked to complete an alternative assignment.
10.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.
11. 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
12.Use word processing application spell check and grammar check function
to help editing your assignment.
13.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.

Page | 3
Sakuntha Sankalpa Programming – 01
STUDENT ASSESSMENT SUBMISSION AND
DECLARATION
When submitting evidence for assessment, each student must sign a
declaration confirming that the work is their own.
Student name: Assessor name:
S A D Sakuntha Sankalpa Lasanthika Jayasekara

Issue date: Submission date: Submitted on:


24/04/2024 31/08/2024 20/01/2025

Programme: Pearson BTEC HND in Computing

Unit: Unit 01 – Programming


Assignment number and title:
Building a Leave Management System for Grifindo Lanka Toys (Pvt) Ltd.

Plagiarism
Plagiarism is a particular form of cheating. Plagiarism must be avoided at all
costs and students who break the rules, however innocently, may be
penalized. It is your responsibility to ensure that you understand correct
referencing practices. As a university level student, you are expected to use
appropriate references throughout and keep carefully detailed notes of all
your sources of materials for material you have used in your work, including
any material downloaded from the Internet. Please consult the relevant unit
lecturer or your course tutor if you need any further advice.

Guidelines for incorporating AI-generated content into


assignments: The use of AI-generated tools to enhance intellectual
development is permitted; nevertheless, submitted work must be original.
It is not acceptable to pass off AI- generated work as your own.

Student Declaration

Student declaration

I certify that the assignment submission is entirely my own work and I fully
understand the consequences of plagiarism. I understand that making a false
declaration is a form of malpractice.

Student E208856@esoft.academy Date 20/01/2025


signature: :

Page | 4
Sakuntha Sankalpa Programming – 01
Unit 01: PROGRAMMING
Assignment Brief
Student Name/ID
S A D Sakuntha Sankalpa/E208856
Number

Unit Number and Unit 01 – Programming


Title
Academic Year 2024/2025

Unit Tutor Lasanthika Jayasekara

Assignment Title Building a Leave Management System for Grifindo Lanka


Toys (Pvt) Ltd.

24/04/2024
Issue Date
Submission Date 20/01/2025

Submission Format
The assignment submission is in the form of the following.
 The submission should be in the form of an individual written report
written in a concise, formal technical style using single spacing and
font size 12.
 Student has to submit the complete GUI System with the database.

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

Page | 5
Sakuntha Sankalpa Programming – 01
Transferable skills and competencies developed
Computing-related cognitive skills :
 Demonstrate knowledge and understanding of essential facts,
concepts, principles and
theories relating to computing and computer applications
 Use such knowledge and understanding in the modelling and
design of computer- based
systems for the purposes of comprehension, communication,
prediction and the understanding of trade-offs
 Recognise and analyse criteria and specifications appropriate to
specific problems, and
plan strategies for their solutions
 Critical evaluation and testing: analyse the extent to which a
computer-based system
meets the criteria defined for its current use and future development
 Methods and tools: deploy appropriate theory, practices and tools
for the design, implementation and evaluation of computer-based
systems.

Computing-related practical skills :


 The ability to specify, design and construct reliable, secure and
usable computer- based
systems
 The ability to evaluate systems in terms of quality attributes and
possible trade-offs presented within the given problem
 The ability to deploy effectively the tools used for the
construction and documentation
of computer applications, with particular emphasis on
understanding the whole process
involved in the effective deployment of computers to solve practical
problems
 The ability to critically evaluate and analyse complex problems,
including those with incomplete information, and devise appropriate
solutions, within the constraints of a budget.

Generic skills for employability:


 Intellectual skills: critical thinking; making a case; numeracy and
literacy
 Self-management: self-awareness and reflection; goal setting and
action planning
 Independence and adaptability; acting on initiative; innovation and
creativity

Page | 6
Sakuntha Sankalpa Programming – 01
 Contextual awareness, e.g. the ability to understand and meet
the needs of individuals,
business and the community, and to understand how workplaces
and organisations are
governed.

Page | 7
Sakuntha Sankalpa Programming – 01
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.

Page | 8
Sakuntha Sankalpa Programming – 01
Activity 2

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 Lanka Toys is a small-scale Toy building company which is in Sri Lanka and
currently they have 20 employees working at this company. Grifindo Lanka Toys is the Sri
Lankan branch of Grifindo Toys Company which is in UK and previously they have hired your
freelance company to develop their payroll system and now they are hiring you again to
develop their leave management system for the Sri Lankan branch, Grifindo Lanka Toys
Company.
Specifications for the leave management system as follows,

This leave management system has two user roles, and they are Employee and Admin, and they
are having two separate desktop applications to interact with the centralized database. Developer
can consider the centralized database as a local database for the development purposes.

Page | 9
Sakuntha Sankalpa Programming – 01
Functional requirements for the Employee and Admin as follow.

1. Employee Application.

 Employee should be able to login to the system with the employee number
and the given password.

 Employee should be able to apply for a leave through the system.

Note: - Normally an employee has 14 annual leaves, 7 casual leaves for a year
and 2 shorts leaves per month. Employee can apply casual leaves as they want
before their defined roaster starts. Annual leaves can be applied before 7 days
prior to the leave date. Short leave duration is 1 hour and 30 minutes and can
be applied for upcoming time slots.

 Employee can view the status of applied leaves (Whether applied leaves
are approved or not).

 Employee can delete applied leaves.

 Employee can view their remaining leaves and history of applied leaves.

2. Admin Application

 Admin should be able to login to the leave management system.

 Admin should be able to register new employees to the system.

 Admin should be able to define the number of annual leaves, casual leaves for
a year and 2 short leaves per every month for every employee. (Newly joined
employees will less number of leaves compared to permanent employees)

 Admin should be able to define the roaster starting time and end time for
each employee.

Page | 10
Sakuntha Sankalpa Programming – 01
 Admin should be able to approve or reject applied leaves of each employee.

 Admin should be able to view leave reports of,

 Individual employee leave history for a given date range.

 All employees leave history for a given date range.

Activity 3

3.1. Write the complete pseudocode for the employee apply leave function of the above
system. Use the visual studio IDE (using C#.net) to implement the above two applications.
Ideally there should be two separate classes for the above two applications 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.

3.2. 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 two small GUI systems for the above scenario and those two
applications should be complete functional systems 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.

Page | 11
Sakuntha Sankalpa Programming – 01
Reading:
Aho, A. V. et al. (1987) Data Structures and Algorithms. 1st Ed. Addison-Wesley. Hunt,
A. et al. (2000) The Pragmatic Programmer: From Journeyman to Master. 1st Ed.

Addison-Wesley. McConnell, S. (2004) Code Complete: A Practical Handbook of


Software Construction. 2nd Ed. Microsoft Press.

HN Global:
HN Global HN Global (2021) Reading Lists. Available at:
https://hnglobal.highernationals.com/learning-zone/readin
g-lists

HN Global (2021) Student Resource Library. Available


at: https://hnglobal.highernationals.com/subjects/resource-
libraries

Page | 12
Sakuntha Sankalpa Programming – 01
Content

Page | 13
Sakuntha Sankalpa Programming – 01
s
Activity 01..................................................................................................................................................................15
Explanation for Computer algorithms...................................................................................................................16
characteristics of good computer algorithm...........................................................................................................16
The Fibonacci and Factorial Number Algorithms...................................................................................................17
The programming process.....................................................................................................................................19
Challenges to be faced in programming process...................................................................................................22
Taking a Sample Number and dry run above fibonaci and factorial number series..............................................22
Big O notation........................................................................................................................................................24
Python Code of financial numbers........................................................................................................................25
Python Code of factorial numbers.........................................................................................................................26
Evaluate the implementation of an algorithm in a suitable language...................................................................27
relationship between the written algorithm and the code variant........................................................................29
Activity 02..................................................................................................................................................................29
Programming paradigms.......................................................................................................................................30
Coding examples of programming paradigms.......................................................................................................41
Critically evaluating the source code of an application that implements the procedural, object-orientated and
event-driven paradigms........................................................................................................................................47
Activity 03..................................................................................................................................................................48
pseudocode for the employee apply leave function of the system.......................................................................48
The database structure of Grifindo Lanka Toys leaves management system........................................................50
features of an Integrated Development Environment (IDE)..................................................................................51
Evaluate the use of the Visual Studio IDE for my application development contrasted with not using an IDE.....52
GUI applications of Grifindo Lanka Toys................................................................................................................54
debugging process and the features available in Visual studio IDE for debugging................................................65
Coding Standards in Application Development.....................................................................................................67
Why Coding Standards Are Necessary...................................................................................................................68
References.................................................................................................................................................................69

Page | 14
Sakuntha Sankalpa Programming – 01
Acknowledgement
I would like to express my sincere gratitude to Ms. Lasanthika Jayasekara for her guidance and support throughout
this programming module. Her expertise and dedication have been invaluable in helping me understand the
concepts and complete this assignment successfully. Thank you for your encouragement and for fostering an
environment of learning and growth.

Introduction
This assignment is part of the programming module, focusing on the fundamental concepts and techniques
essential for developing software applications. Throughout this module, various programming paradigms,
algorithms, and data structures were explored, providing a solid foundation in coding practices. This document
outlines the steps taken, the methodologies applied, and the results achieved during the completion of the
assignment, highlighting the key learning outcomes and challenges encountered.

Page | 15
Sakuntha Sankalpa Programming – 01
Activity 01

P1 Define an algorithm and outline the process in building an application

Explanation for Computer algorithms

Algorithms - their meaning in computer science

In Computer Science, an algorithm is a list set of instructions, used to solve problems or perform tasks,
based on the understanding of available alternatives.

Algorithms are more than just programming, they are specifications for performing calculations, data
processing, automated reasoning or decision making for example (non-exhaustive list).
To this extent, it is necessary to understand what it means for an algorithm to be correct, and to accurately
solve the problem at hand. (Cross and Cross, 2022)

characteristics of good computer algorithm.

A good computer algorithm usually has the following characteristics

 Correctness
 The algorithm should correctly solve the problem it was designed to address. This means it
produces the expected output for all possible valid inputs.

 Efficiency
 The algorithm should use resources such as time (speed) and space (memory) efficiently. This
is often measured in terms of time complexity (how the runtime scales with the size of the
input) and space complexity (how the memory usage scales with the size of the input).

 Clarity and Simplicity


 The algorithm should be easy to understand and implement. A clear and simple algorithm is
less prone to errors and easier to debug, maintain, and optimize.

 Generality
 A good algorithm should work across a wide range of inputs and not just for specific cases. It
should be flexible enough to handle variations in the input size and type.

 Scalability
 The algorithm should perform well even as the size of the input data grows significantly.
Scalability ensures that the algorithm can handle large-scale problems without a drastic
Page | 16
Sakuntha Sankalpa Programming – 01
increase in resource usage.

 Robustness
 The algorithm should be able to handle unexpected or unusual inputs gracefully, including
edge cases and potential errors in the input data. It should fail gracefully if an error occurs.

 Maintainability
 The algorithm should be written in a way that is easy to modify and update. This includes
using clear naming conventions, modular design, and comprehensive documentation.

 Optimality
 The algorithm should provide the best possible solution to the problem, given the constraints.
In some cases, this means finding the most efficient solution, while in others, it might mean
finding the most accurate or precise result.

 Portability
 The algorithm should be designed in a way that can be implemented on different platforms or
environments with minimal modification.

Below are some types of algorithms

 Sorting Algorithms
o Bubble Sort
o Merge Sort
o Quick Sort
 Search Algorithms
o Linear Search
o Binary Search
 Machine Learning Algorithms
o K-Means Clustering
o Decision Tree
 Dynamic Programming Algorithms
o Fibonacci Sequence
o Knapsack Problem

Page | 17
Sakuntha Sankalpa Programming – 01
(Gillis, 2022)
The Fibonacci and Factorial Number Algorithms

Fibonacci number series


 The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding
ones. It starts like this:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
 The mathematical Formula is:
fib(n)= fib(n-1) + fib(n-2)

Fibonacci number Displays using Pseudo code

BEGIN

DECLARE num, n, fib, x AS INTEGER

INPUT num,
FUNCTION fibonaci(n)
IF n == 1 THEN
RETURN 0
ELSE IF n == 2 THEN
RETURN 1
ELSE
SET fib TO fibonaci(n-1) + fibonaci(n-2)
RETURN fib
END IF
END FUNCTION

FOR x FROM 1 TO num


PRINT fibonaci(x)
END FOR

END

Factorial Number Algorithm

 A factorial of a number, written as n!, is the product of all positive integers less than or equal to
that number. For example, the factorial of 4 (written as 4!) is 4 times 3 times 2 times 1,

4! = 4 x 3 x 2 x 1 = 24.

 The mathematical Formula is:

fact(n) = 1 * 2 * 3 … * n

Page | 18
Sakuntha Sankalpa Programming – 01
Factorial number series Display using Pseudo code

BEGIN

INPUT: num
result = 1
For x from 1 to num:
result = result * x
PRINT result
END FOR

END

P2 Determine the steps taken from writing code to execution.

The programming process

Definition. The (SDLC) can be defined as the system and structured process by means of which the
quality of software is improved, in minimal production time and lowest cost possible. The (SDLC) is
directed towards the development process of high-quality software that fulfills and even surpasses
customers’ expectations and requirements.

All programming involves creating something that solves a problem. The problems can range from
something of great scientific or national importance, through to something as trivial as relieving personal
boredom! This section describes one approach to solving such problems - think of it as a rough guide to
the things you should do (Bham.ac.uk, 2020)

In broad terms, those things are:

1. Identify the Problem


2. Design a Solution
3. Write the Program
4. Check the Solution
Page | 19
Sakuntha Sankalpa Programming – 01
1) Identify the Problem

 In fact, this stage should really be named as identification of the solution because in fact what is
being attempted here is to determine precisely what it is that one is seeking to achieve.

There are two Stages to identify a solution:

o Requirements
o Specifications

 Requirements

In fact, this stage should really be named as identification of the solution because in fact what is
being attempted here is to determine precisely what it is that one is seeking to achieve.

 Specifications

The second step is to then look at the list of requirements and to decide of it precisely what your
solution must do to meet it. There are again, as have been discussed earlier, often a large number
of options available to solve a single issue; here, your target is to choose which of those options
you prefer. Thus, you are attempting, in a somewhat accurate way, to define precisely the nature of
the action of your final program.

2) Design a solution

 Once you've identified the things required to solve your problem, and specified what form your
solution will take, the next step is to work out just how you're going to turn that specification into a
working program. This is usually the hardest task!

As mentioned before, a program is simply a list of steps describing to the computer what it should
do. A design is simply a higher-level description of those steps. In effect it's a program written as
if the computer was a person. So, it doesn't have to completely spell out every step - because
humans know how to do a lot of things already and have a lot of common sense, meaning that they
can work the simple steps out for themselves. It also doesn't have to be written in any special
programming language - English will do (although people often use special notations like
pseudocode or flow charts and diagrams for the more complicated sections.

3) Write the program

 Programming is the act of describing your design to the computer. It is giving commands to the
computer using a suitable language (programing language).

There are three Stages in write a program:

o Coding
o Compiling
o Debugging

 Coding

Page | 20
Sakuntha Sankalpa Programming – 01
Coding is the process of converting the design into an actual application written in some form of
programming language. (C#, python, Dart, Java, JavaScript)

 Compiling

In fact, compilation means the conversion of the program written in some or the other
programming language to the instructions formed by the combination of 0’s and 1’s which can be
easily understood by the computer. This is necessary because the chip that makes computer work
only understands binary machine code - something that most humans would have a great deal of
trouble using since it looks something like: This is necessary because the chip that makes your
computer work only understands binary machine code - something that most humans would have a
great deal of trouble using since it looks something like:

01110110
01101101
10101111
00110000
00010101

 Debugging

What is debugging?

Debugging is the process of finding and fixing errors or bugs in the source code of any software.
When software does not work as expected, computer programmers study the code to determine
why any errors occurred. They use debugging tools to run the software in a controlled
environment, check the code step by step, and analyze and fix the issue. (Amazon Web Services,
Inc., n.d.)

4) Check the Solution

Software testing is the act of checking all the relevant activities conducted with the purpose of
identifying whether the specific software program meets the needed level of quality and
functionality or not. The process verifies if there were any mistakes or holes and if the result of the
application is to the organization’s expectations before the software is deployed and available for
use.

What is software testing -:

Software testing is the process of evaluating and verifying that a software product or application
does what it’s supposed to do. The benefits of good testing include preventing bugs and improving
performance. (IBM, 2019)

Challenges to be faced in programming process

Page | 21
Sakuntha Sankalpa Programming – 01
Identify the Problem

Ambiguity in Requirements: - Sometimes, requirements can be ambiguous, which results in many


misunderstandings and numerous assumptions that may be incorrect.

Design a solution

Design Complexity: - This is perhaps the biggest challenge one can face when creating a design:
achieving the best

Technology Choices: - Selecting the appropriate technologies and frameworks is crucial and challenging.

Integration Issues: - Ensuring that different components of the system will integrate seamlessly can be
tough.

Write the program

Syntax and Semantics: - And in special the understanding of the syntax and semantics of the programming
language can’t be a problem for a developer.

Logical Errors: - Bugs that result from logical errors in the code can be hard to identify and fix.

Time Management: - Balancing speed and accuracy in coding is often a significant challenge.

Version Control: - Properly managing code versions and changes can be difficult,

Check the Solution

Automated vs. Manual Testing: - Deciding when to use automated tests versus manual tests can be
challenging.

Comprehensive Testing: - Ensuring all parts of the application are thoroughly tested can be time-
consuming.

Taking a Sample Number and dry run above fibonaci and factorial number series

Page | 22
Sakuntha Sankalpa Programming – 01
1. Fibonacci Numbers

 First, I input “10” which is equal to “num”, and I wrote the function “fibonaci(n)”. “n” is the
parameter of the fibonaci function.
 I created if, else statements like this (if n = 1 return 0 and if n = 2 return 1). If those statements are
false “fib” variable equal to “n-1” plus “n-2” then return “fib” and close the function

E.g. –

INPUT num,
FUNCTION fibonaci(n)
IF n == 1 THEN
RETURN 0
ELSE IF n == 2 THEN
RETURN 1
ELSE
SET fib TO fibonaci(n-1) + fibonaci(n-2)
RETURN fib
END IF
END FUNCTION

 After that I create a for loop. Its range is 1 to num. the “num” value is 10
 then “x” value is pass to the parameter “n”

E.g. –

FOR x FROM 1 TO num


PRINT fibonaci(x)
END FOR

The outputs are: 0,1,1,2,3,5,8,12,21

outputs at the end of each iteration and the final output

Iteration of “x” n Fn-2 Fn-1 Fn


1 1 0 0 0
2 2 0 1 1
3 3 0 1 1
4 4 1 1 2
5 5 1 2 3
6 6 2 3 5
7 7 3 5 8
8 8 5 8 13
9 9 8 13 21

2. factorial numbers
Page | 23
Sakuntha Sankalpa Programming – 01
BEGIN

INPUT: num
result = 1
For x from 1 to num:
result = result * x
PRINT result
END FOR

END
 I input “10” as the “num”. After that created a variable as “result = 1”
 After That I created a for loop, it range is “1” to “10”.
 The “x” values are multiplied with the “rusalt” value

It outputs are: - 1, 2,6 ,24, 120, 720, 5040, 40320, 362880, 3628800

outputs at the end of each iteration and the final output

n n!
1 1
2 2
3 6
4 24
5 120
6 720
7 5040
8 40320
9 362880
10 3628800

Big O notation

 Big(O) notation is considered as the main objective of my research to evaluate the time complexity
as well as space complexity of the algorithm. In other words, it contributes as a way of assessing
how well an algorithm 'performs' and how much storage and computing resources it consumes.

 Big O notation is a powerful tool used in computer science to describe the time complexity or
space complexity of algorithms. It provides a standardized way to compare the efficiency of
different algorithms in terms of their worst-case performance. Understanding Big O notation is
essential for analyzing and designing efficient algorithms. (geeksforgeeks, 2018)

 Simply Big O notation is used to calculate algorithm’s time complexity and space complexity
E.g.-
1) Constant Time O (1)
 Constant time complexity: it is a scenario where the time of running an algorithm does not change
even with a variation in the size of the input data.
Page | 24
Sakuntha Sankalpa Programming – 01
 Example: Accessing an element in an array by index.
2) Linear Time O (n)
 where the algorithm's runtime grows linear with the input size.
 Example: Iterating through all elements in a list.
3) Logarithmic Time O (log n)
 Logarithmic time complexity, where the algorithm's runtime grows logarithmically with the input
size.
 Example: Binary search in a sorted array.
4) Quadratic Time O(n2)
 Quadratic time complexity, where the algorithm's runtime grows quadratically with the input size.
 Example: Simple sorting algorithms like bubble sort, insertion sort.
5) Linearithmic Time – O (n log n)
 The runtime grows in a combination of linear and logarithmic rates.
 Example: Efficient sorting algorithms like mergesort and heapsort.
6) Cubic Time – O(n3)
 The runtime grows cubically with the input size.
 Example: Certain dynamic programming algorithms.
7) Exponential Time – O(2n)
 The runtime grows exponentially with the input size.
 Example: Solving the traveling salesman problem using brute force.
8) Factorial Time – O(n!)
 The runtime grows factorially with the input size.
 Example: Solving the traveling salesman problem by evaluating all permutations.

Above big-O notations display in graph like this

(freeCodeCamp.org, 2018
Python Code of financial numbers

num=int(input("Enter The Number :"))


def fibonaci(n):
if n==1:
Page | 25
Sakuntha Sankalpa Programming – 01
return 0
elif n==2:
return 1
else:
fibo= fibonaci(n-1)+fibonaci(n-2)
return fibo
for x in range(1,num):
print(fibonaci(x))

Time complexity:

 Input Reading - “num=int(input("Enter The Number :")” This operation reads


the input from the user and converts it to an integer. The complexity of this operation is Big-O (1).

 Function Definition – “def fibonaci(n):” Defining a function has no effect on time


complexity, so we can consider this operation as Big-O(1)

 Recursive Case – “fibo= fibonaci(n-1)+fibonaci(n-2)” This “ else: ” block


contains the recursive calls to calculate Fibonacci numbers. The time complexity of these recursive
calls is exponential. which is Big-O(2n) in the worst case.

 Loop for Printing Fibonacci Sequence – “for x in range(1, num): ,


print(fibonaci(x))” This loop runs 1 to num times For each iteration, it calls
“fibonaci(x)” it’s time complexity is Big-O(2n).

Therefore, the overall time complexity of the fibonaci code is = O(1) + O(1) + O(2n) + O(2n)
= Bog-O(2n)
according to the above graph the time complexity is in horrible range. It is the worst case

space complexity:

 Input Reading – “num=int(input("Enter The Number :"))” The space complexity


of this operation is Big-O(1) because it stores only a single integer value.

 Function Call Stack - Each recursive call to “fibonaci(n)” adds a new frame to the call stack.
In the worst case, the maximum depth of the call stack will be” n”. Therefore, the space
complexity due to the call stack Big-O(n)

Therefore, the overall space complexity of the fibonaci code is = Big-O(n)


according to the above graph the time complexity is in fair range. It is good

Fibonaci number python codes Big-O notation is


 Time complexity: - Big-O(2n)
 Space complexity: - Big-O(n)
Python Code of factorial numbers

num=int(input("Enter The Number :"))


rusalt=1
for x in range(1,num+1):

Page | 26
Sakuntha Sankalpa Programming – 01
rusalt =rusalt*x
print(rusalt)

Time complexity:

 Input reading - “num = int(input(“Enter The Number :”))” This operation


reads the input from the user and converts it to an integer. The complexity of this operation is Big-
O (1).

 Initialization - “rusalt=1” This initializes the variable “rusalt”. This is also a constant time
operation, Big-O(1)

 Loop - “for x in range(1, num + 1):” The loop runs from 1 to “num”. The number
of iterations “num” so the loop run “num” times Big-O(n)

 Multiplication and Print: “Rusalt = rusalt*1” inside the loop the multiplication operation
is performed. Which is Big-O(1).For each iteration

Therefore, the overall time complexity of the factorial code is = O(1) + O(1) + O(1) +O(n)
= Big-O(n)
according to the above graph the time complexity is in fair range. It is good

Space complexity:

 Input Reading - “num = int(input(“Enter The Number :”))” this line reads an
integer input from the user the space used by “num” is O(n) as it stores a single integer value.

 Initialization - “rusalt=1” This initializes the variable “rusalt” to 1. The space used by
“rusalt” is also O(1) as it stores a single integer value.

 Loop - “for x in range(1, num + 1):” The loop runs from 1 to “num” The loop
variable “x” also requires O(1) space, as it stores a single integer value at any point in time.

 Multiplication and Print – “result = result * x:” Inside the loop, the multiplication
operation does not require additional space beyond what is already used by “result” and “x”.
The result of the multiplication is stored back in “result”, which remains O(1) space.

Therefore, the overall space complexity of the factorial code is = Big-O(1)

according to the above graph the space complexity is excellent. It is too good

factorial number python codes Big-O notation is


 Time complexity: - Big-O(n)
 Space complexity: - Big-O(1)
Evaluate the implementation of an algorithm in a suitable language

Algorithm assessment requires a number of procedures, and it differs based on an algorithm’s nature and
the chosen programming language. Here's a general approach:

Page | 27
Sakuntha Sankalpa Programming – 01
 Understanding the Algorithm
o Clarity of Purpose - Before you start working with an algorithm, ensure that you really
know what is expected of the algorithm. What challenge does it address? The expected
inputs and the expected outputs, also known as the forecasted input or output, must be
specified.

o Step-by-Step Breakdown - Split the given algorithm into steps/ instructions or write in the
pseudocode form. This is helpful in transforming it in code in the future.

 Choosing a Suitable Language


o Performance Needs - If the algorithm requires a lot of computation (for example, sorting
big arrays, real-time computations), such languages as C++, Java or Rust can be used.

o Ease of Implementation - If the speed of the algorithm’s development and its intelligibility
is the most important requirement, then, perhaps, it is better to use Python or JavaScript.

o Community and Libraries - Deliberate on the word environment of the language. For
instance, Python has numerous libraries for data science and machine learning making it
perfect for the related algorithms.

 Implementation
o Writing Code - In most cases, the pseudocode is strictly translated into a particular
programming language. Organizations must aim to adhere to such aspects as writing clear
code, avoiding confusing variable names and using consistent code style.

o Edge Cases - Apply the algorithm with conclusion to cases when the input is empty,
contains exceptional values or is in any other way problematic.

o Comments and Documentation - Two, make comments where one describes the purpose of
understanding complex parts, and the third part of documentation is to describe the general
approach.

 Testing the Algorithm


o Unit Tests - While developing your unit tests, it is crucial to write tests for normal or often
used cases, some special or corner cases, and finally, some test to cases with invalid inputs.

o Performance Testing - If necessary and for higher data volumes, it is possible to check the
algorithm in terms of its desired characteristics.

o Comparison - The above implementation can then be compared to others that has been
known for correctness and efficiency.

 Optimization
o Refactor - Always try to reduce the amount of code needed to solve a problem, but make
sure this doesn’t automatically translate into making the code less readable.

o Time and Space Complexity - Critical of the performance of the algorithm, including its
time and space complexity. Stabilize where possible but in case of need increase efficiency
of resource usage.

relationship between the written algorithm and the code variant.

Page | 28
Sakuntha Sankalpa Programming – 01
The relationship between a written algorithm and its code variant can be understood as follows: The
relationship between a written algorithm and its code variant can be understood as follows:

 Algorithm as a Blueprint
The algorithm is a simple working out of strategic logically orderly planned concept formula or set
of procedures to run a business. It can be stated mainly in plain or pseudocode and defines the
steps necessary for a desired result to be obtained. It is simply an algorithm which is written in
logical format without being tied to the specific language of programming.

 Code as the Implementation


The code variant is somewhat different – it is the actual working version of the algorithm in a
certain programming language. It is actually this transforming the general steps of an algorithm
into terms that can be understood by a computer. It relates to syntax, variables, functions, or other
wordings that makes the algorithm functions in the actual computation.

 From Concept to Execution


The process starts with the algorithm and that is the strategy to be followed in solving the problem.
This algorithm is then converted to code where the information is processed in accordance to rules
of a particular language. The code variant adds practicality to the algorithm by making it
operational on the computer platform.

 Clarity and Precision


However, the former can be slightly more free form, more a ‘concept,’ while the latter must be
stringent, exact. If there is any ambiguity with the algorithm it has to be cleared during coding to
make the program work the right way.

Therefore, the written algorithm is fundamental while the code variant is the representation of such a
concept in a given programming language.

Activity 02
P3 Discuss what procedural, object orientated and event driven paradigms are; their characteristics and the
relationship between them.

Programming paradigms

Page | 29
Sakuntha Sankalpa Programming – 01
Programming paradigms are fundamental approaches to programming that dictate how developers
conceptualize and structure their code. We can think of them as the guiding philosophies or blueprints
for writing code because they offer a unique lens through which to view and solve problems.

These paradigms shape the way programmers think about and structure their code. By understanding
different paradigms, you can gain new insights into writing more efficient, readable, and maintainable
code. (datacamp.com, n.d.)

(GeeksForGeeks, 2018)

Imperative paradigm

Imperative paradigm is the first programming paradigm that was developed. By this paradigm a program
is defined as a clear set of instructions inputted to a computer and made of sequences.

Therefore, the source code of imperative languages contains a list of instructions, which describe
particulars of operations to be done – and when – to yield a specific result. In other words, it is possible to
change the values stored in the variables, when the program is running. To control the commands,
controlling structures including loops or branches are integrated in the program.

 Imperative programming is a software development approach in computer science that employs


statements to modify the state of a program. Functions are implicitly coded at every step necessary
to solve a problem in imperative programming, hence pre-coded models aren't used. In contrast to
declarative programming, which tells the computer “What" the program should do, imperative
programming tells the machine “How" to do it. (www.javatpoint.com, n.d.)

These are the best-known imperative programming languages: (Java, Pascal, C, C#, C++, Python)

Declarative paradigm

Declarative programming is a paradigm of programming where instead of stating how something is to be


done, the specifications of what needs to be done are given. The approach in question is based around the
emphasis on what must be attained, rather than fundamental instructions on how this is to be done. It is
Page | 30
Sakuntha Sankalpa Programming – 01
different from an imperative program that has the command set which aims to solve a particular set of
problems and is developed through defining the sequence of steps necessary to get the solution.
Declarative programming refers to a certain category of problems with language implementation handling
the quest for solution. In some cases of parallel processing applications, the declarative programming
approach proves useful in easing the programming of some of the applications.

Order of expression or statements or the replication of a statement would not have any impact in
declarative programming. Declarative programming can be further categorized into constraint
programming, logic programming and constraint logic programming. Prolog, SQL and embedded SQL are
some of the well-known examples of declarative programming languages. Tools are provided to
programmers in declarative programming to allow abstraction of the implementation and to help in the
concentration of the issue. (Techopedia.com, n.d.)

Declarative programming language can also be implemented in various fields and some examples are
given below.
 Database Query Languages (SQL, XQuery)
 Markup Languages (HTML, XML)
 Logic Programming (Prolog, Datalog)
 Functional Programming Languages (Haskell, Lisp)
 Domain-Specific Languages (DSLs)

Procedural programming paradigm

Procedural programming is a programming paradigm that focus on the use of reference to procedures, it’s
a practice of breaking systems into small regulatory modules known as procedures or functions. Every
procedure include a set of steps that are used to accomplish simple tasks and this will aid in compiling and
dividing the processes. In procedural programming, the control flow depends on sequences, decisions, and
loops; therefore, it is easy to understand and solve. Some of the examples of procedural programming
languages are C and Pascal and in this paradigm of programming the problems under consideration are
divided into sub-problems on the basis of a top-down approach.

Procedural Programming can be defined as a programming model which is derived from structured
programming, based upon the concept of calling procedure. Procedures, also known as routines,
subroutines or functions, simply consist of a series of computational steps to be carried out. During a
program’s execution, any given procedure might be called at any point, including by other procedures
or itself. (GeeksForGeeks, 2019)

Characteristics of Procedural programming

 Sequence of Execution: -
Instructions are executed in a linear sequence, following a top-to-bottom approach. This makes the
program flow straightforward and easy to follow.

 Local and Global Variables: -


Procedural programming allows for the use of both local variables (declared within a procedure
and accessible only within that procedure) and global variables (declared outside all procedures
and accessible by any procedure).

 Parameter Passing: -
Procedures can accept inputs, known as parameters, and return outputs. This allows for the reuse
of code with different data.

 Control Structures: -
Page | 31
Sakuntha Sankalpa Programming – 01
Procedural programming relies heavily on control structures like loops (“for”,” while”)
conditions
(“If” “Switch”) and Jumps (“goto”) to control the flow of the program.

 Top-Down Approach: -
Development often follows a top-down approach, where high-level functionality is defined first,
and then detailed by breaking it down into smaller procedures.

Advantages of Procedural programming

 Versatility: -
Thus, procedural programming is a very flexible paradigm that enables developing very diverse
coding projects with rather dramatically different aims. Procedural programming languages are
available for almost all sorts of development projects ranging from software and web development
and therefore there is always a procedural programming language that can help one to achieve his
or her intended goals.

 Simplicity: -
Procedural programming is a relatively simple approach to computer programming. This is why
many developers start working with procedural programming languages, as they provide a
foundation for coding that the developer can apply as they learn other languages, such as an
object-oriented language.

 Accessibility: -
It should also be noted that the most commonly used programming languages come with
procedural programming as a basis, which is why there are many references for a beginner who
dreams of knowing them. This also encompasses those paid courses that are available including
the free online resources and communities you can visit when you encounter these challenges with
help in fast tracking your development.

Disadvantages of Procedural programming

 Complexity: -
While procedural programming languages have the advantage of simplicity, this results in a
problem when one is trying to develop intricate programs. Sometimes, it might be better to choose
a language with the object-oriented approach when working on more detailer’s projects.

 Troubleshooting: -
The use of global data in procedural programming languages can make it challenging to identify
the source of errors in your code. This can cause a complex debugging process, adding time to
your development schedule.

 Troubleshooting: -
The use of global data in procedural programming languages can make it challenging to identify
the source of errors in your code. This can cause a complex debugging process, adding time to
your development schedule.

Object-oriented programming paradigm.

Object-oriented programming is a programming paradigm, or classification, that organizes a group of data


attributes with functions or methods into a unit, known as an object. Typically, OOP languages are class-
based, meaning a class defines the data attributes and functions as a blueprint for creating objects, which
Page | 32
Sakuntha Sankalpa Programming – 01
are instances of the class. One class may represent multiple independent objects, which interact with each
other in complex ways.

Object-oriented programming (OOP) is a computer programming model that organizes software design
around data, or objects, rather than functions and logic. An object can be defined as a data field that has
unique attributes and behavior. (Gillis, 2021)

(www.javatpoint.com, n.d.)

What is the structure of object-oriented programing?

The structure, or building blocks, of object-oriented programming include the following:


 Classes
Classes are user-defined types of data that provide the blueprint by having the attributes and the
methods of objects.

 Objects
An object is a real-world element in an object–oriented environment that may have a physical or a
conceptual existence.
Objects can be modelled according to the needs of the application. An object may have a physical
existence, like a customer, a car, etc., or an intangible conceptual existence, like a project, a
process, etc.

 Methods
Methods are functions that objects can perform. They are defined inside a class that describe the
behaviors of an object. Each method contained in class definitions starts with a reference to an
instance object. Additionally, the subroutines contained in an object are called instance methods.
Programmers use methods for reusability or keeping functionality encapsulated inside one object
at a time.

 Attributes
indicate the state of an object. In other, they are traits that define classes. Objects have data in the
field of attributes. These kinds of attributes are owned by the class and they are developed when
one is creating the class template.

Object-oriented languages are: - Python, C#, Dart, Java, etc....


Page | 33
Sakuntha Sankalpa Programming – 01
What are the main principles of OOPs: -
 Encapsulation
 Abstraction.
 Inheritance.
 Polymorphism

Encapsulation

Encapsulation is a mechanism that allows us to bind data and functions of a class into an entity. It protects data and
functions from outside interference and misuse. Therefore, it also provides security. A class is the best example of
encapsulation.

(Muniz, 2023)

The encapsulation principle states that all important information is contained inside an object and only
select information is exposed. The implementation and state of each object are privately held inside a
defined class. Other objects do not have access to this class or the authority to make changes. They are
only able to call a list of public functions or methods. This characteristic of data hiding provides greater
program security and avoids unintended data corruption. (Gillis, 2021)

Why should we use encapsulation in programming?

Encapsulation in programming is used to improve code maintainability, security, and flexibility. It enables
the bundling of data and methods that operate on that data within a single unit (i.e., a class or object),
making it easier to manage and understand (StudySmarter UK, n.d.)

Deferent types of Encapsulations: -


 Data Member Encapsulation
 Method Encapsulation
 Class Encapsulation

Advantages using Encapsulation: -


 Data Protection
 Flexibility
 Reusability

Page | 34
Sakuntha Sankalpa Programming – 01
Abstraction

(Pankaj, 2022)

Abstraction occurs when a programmer hides any irrelevant data about an object or an instantiated class to
reduce complexity and help users interact with a program more efficiently. The term abstraction vs
encapsulation can describe the process of hiding some of the information contained in an object or class,
but it may also refer to the object itself. An abstraction is any named entity that contains a selection of
data and behaviors specific to a particular usage of the originating entity.

Types of Abstractions are: -


 Data Abstraction

 Process Abstraction

There are the following advantages of abstraction:

 It reduces complexity
 It avoids delicacy
 Eases the burden of maintenance
 Increase security and confidentially

Inheritance

The concept allows us to inherit or acquire the properties of an existing class (parent class) into a newly
created class (child class). It is known as inheritance. It provides code reusability.

Page | 35
Sakuntha Sankalpa Programming – 01
(Gautam, n.d.)

In object-oriented programming (OOP), inheritance is a mechanism that allows a class to inherit


properties and behaviors from another class. It is a fundamental concept in OOP that promotes code
reuse and establishes relationships between classes.

Advantages of Inheritance in OOP: -

 Code reusability
 Efficiency
 ease of maintenance
 modification
 modularity
 organization.

Types of Inheritance in OOPs are: -

 Single Inheritance.
 Multiple Inheritance.
 Multilevel Inheritance.
 Hierarchical Inheritance.
 Hybrid Inheritance.

Polymorphism

Page | 36
Sakuntha Sankalpa Programming – 01
The word polymorphism is derived from the two words i.e. ploy and morphs. Poly means many and
morphs means forms. It allows us to create methods with the same name but different method signatures.
It allows the developer to create clean, sensible, readable, and resilient code.

(www.javatpoint.com, n.d.)

The above figure best describes the concepts of polymorphism. A person plays an employee role in the
office, father and husband role in the home.

What is polymorphism?

Polymorphism is the ability for something to take on many forms. In terms of a programming language
exhibiting this characteristic, we can create class objects that are inherited from the same parent class and
have the same names but different behaviors. Variables and functions also exhibit polymorphic behavior
in OOP by using a single interface with different underlying forms. This increases the language's ability to
reuse the same lines of code on multiple occasions. (App Architecture, n.d.)

Types of polymorphism

 Compile-time polymorphism.
 Runtime polymorphism.

Advantages of polymorphism

 It helps programmers reuse the code and classes once written, tested and implemented. They can
be reused in many ways.
 Single variable names can be used to store variables of multiple data types (Float, double, Long,
Int etc.).
 Polymorphism helps in reducing the coupling between different functionalities.

Advantages of using Object-oriented programming

Page | 37
Sakuntha Sankalpa Programming – 01
 Encapsulation: -
o Objects can hide their internal state and require all interaction to be performed through an
object's methods, which provides a clear structure.
 Reusability: -
o Objects and classes can be reused across different programs.
 Maintainability: -
o Code is more manageable and easier to modify when changes are needed, thanks to
encapsulation and modularity.
 Simplification: -
o By abstracting complex realities, OOP allows for simplified interfaces and interactions.
 Flexibility: -
o Objects can be treated as instances of their parent class rather than their actual class,
allowing for dynamic method binding and more flexible code.
 Teamwork: -
o OOP facilitates division of labor in a team, as different members can work on different
objects or classes independently.

Disadvantages of using Object-oriented programming

 Learning Curve: -
o OOP concepts like inheritance, polymorphism, and abstraction can be difficult for
beginners to understand.
 Overhead: -
o Creating and managing objects can introduce overhead and increase complexity, especially
in simple applications.
 Efficiency: -
o OOP can sometimes lead to less efficient performance due to the abstract layers and the
extra memory used by objects.
 Development Time: -
o Initial design and development can take longer due to the need for planning out the object
structures and interactions.
 Speed: -
o The use of objects can slow down a program compared to procedural programming due to
the additional processing needed to manage them.

Event Driven programming

Event driven programming is an approach to programming that is based on new events of the user such as
mouse clicks, key press or outputs from sensors, or messages from other programs. Event-driven
programming is a programming technique employed by programmers in graphical user interfaces and
other applications that address certain actions to be performed as a result of users’ input such as (user
clicks).

Event-driven programming (EDP) is a programming paradigm where external events determine the flow
of program execution. These events come in different shapes: user actions (e.g., button clicks, keyboard
inputs), system events (like a finished file download), messages from other programs, sensor outputs, etc.
(Quix.io, 2023)

Page | 38
Sakuntha Sankalpa Programming – 01
(Quix.io, 2023)

Characteristics of event Driven programming

 Service Oriented
Service oriented in one of the features of event driven programming that is used to write programs
that are made for services, and it takes does not slow down the computer as service oriented only
consume little of the computer processing power and usually services run in the background of
OS.
 Time driven
In event driven processing, time is a paradigm, it is a code that operates on a time frame and time
is a particular code that operates on a particular time, this is a set to do task at a certain time, for
instance, once a day, once a week or once a month. For instance, the windows update is an
example of a time-driven activity, which the user takes at a specified time to check and download
the update.

 Trigger functions
Trigger functions in event-driven programming are a function that decide what code to run when
there are a specific event occurs, which are used to select which event handler to use for the event
when there is specific event occurred.

 Events
Events are mouse, keyboard, and user interface, which events must be initiated in the program to
occur; these imply that the user interacts with an object in a program; for instance, by clicking a
button using a mouse or hitting a button using a keyboard among others.

Page | 39
Sakuntha Sankalpa Programming – 01
Advantages of using event driven programing.

 Improved User Experience: -


EDP is highly responsive to user inputs, making it ideal for GUI applications where user
interaction is paramount.

 Real-time Processing: -
It allows programs to process real-time events efficiently, which is essential for applications like
gaming, embedded systems, and IoT devices.

 Maintainability: -
This modularity also makes it easier to update and maintain the code, as changes in one part of the
program are less likely to impact other parts.

 Adaptability: -
EDP systems can easily adapt to new types of events, making them flexible to changing
requirements or new features.

 Scalable to Complex Systems: -


EDP can scale well to complex applications because it can handle a large number of events
efficiently.

disadvantages of using event driven programing.

 Difficult Debugging: -
Debugging can be challenging due to the asynchronous nature of event handling. Events can occur
in an unpredictable order, making it hard to trace issues.

 Event Handling Overhead: -


There can be performance overhead associated with managing the event queue and dispatching
events, which might not be suitable for performance-critical applications.

 Higher Memory Usage: -


Event-driven systems might require more memory to manage the event queue and maintain the
state of various event handlers.
 CPU Usage: -
Continuous polling for events can lead to higher CPU usage, although this is less of an issue with
modern hardware and efficient event-loop implementations.

 Learning and Understanding: -


For developers new to the paradigm, understanding and effectively using EDP can have a steeper
learning curve compared to more straightforward procedural or object-oriented approaches.

Use Cases of Event Driven Programming


 Graphical User Interfaces (GUIs)
 Web Development
 Embedded Systems
 Games

Coding examples of programming paradigms


Page | 40
Sakuntha Sankalpa Programming – 01
Procedural programming paradigm

Example code and their output for the represent Procedural programming paradigm

Python: -

Explanation above code: -

 I define a function call “sum” that takes a single argument “sample_list”


 Inside the function, I created a variable called “total” initialized to 0.
 The function then iterates over each element “x” in “sample_list” and adds its value
to “total”.
 After the loop is completed, the function returns the final value of “total”.
 The “sum” function is called twice. They are,
o “Print(sum(list1))” calculates the sum of elements in list1 and prints the rusalt
o “Print(sum(list2))” calculates the sum of elements in list2 and prints the rusalt

Object-oriented programming paradigm

Page | 41
Sakuntha Sankalpa Programming – 01
Encapsulation

Example code and their output for the represent Encapsulation


Python -

Explanation above code: -

 I define a class called “Person” with an “__init__” method that initializes two private
attributes: “__name” and “__age”.
 The “get_age” method returns the value of the private “__age” attribute.
 The “set_age’ method allows us to update the “__age” attribute if the provided age is greater
than 0.
 I create an instance of the “person” class named “p” with tha name “Amal” and an initial age
of 30
 I print the current age using “p.set_age()”, which outputs 30.
 Next, I set the age to 35 using “p.set_age(35)”
 After this update, I print the age again, which now outputs 35.
 Finally, attempt to set the age to -5 using “p.set_age(-5)”, However, since the provided age
is not greater than 0, the age remains unchanged.

Abstraction
Page | 42
Sakuntha Sankalpa Programming – 01
Example code and there output for the represent abstraction

Explanation above code: -

 Abstract base class (ABC)


o The “ABC” module provides mechanisms for abstract base class in python.
An abstract base class is a class that defines a common interface for its subclasses but
cannot be instantiated itself.
o In this code, “Animal” is an abstract base class (ABC)
 “Animal” class
o The “Animal” class inherits from “ABC”, which means it is an abstract base class.
o It defines an abstract method called “sound ()”. Subclasses of “Animal” must
implement this method.
 “Dog” class
o The “dog” class inherits from “Animal”.
o It overrides the “sound ()” method and returns the string “Woof”.
 “Cat” class
o The” Cat” class also inherits from “Animal”.
o It overrides the “sound ()” method and return the string “meow”
 Creating instance
o The lines “dog=Dog ()” and “cat=Cat ()” create instance of the “Dog” and
“Cat” classes, respectively
 Calling “Sound ()” Method
o The lines “print(dog.sound())” and “print(cat.sound())” call the
“sound()” method on the “dog” and “cat” instances

Inheritance
Page | 43
Sakuntha Sankalpa Programming – 01
Example code and there output for the represent Inheritance
Python -

Explanation above code: -


 Class Definitions:
o There are two classes defined “Animal” and “Dog”.
o “Animal” is the base class, and “Dog” is a derived class (or subclass) of “Animal”.
 Method Definitions:
Both classes have methods:
o “Animals” have a single method called “eat()”, which prints “I can eat”.
o “Dog” has an additional method called “display()”, which prints the dog’s name.
 Creating an Instance:
o An instance of the “Dog” class is created using the following line: “labrador = Dog()”
o This creates an object (Instance) of the “dog” class.
 Setting the dog’s name:
o The next line assigns the name “Scooby” to the “name” attribute of the labrador object
“labrador.name =”Scooby”.
 Method calls:
o “labrador.eat()” calls the “eat()” method inherited from the “Animal”
class, Which prints “I can eat”.
o “labrador.display()” call the “display()” method specific to the “dog” class
which prints “my name is Scooby”

Polymorphism
Page | 44
Sakuntha Sankalpa Programming – 01
Example code and their output for the represent Polymorphism

Python -

Explanation above code: -

 I’ve defined a base class called “Animal”. This class has a method called “make
_sound()”, which prints “Generic animal sound” when called.
 Next, I’ve defined two subclasses “dog” and “cat”. Both of those subclasses are inherited
from the “Animal” class.
 The “dog” class overrides the “make_sound()” method. When I create an instance of “dog”
and call its “make_sound()” method, it will print “woof”
 Similarly, the “cat” class also overrides the “make_sound()” method. When I create an
instance of “cat” and call its “make_sound()” method, it will print “meow”
 Finally, I’ve created a list called “animals” containing instance of both “dog” and “cat”.
The loop literates through each animal in the list and call its “make_sound()” method

Event Driven programing paradigm

Page | 45
Sakuntha Sankalpa Programming – 01
Example python code -

Its output –

 Importing tkinter
o The first line “import tkinter an tk” impots the “tkinter” module and assign
it the alias “tk”.
o “tkinter” is standard python library for GUI applications.
 Creating a GUI window
o “Root = tk.Tk()” creates the main application window.
o “Root.title(“Event Driven Example”)” seats the title of the window.
 Widgets
o “label = tk.label(root, text =”Enter your name :”)” create a label
widget with specified text
o “entry = tk.Entry(root)” creates an input field (entry widget) where the user can type their
name.
o “button =tk.Button(root, text="Submit",
Page | 46
Sakuntha Sankalpa Programming – 01
command=update_label)” creates a button widget with the label “Submit” and
associates it with the “update_label” function.

 Layout
o “pack()” is used to organize widgets within the window. It arranges them vertically with
padding “pady” between them
 Event handling
o The “command=update_label” parameter in the button widget specifies that when
the button is clicked, the “update_label” function should be called.

 Main Event Loop:


o “root.mainloop()” starts the event loop, which listens for user interactions (button
clicks, etc.) and updates the GUI accordingly.

Critically evaluating the source code of an application that implements the procedural, object-
orientated and event-driven paradigms

To critically evaluate the source code of an application that implements procedural, object-oriented, and
event-driven programming paradigms, it's essential to analyze the code structure, characteristics, and the
strengths and weaknesses of each paradigm.

1. Procedural Programming

Characteristics -

Procedural programming is centered around the concept of procedure calls, where the program is divided
into functions or routines that operate on data. This paradigm emphasizes a linear top-down approach and
treats data and procedures as separate entities.

Strengths-
 Simplicity: Procedural code is often straightforward and easy to understand, especially for
beginners.
 Modularity: The division of code into procedures promotes modularity, making it easier to
manage and maintain.
 Reusability: Functions can be reused across different parts of the program, reducing redundancy.

Weaknesses -
 Data Exposure: Data is often exposed globally, leading to potential security issues.
 Limited Reusability: While functions can be reused, the paradigm does not inherently support the
reuse of code structures in different contexts.
 Difficulty in Managing Complexity: As applications grow, procedural code can become
unwieldy and harder to manage due to its linear nature.

2.Object-Oriented Programming (OOP)


Page | 47
Sakuntha Sankalpa Programming – 01
Characteristics -

OOP focuses on encapsulating data and behavior into objects, which represent real-world entities. Key
principles include inheritance, polymorphism, and encapsulation.

Strengths -
 Data Abstraction: OOP allows for data hiding, enhancing security and reducing the risk of
unintended interference.
 Reusability: Inheritance enables code reuse across different classes, reducing redundancy and
improving maintainability.
 Modularity: Code is organized around objects, making it easier to understand and manage
complex systems.

Weaknesses -
 Complexity: OOP can introduce complexity in design and implementation, particularly for new
developers.
 Performance Overhead: The abstraction layers can lead to performance issues, especially in
resource-constrained environments.

3.Event-Driven Programming

Characteristics -

Event-driven programming revolves around the concept of events, where the flow of the program is
determined by user actions or other events. This paradigm is commonly used in graphical user interfaces
(GUIs) and asynchronous programming.

Strengths -
 Responsiveness: Applications can respond to user inputs and events in real-time, enhancing user
experience.
 Decoupling: Event-driven architectures promote loose coupling between components, making
systems easier to modify and extend.
 Scalability: This paradigm is well-suited for applications that require handling multiple events
simultaneously, such as web applications.

Weaknesses -
 Debugging Difficulty: The asynchronous nature of event-driven programming can complicate
debugging and tracking the flow of execution.
 State Management: Managing the state across different events can be challenging, leading to
potential inconsistencies.

Conclusion

In evaluating the source code of an application that employs these three paradigms, it is crucial to consider
the specific use case and requirements of the application. Each paradigm offers distinct advantages and
challenges that can significantly impact the application's performance, maintainability, and user
experience. A well-structured application may leverage the strengths of each paradigm while mitigating
their weaknesses, resulting in a robust and efficient system.
procedural object-orientated event-driven
Page | 48
Sakuntha Sankalpa Programming – 01
In procedural code, functions or Consider the use of classes, Event-driven code responds to
procedural are the main building objects and inheritance. events (user inputs, system
blocks. events, etc.).
Assess whether the application’s Evaluate the design or classes Check how events are handled
procedural code is well-structured, whether they encapsulate data whether through callback,
with logical flow and minimal and behavior effectively. listeners, ore event driven
redundancy. architecture.
Look for any global variables or Look for proper use of Evaluate the responsiveness and
side effects that might impact inheritance, polymorphism, and efficiency of event handling.
maintainability. interfaces.

Activity 03
Page | 49
Sakuntha Sankalpa Programming – 01
P4 - Write a program that implements an algorithm using an IDE.

pseudocode for the employee apply leave function of the system

START

IF employee is not logged in THEN


Display a message: "Please login to apply for leave."
END the function

ELSE IF leave type !="Annual" && leave type !="Casual"&& leave type !="Short" THEN
Display a message: "Invalid leave type."
END the function

ELSE IF start date < today THEN


Display a message: "Leave start date cannot be in the past."
END the function

ELSE IF leave = = "Annual" && start date < 7 days from today THEN
Display a message: "Annual leave must be requested at least 7 days in advance."
END the function

ELSE IF leave = = "Short" && duration > 1 hour and 30 minutes THEN
Display a message: "Short leave cannot exceed 1 hour and 30 minutes."
END the function

ELSE IF Number of holidays taken > Holiday limit THEN


Display a message: "Not enough leave days available now."
END the function

ELSE IF the leave request is successfully created THEN


Deduct the leave days from the employee's balance
Display a success message with the leave request ID

ELSE
Display an error message: "Failed to apply for a leave. Please try again later."
END

Page | 50
Sakuntha Sankalpa Programming – 01
Visual studio IDE (C#.net) Implementation of the above algorithms

Page | 51
Sakuntha Sankalpa Programming – 01
The database structure of Grifindo Lanka Toys leaves management system

Page | 52
Sakuntha Sankalpa Programming – 01
implement in Microsoft SQL Server management Studio

features of an Integrated Development Environment (IDE)

 Code Editor
Page | 53
Sakuntha Sankalpa Programming – 01
Provides syntax highlighting, auto-completion, and error detection, making it easier to write and
understand code.

 Debugging Tools
Allows you to set breakpoints, inspect variables, and step through code, which helps in identifying
and fixing bugs.

 Integrated Version Control


Supports version control systems like Git, enabling you to manage code versions, collaborate with
others, and track changes.

 Build Automation Tools


Streamlines the process of compiling code, running tests, and deploying applications, saving time
and reducing manual effort.

 Code Navigation
Offers features like go-to-definition, find references, and code folding, which make it easier to
navigate large codebases.

 Refactoring Support
Provides tools for renaming variables, extracting methods, and other refactoring tasks, helping
you improve code quality and maintainability.

 Plugins and Extensions


Supports a wide range of plugins and extensions that can add new features or integrate with other
tools and services.

 Integrated Terminal
Includes a terminal or command-line interface within the IDE, so you can run commands without
leaving the development environment.

 Project Management
Helps organize and manage project files, dependencies, and configurations in a structured manner.

 Real-Time Collaboration
Some IDEs offer features for real-time collaboration, allowing multiple developers to work on the
same code simultaneously.

 Language Support
Often comes with support for multiple programming languages and frameworks, making it
versatile for different types of projects.

 Documentation and Help


Provides integrated documentation and access to help resources, making it easier to learn new
languages and technologies.

Evaluate the use of the Visual Studio IDE for my application development contrasted with not
using an IDE
Page | 54
Sakuntha Sankalpa Programming – 01
 Code Navigation and Writing
o Visual Studio provides efficient code navigation tools, allowing developers to quickly find,
understand, and modify code. Features like IntelliSense (code completion), code snippets,
and AI-assisted development tools (such as GitHub Copilot) enhance productivity.
o Contrast: Without an IDE, developers might struggle with manual code navigation, leading
to slower development and more errors.

 Debugging and Profiling:


o Visual Studio’s integrated debugger allows developers to identify and fix issues efficiently.
Features like breakpoints, watch windows, and step-by-step execution aid in debugging.
o Profiling tools help optimize performance by identifying bottlenecks.
o Contrast: Debugging without an IDE involves manual print statements or external tools,
which can be time-consuming and error prone.

 Testing Tools:
o Visual Studio offers comprehensive testing tools, including unit testing, code coverage
analysis, and load testing.
o Developers can ensure code quality and catch issues early.
o Contrast: Without an IDE, setting up and running tests becomes more cumbersome.

 Version Control Integration:


o Visual Studio seamlessly integrates with version control systems (e.g., Git). Developers
can manage code changes, collaborate, and track history.
o Contrast: Without an IDE, version control requires using external tools or commands.

 Collaboration and Agile Workflows:


o Visual Studio supports agile methodologies with features like work item tracking, sprint
planning, and team collaboration.
o Contrast: Without an IDE, managing agile processes becomes manual and less efficient.

 Extensions and Customization:


o Visual Studio allows developers to extend functionality through thousands of extensions
(e.g., ReSharper, Visual Studio Code extensions).
o Customization options enhance the development experience.
o Contrast: Without an IDE, developers miss out on these productivity-enhancing extensions.

Activity 04
Page | 55
Sakuntha Sankalpa Programming – 01
GUI applications of Grifindo Lanka Toys.

Employees Application

 Login page

Employees can login using the given password and employee number. The password and
employee number have created Admin. Its user interface is like this

If the username and password, you entered are correct or incorrect. This message boxes will show

Login page codes.

Page | 56
Sakuntha Sankalpa Programming – 01
 Apply leaves page

Page | 57
Sakuntha Sankalpa Programming – 01
Employees can apply for leave using this page. employee can see a leave is approved or reject

Apply leaves page codes.

Page | 58
Sakuntha Sankalpa Programming – 01
 Dashboard page

When you enter your employee number you can see if your applied leaves have been approved or
rejected and holidays and available leaves can show

Page | 59
Sakuntha Sankalpa Programming – 01
Dashboard page code

Admin Application

Page | 60
Sakuntha Sankalpa Programming – 01
 Home page

You can choose what you want

 Add new employee page

Admins can add new employees. Admin can decide what employee number and password is. the interface
is like this

Page | 61
Sakuntha Sankalpa Programming – 01
Add new employees page code.

 Applied leaves page

admin can decide leave are reject or approved

Page | 62
Sakuntha Sankalpa Programming – 01
If you press Approve this message box will show.

If you press Reject this message box will show.

Applied leaves page codes

Page | 63
Sakuntha Sankalpa Programming – 01
 Leave history page

When you enter your employee number. you can see your applied leaves have been approved or rejected
and holidays and available leaves can show

Leave history page code

Page | 64
Sakuntha Sankalpa Programming – 01
 Add new holidays page.

Admins can decide what the holidays are.

Page | 65
Sakuntha Sankalpa Programming – 01
Add new holidays page codes.

Page | 66
Sakuntha Sankalpa Programming – 01
P5 Explain the debugging process and explain the debugging facilities available in the IDE.

Activity 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.

debugging process and the features available in Visual studio IDE for debugging

 Breakpoints

Set breakpoints at specific lines of code to pause execution and inspect variables, call stacks, and other
information.

 Navigate code in the debugger using step commands.

Step Into (F11): This command allows you to step into a method or function call. If you’re paused on a
line with a method call, pressing F11 will take you inside that method to see its execution.

Step Over (F10): Use this command to execute the current line of code and move to the next line. If the
current line contains a method call, it won’t step into that method; instead, it will execute it and move on.

Step Out (Shift + F11): When you’re inside a method (after using Step Into), Step Out will take you back
to the calling method. It’s useful when you want to skip the details of the current method and return to the
higher-level context.

 Run to curser
When you are editing code (rather than paused in the debugger), right-click a line of code in your app and
choose Run to Cursor (or press Ctrl + F10). This command starts debugging and sets a temporary
breakpoint on the current line of code. For more details on this feature and similar navigation features,
Page | 67
Sakuntha Sankalpa Programming – 01
(Mikejo5000, n.d.)

 Inspect variables with data tips


Now that you know your way around a little, you have a good opportunity to start inspecting your app
state (variables) with the debugger. Features that allow you to inspect variables are some of the most
useful features of the debugger, and there are different ways to do it. Often, when you try to debug an
issue, you are attempting to find out whether variables are storing the values that you expect them to have
in a particular app state. For detailed information on using data tips, (Mikejo5000, n.d.

Page | 68
Sakuntha Sankalpa Programming – 01
 Inspect variables with the Autos and Locals windows

In the Autos window, you see variables along with their current value and their type. The Autos window
shows all variables used on the current line or the preceding line (In C++, the window shows variables in
the preceding three lines of code. Check documentation for language-specific behavior). For more
information on using these windows, (Mikejo5000, n.d.)

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

1. Variable Naming Conventions

 Variables like holiday, date, and leave_type are named in a way that reflects their purpose, ensuring
readability.
 However, some names (e.g., guna2GradientButton1_Click) could be more descriptive to indicate the
button's purpose.

2. Indentation
 Use consistent indentation to improve readability.

Page | 69
Sakuntha Sankalpa Programming – 01
3. SQL Query Construction

 The query_insert string dynamically constructs an SQL query using concatenation.


 This approach works but is not a recommended standard due to potential SQL injection risks. Using
parameterized queries would be a safer standard.

4. Try-Catch-Finally Block

 Proper error handling is implemented using try-catch-finally.


 The finally block ensures the database connection (con) is closed regardless of success or failure, which
aligns with good resource management practices.

4. MessageBox Usage
 Informative messages (e.g., "Added New Holiday" and "error") are displayed to the user, which improves
user experience.
 However, the error message could be more specific to assist in debugging.

Page | 70
Sakuntha Sankalpa Programming – 01
5. Database Operations
 The cmd.ExecuteNonQuery() command executes the SQL query for inserting data.
 However, con.Open() is called after creating the SqlCommand object, which might not follow optimal
execution flow.

6. Hardcoded Dataset Adapter Usage


 The holidaysTableAdapter objects are explicitly referenced to update datasets.
 These could be abstracted or parameterized for more flexible and maintainable code.

7. Error Handling
 The catch block does not provide detailed error information, which might hinder debugging.

Why Coding Standards Are Necessary

For the Team


 Consistency: Coding standards ensure that all team members write code in a uniform manner,
making the codebase easier to read and understand for everyone.

 Maintainability: Consistent code is easier to maintain, debug, and enhance. This reduces the time
and effort required for new team members to get up to speed.

 Collaboration: With a shared understanding of coding practices, team members can collaborate
more effectively and avoid misunderstandings.

 Quality: Adhering to coding standards can help in catching potential bugs early and improving the
Page | 71
Sakuntha Sankalpa Programming – 01
overall quality of the software.

For the Individual


 Professional Growth: Following coding standards helps individuals write cleaner, more efficient
code, which is a valuable skill in their professional development.

 Readability: Writing code according to standards makes it easier for the individual to understand
their own code later, especially when revisiting it after some time.

 Efficiency: With established standards, individuals spend less time figuring out how to write or
format their code, allowing them to focus more on solving the actual problems.

 Error Reduction: Consistent practices help in minimizing errors and improving debugging
efficiency, as patterns in code become more predictable.

References
Page | 72
Sakuntha Sankalpa Programming – 01
Upadhyay, S. (2023). What Is An Algorithm? Characteristics, Types and How to write it | Simplilearn.
[online] Simplilearn.com. Available at:
https://www.simplilearn.com/tutorials/data-structure-tutorial/what-is-an-algorithm#:~:text=An
%20algorithm%20is%20a%20set.

‌Bham.ac.uk. (2020). The Programming Process. [online] Available at:


https://www.cs.bham.ac.uk/~rxb/java/intro/2programming.html.

IBM (2019). What is software testing? [online] Ibm.com. Available at:


https://www.ibm.com/topics/software-testing.

‌geeksforgeeks (2018). Analysis of Algorithms | Big-O analysis - GeeksforGeeks. [online] GeeksforGeeks.


Available at: https://www.geeksforgeeks.org/analysis-algorithms-big-o-analysis/.

Huang, S. (2020). What is Big O Notation Explained: Space and Time Complexity. [online]
freeCodeCamp.org. Available at: https://www.freecodecamp.org/news/big-o-notation-why-it-matters-and-
why-it-doesnt-1674cfa8a23c/.

GeeksForGeeks (2018). Introduction of Programming Paradigms - GeeksforGeeks. [online]


GeeksforGeeks. Available at: https://www.geeksforgeeks.org/introduction-of-programming-paradigms/.

javatpoint (2011). Java OOPs Concepts - Javatpoint. [online] www.javatpoint.com. Available at:
https://www.javatpoint.com/java-oops-concepts.

Stack Overflow. (n.d.). oop - What is polymorphism, what is it for, and how is it used? [online] Available
at: https://stackoverflow.com/questions/1031273/what-is-polymorphism-what-is-it-for-and-how-is-it-used.

Neubauer, T. (2023). The what, why and how of event-driven programming. [online] Quix.io. Available
at: https://quix.io/blog/what-why-how-of-event-driven-programming#:~:text=Event%2Ddriven
%20programming%20(EDP).

Page | 73
Sakuntha Sankalpa Programming – 01

You might also like