0% found this document useful (0 votes)
13 views153 pages

Programming Assigment Lahiru Sehan

Uploaded by

hopesp2877
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)
13 views153 pages

Programming Assigment Lahiru Sehan

Uploaded by

hopesp2877
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/ 153

Contents

Table of Figures........................................................................................................................4
Table of Tables.........................................................................................................................6
Activity 01...............................................................................................................................28
1.1 Algorithms......................................................................................................................28
1.2 Characteristics of a Good Algorithm..............................................................................30
1.3 Pseudo Codes.................................................................................................................32
1.4 Fibonacci Series.............................................................................................................39
1.5 Python Algorithm to Generate both Fibonacci and factorial Series in a Number..........46
Activity 02...............................................................................................................................51
2.1 Programming Paradigms: An Overview..................................................................51
2.2 Characteristics of Procedural Programming............................................................56
2.3 Object-Oriented Programming (OOP).....................................................................65
2.4 Event-Driven Programming...........................................................................................70
Activity 3.................................................................................................................................77
3.1 Pseudocodes of Grifindo Toys Payroll System..............................................................77
3.1.1 Salary Component..............................................................................................................77
3.2: Overview of Visual Studio IDE....................................................................................80
3.1.2 Implementing Visual Studio IDE to the Components..........................................................81
3.2 Creating Separate Classes for Components....................................................................83
3.3 Database Structure Design.............................................................................................86
3.3.1 Database Design Principles.................................................................................................86
3.3.2 Entities and Relationships in Employee System..................................................................87
3.3.3 SQL Table Creation for Employee Information...................................................................88
3.3.4 SQL Table Creation for Salary Information..........................................................................89
3.4 Features of a Integrated Development Environment (IDE)...........................................90
3.4.1 Code Editing and Autocompletion......................................................................................90
3.4.2 Debugging Tools.................................................................................................................90
3.4.3 GUI Design and Form Building............................................................................................91
3.5 Visual Studio IDE for Application Development..........................................................92
3.5.1 Advantages of Using Visual Studio......................................................................................92
3.5.2 Efficiency in Coding and Debugging....................................................................................93
3.5.3 Integration with .NET Framework.......................................................................................94
3.5.4 Visual Studio vs. Manual Development..............................................................................95
Activity 4.................................................................................................................................96
4.1 GUI Grifindo Toys payroll System................................................................................96
4.1.1 Loading Screen....................................................................................................................96
4.1.2 Login Page...........................................................................................................................97
4.1.3 Main Form..........................................................................................................................98
4.1.4 Home..................................................................................................................................99
4.1.5 Employee Component......................................................................................................100
4.1.6 Employe Salary Information Form....................................................................................101
4.1.7 Settings Component..........................................................................................................102
4.1.8 Salary Component............................................................................................................103
4.1.8 View..................................................................................................................................104
4.2 Debugging Process in Visual Studio............................................................................105
Setting Breakpoint.....................................................................................................................105
Inspecting Variables and Values........................................................................................105
Watch and Immediate Windows........................................................................................105
Exception Handling: Exception Handling..........................................................................105
Call Stack...........................................................................................................................105
4..2.1 Debugging Grifindo Toys Project.....................................................................................106
4.3 Coding Standards and outline of Grifindo Toys System..............................................109
4.4 Coding Standards in Software Development.........................................................132
Table of Figures

Figure 1 Algorithms (authors work).........................................................................................32


Figure 2 Pseudocode for Fibonacci Series (authors work).......................................................42
Figure 3 Pseudocode for Factorial Calculation (authors work)...............................................43
Figure 4 Dry Run Example for Fibonacci Series (n = 5) (authors work).................................44
Figure 51.3.5 Dry Run Example for Fibonacci Series (n = 4) (authors work).........................45
Figure 6 Python code for both Fibonacci and factorial Series generator(authors work)........49
Figure 7 Fibonacci and factorial Calculator.............................................................................50
Figure 8 Fibonacci Series for 20 is Calculated. (authors work)...............................................50
Figure 9 example of procedural code in Python that follows the principles of structured
programming. (authors work)..................................................................................................57
Figure 10 Results of a Structured Programming Procedural Code(authors work)...................58
Figure 11 Code Of My Simple GUI Average Calculator with a procedural code in Python that
follows the principles of structured programming(authors work)...........................................59
Figure 12 Code Of My Simple GUI For Calculating Average With Procedural Programming
..................................................................................................................................................59
Figure 13 Results 1...................................................................................................................60
Figure 14 Results 2(authors work)...........................................................................................60
Figure 15 Advantages and Disadvantages of Procedural Programming(authors work)..........61
Figure 16 Calculating the Sum of Numbers(authors work).....................................................62
Figure 17 results(authors work)...............................................................................................62
Figure 18 Reading and Writing Files(authors work)................................................................64
Figure 19 User Authentication(authors work)..........................................................................65
Figure 20 Results for User 1(authors work).............................................................................65
Figure 21 benefits and challenges of using Object-Oriented Programming (OOP) in larger
software systems(authors work)...............................................................................................69
Figure 22 Code and The Result For OOP Code(authors work)...............................................70
Figure 23 Code and Results for a Event-Driven Program (authors work)..............................72
Figure 24 Event Driven Architecture.......................................................................................76
Figure 25 Salary Component(authors work)............................................................................78
Figure 26 Salary Component Pseudo Code(authors work)................................................80
Figure 27 Visual Studio 2022 Interface along with Grifindo Toys Project(authors work)......81
Figure 28 Custom Class: ID Generator(authors work)............................................................84
Figure 29 Custom Class: ThemeChanger(authors work).........................................................85
Figure 30 Custom Class: TextAnimation(authors work).........................................................86
Figure 31 Grifindo Toys Employe and Salary Tables(authors work)......................................88
Figure 32 Employe table Expanded(authors work)..................................................................89
Figure 33 Salary Table Expanded(authors work).....................................................................90
Figure 34 Visual Studio Supporters.........................................................................................95
Figure 35 Loading Screen(authors work).................................................................................97
Figure 36 Login(authors work)................................................................................................98
Figure 37 Main Form(authors work)........................................................................................99
Figure 38 home(authors work)...............................................................................................100
Figure 39 Employee Form(authors work)..............................................................................101
Figure 40 Employe Salary Adding Form(authors work)........................................................102
Figure 41 Settings Component(authors work).......................................................................103
Figure 42 Salary Component(authors work)..........................................................................104
Figure 43 View(authors work)...............................................................................................105
Figure 44 Correct Info is Entered(authors work)...................................................................107
Figure 45 But It Says Invalid(authors work)..........................................................................107
Figure 46 Visual Studio Warning Indicating there is an Error(authors work).......................108
Figure 47 Visual Studio Error Handling(authors work).........................................................109
Figure 48 Loading Screen(authors work)...............................................................................110
Figure 49 Loading Texts and Initialization(authors work)....................................................111
Figure 50 Loading Texts and Initialization(authors work)....................................................111
Figure 51 timer Tick Event(authors work).............................................................................112
Figure 52 Simulating The Texts like a Loading Screen(authors work).................................113
Figure 53 Round Edged Form(authors work)........................................................................113
Figure 54 Validate Login(authors work)................................................................................114
Figure 55 Login Form, (authors work)...................................................................................115
Figure 56 If user input Invalid Info(authors work)................................................................115
Figure 57 Styling(authors work)............................................................................................116
Figure 58 Main Form(authors work)......................................................................................117
Figure 59 color 2(authors work).............................................................................................117
Figure 60 Color 1(authors work)............................................................................................117
Figure 61 Theme Class, Colors(authors work)......................................................................118
Figure 62 Color Selection(authors work)...............................................................................118
Figure 63 Button Activates upon Clicking(authors work).....................................................119
Figure 64 Button Activation(authors work)...........................................................................119
Figure 65 Button Deactivation(authors work)........................................................................120
Figure 66 other Buttons Deactivate upon Clicking another button(authors work)................120
Figure 67 Onpen Forms Withing another form(authors work)..............................................121
Figure 68 Employe Form opened in Main Form(authors work)............................................121
Figure 69 Display Time(authors work)..................................................................................122
Figure 70 Live time Can Be seen on Top(authors work).......................................................122
Figure 71 Id Generator(authors work)....................................................................................123
Figure 72 generated ID(authors work)...................................................................................123
Figure 73 Employe and Salary Details have Added Successfully(authors work)..................124
Figure 74 Data View(authors work).......................................................................................124
Figure 75 Data Updated(authors work)..................................................................................125
Figure 76 Data Deleted(authors work)...................................................................................125
Figure 77 Data Retrieve / Search(authors work)....................................................................126
Figure 78 Settings Component(authors work).......................................................................127
Figure 79 Salary Summary generation(authors work)...........................................................127
Figure 80 Generating and Displaying Salary Summary(authors work).................................128
Figure 81 Set Default information(authors work)..................................................................129
Figure 82 Generate Summary and Set Default info(authors work)........................................129
Figure 83 Salary Component.(Authors Work).......................................................................130
Figure 84 Retreve Employe information To the Salary Component (Authors Work)...........131
Figure 85 Salary Calculated According to the Given info (Authors work)...........................132
Figure 86 Salary Calculation Code (authors Work)...............................................................132
Figure 87 Team VS Individual Coding Standards(authors work)..........................................134
Table of Tables

Table 1 Table 1 Steps and Challenges in The Process of Writing and Executing a Computer
Program....................................................................................................................................36
Figure 2 Factorial of 20 is Calculated(authors work)...............................................................50
Table 3 Database Design Principles(authors work).................................................................86
Table 4 Manual Development Vs Visual Studio(authors work)..............................................95
Table 5 Debugging Processes in Visual Studio......................................................................105
Table 6 Coding Standards......................................................................................................132
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
G A Lahiru Shehan Karunarathne
Student’s name
List which assessment Pass Merit Distinction
criteria the Assessor has
awarded.
INTERNAL VERIFIER CHECKLIST
Do the assessment criteria awarded
match those shown in the Y/N
assignment brief?
Is the Pass/Merit/Distinction grade
awarded justified by the assessor’s Y/N
comments on the student work?
Has the work been assessed
Y/N
accurately?
Is the feedback to the student:
Give details:
• Constructive?
• Linked to relevant assessment Y/
criteria? N
• Identifying opportunities for Y/
improved performance? N
• Agreeing actions? Y/
N
Y/
N
Does the assessment decision need
Y/N
amending?
Assessor signature Date

Internal Verifier signature Date


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

Give details:

Assessor signature Date


Internal
Date
Verifier
signature
Programme
Date
Leader signature
(if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID
Unit Title
Assignment Number Assessor
Submission Date Date Received
1st submission
Re-submission Date Date Received 2nd
submission
Assessor Feedback:
LO1. Define basic algorithms to carry out an operation and outline the process of programming an applica
Pass, Merit & Distinction Descripts P1 M1 D1

LO2. Explain the characteristics of procedural, object-orientated and event-driven programming, con
analysis of a suitable 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 Date
signature
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

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
Studio IDE for your application development contrasted with not using an IDE.

Activity 4
2.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 have described in the above scenario with
the database structure which has designed in activity 3.
2.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.

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

1.1 Algorithms

Introduction to Algorithms
An algorithm is a precise, step-by-step set of instructions or a well-defined computational
procedure designed to solve a specific problem or perform a particular task. Algorithms are
fundamental to computer science and are used in various fields, including mathematics, data
processing, and programming.

Algorithms are not merely a fundamental aspect of computer science; they are the backbone of
modern computing. They provide a structured approach to problem-solving that is not limited to
any single domain. Whether you're navigating through complex mathematical equations, sorting
vast datasets, or instructing a computer to perform intricate tasks, algorithms are the guiding
principles that enable these operations to be executed with precision and efficiency.

In essence, algorithms are the intellectual building blocks of computation. They encapsulate
human ingenuity, logic, and problem-solving skills in a format that can be executed by machines.
These step-by-step procedures are like recipes in a cookbook, meticulously detailing each action
required to achieve a desired outcome.

One of the most captivating aspects of algorithms is their universality. They transcend specific
programming languages, hardware architectures, and application domains. An algorithm
developed to solve a mathematical problem can be just as applicable to processing images or
simulating physical phenomena. This versatility highlights the profound impact of algorithms on
diverse fields, from artificial intelligence and cryptography to finance and scientific research.

(Algorithms (4th Edition) by Robert Sedgewick and Kevin Wayne)

Gattapola Arachchilage Lahiru Shehan


28
Karunarathne
Importance of an Algorithm
Algorithms are the bedrock upon which computer science is built. They serve as the intellectual
framework that enables computers to perform tasks, process data, and solve complex problems.
The importance of algorithms in computer science and problem-solving cannot be overstated.

 Efficiency: Algorithms are pivotal in optimizing the use of computational resources, such
as time and memory. Efficient algorithms can significantly reduce the time it takes to
process data or find solutions, making them essential for large-scale applications.

 Problem Solving: Algorithms provide a structured approach to problem-solving. They


break down complex problems into manageable steps, allowing programmers to tackle
intricate challenges systematically.

 Reusability: Well-designed algorithms can be reused across different applications and


scenarios. This reusability reduces redundancy in code and promotes best practices in
software development.

 Scalability: In an era of big data and complex computations, algorithms play a crucial
role in ensuring that software systems can scale up to handle increasing workloads
efficiently.

 Foundation of Programming: Algorithms are the building blocks of computer programs.


Without algorithms, writing software to perform specific tasks would be impractical

 Innovation and Research: Researchers and scientists use algorithms to explore new ideas
and theories. They are essential tools for developing and testing hypotheses.

("Introduction to Algorithms" by Thomas H. Cormen)

Gattapola Arachchilage Lahiru Shehan


29
Karunarathne
Gattapola Arachchilage Lahiru Shehan
30
Karunarathne
1.2 Characteristics of a Good Algorithm

A good algorithm possesses several key characteristics that ensure its effectiveness and
reliability in solving problems.
Algorithms are the foundation of problem-solving in computer science and beyond. To be
considered effective, an algorithm must exhibit specific characteristics that make it trustworthy,
efficient, and adaptable.

1.2.1 Key Characteristics of a Good Algorithm

Correctness:

 A correct algorithm produces the desired output for all valid inputs. It accurately solves
the problem it was designed for.

 Correctness is paramount as an incorrect algorithm can lead to flawed results and costly
errors in applications.

Efficiency:
 An efficient algorithm accomplishes its task in a reasonable amount of time and with
minimal resource consumption, such as CPU time and memory.

 Efficiency is crucial for handling large datasets and time-sensitive applications. It


minimizes computational costs.

Gattapola Arachchilage Lahiru Shehan


31
Karunarathne
Clarity:
 A good algorithm is clear and easy to understand. It is expressed in a way that is
comprehensible to both humans and computers.

 Importance: Clarity promotes maintainability and collaboration among developers. It


reduces the likelihood of bugs and aids in debugging.

Generality:

 A general algorithm can be applied to a wide range of problems within a specific


domain or across domains. It is not overly specialized.

 General algorithms are versatile and reusable, saving time and effort in developing
solutions for similar problems.

A good algorithm is characterized by correctness, efficiency, clarity, and generality. These


attributes ensure that algorithms are not only capable of solving problems accurately but also
perform efficiently, remain easy to understand, and have broad applicability. Mastery of these
characteristics is essential for algorithm designers and programmers.

("Introduction to the Design and Analysis of Algorithms" by Anany Levitin)

Figure 1 Algorithms (authors work)

Gattapola Arachchilage Lahiru Shehan


32
Karunarathne
Gattapola Arachchilage Lahiru Shehan
33
Karunarathne
1.3 Pseudo Codes

Pseudocode is a crucial tool in algorithm development, serving as a bridge between


human-readable descriptions and actual code.

Pseudocode is a high-level, informal, and human-readable description of an algorithm or


a computer program. It uses a mixture of natural language and basic programming constructs to
convey the logic and steps of an algorithm without getting into the specifics of programming
syntax. Pseudocode can be written in plain language, similar to how you'd describe a process to
someone, but it also incorporates fundamental programming concepts like loops, conditionals,
and variables.

1.3.1 How Pseudocode Helps in Algorithm Development

Clarity and Understanding:


 Pseudocode allows developers to express the algorithm's logic in a clear and
comprehensible manner, making it easier for both programmers and non-programmers to
understand the steps involved.
 This clarity is invaluable during the initial stages of algorithm development when the
focus is on logic rather than coding details.

Algorithm Design and Planning:


 Pseudocode serves as a blueprint for the algorithm, enabling developers to plan and
design the solution step by step. It helps in visualizing the entire process before coding
begins.

 It aids in identifying potential issues, refining the logic, and optimizing the algorithm's
structure before implementation.

Gattapola Arachchilage Lahiru Shehan


34
Karunarathne
Language Agnostic:
 Pseudocode is not tied to any specific programming language, making it a universal tool
for algorithm design. It can be easily translated into code in any programming language.

 This language independence ensures that the algorithm's design is not limited to a single
programming language, promoting flexibility and adaptability.

Pseudocode is a valuable tool that aids in algorithm development by providing a clear,


language-agnostic way to express algorithmic logic. It fosters understanding, helps in planning,
and ensures that the algorithm's design is independent of programming language specifics,
making it an essential part of the software development process.

("Introduction to Algorithms" by Thomas H. Cormen)

1.3.2 Steps in the Process of Writing and Executing a Program.

The process of writing and executing a computer program involves several key steps, each of
which plays a vital role in turning a problem-solving idea into a functional software application.

1. Planning:

 The first step in creating a program is to understand the problem you want to solve
thoroughly. Define the objectives, requirements, and constraints of the software. Plan the
logic and algorithm that will address the problem.

 Planning helps ensure that the software will meet the desired goals and that you have a
clear roadmap for development.

2. Coding:

Gattapola Arachchilage Lahiru Shehan


35
Karunarathne
 Once you have a well-defined plan, start writing the actual code for your program.
Convert the algorithm and logic into a programming language that the computer can
understand.

 Coding is where you bring your ideas to life. It involves using the syntax and constructs
of a specific programming language to implement your solution.
3. Testing:

 After writing the code, thoroughly test the program. Check if it behaves as expected for
various inputs and situations. Identify and fix any errors or bugs (bugs are issues in the
code that prevent it from working correctly).

 Testing ensures that the program is reliable and free from critical errors. It helps catch
issues early in the development process.

4. Debugging:

 Debugging is the process of identifying, isolating, and fixing errors in the code. It
involves using debugging tools, print statements, or other techniques to locate and correct
problems.

 Debugging is an essential part of software development. It ensures that the code functions
correctly and produces the intended results.

5. Execution:

 Once you are confident that the code is free from major errors, you execute the program.
This involves running the software with specific inputs or data.

Gattapola Arachchilage Lahiru Shehan


36
Karunarathne
 Execution is the moment when you see the program in action. It allows you to verify that
the program performs its intended tasks.

6. Analysis:

 After executing the program, analyze its performance. Assess factors like speed, memory
usage, and efficiency. Consider whether the program meets the performance
requirements.

 Analysis helps you evaluate the program's effectiveness and identify areas where
improvements can be made.

Authors work

Gattapola Arachchilage Lahiru Shehan


37
Karunarathne
1.3.3 The steps involved in the process of writing and executing a computer program and
analyze the challenges that can be encountered during the coding phase.

Table 1 Table 1 Steps and Challenges in The Process of Writing and Executing a Computer
Program

Steps Step Challenges


1. Problem Understand the problem or Identifying the core requirements
Identification task that the program needs and constraints can be challenging.
and Analysis: to solve. Ensuring that you have a clear
problem statement is crucial.
2. Algorithm Plan and design the Designing an efficient and effective
Design algorithm that outlines the algorithm can be complex,
step-by-step logic to solve especially for complex problems.
the problem. Balancing efficiency with
readability is key.
3. Writing Code: Translate the algorithm into  Syntax Errors: Simple typos
actual code in a or syntax errors can lead to
programming language. bugs that are hard to find.
 Logical Errors: These can be
more challenging, as they
may not result in immediate
errors but produce incorrect
results.
 Code Organization:
Ensuring clean and
maintainable code can be
difficult.
 Debugging: Identifying and

Gattapola Arachchilage Lahiru Shehan


38
Karunarathne
fixing issues can be time-
consuming.
4. Testing: Test the code with various  Test Coverage: Ensuring
input scenarios to ensure it that all possible scenarios
behaves as expected. are tested can be a challenge.
 Regression Bugs: Fixing one
bug can introduce new ones.
 Testing Complex Inputs:
Handling edge cases and
complex data inputs can be
tricky.
5. Documentation Write clear and Writing documentation can be time-
: comprehensive consuming and maintaining it as the
documentation, including code evolves can be challenging.
comments in the code to
explain its functionality.
6. Debugging and If issues or unexpected  Identifying the Root Cause:
Refinement: behavior arises during Debugging often involves
execution, debug and fix the tracing issues back to their
code. source, which can be
difficult.
 Time-Consuming:
Debugging can take a
significant amount of time.

7. Optimization Optimize the code for better Optimization can be complex, and
performance or efficiency if optimizing prematurely can make
needed. the code less readable and
maintainable.

Gattapola Arachchilage Lahiru Shehan


39
Karunarathne
8. Deployment If the program is intended Deployment requires infrastructure
(For for production use, deploy it setup, configuration, and may face
Production on servers or distribute it to compatibility issues.
Use) users as needed.

9. Maintenance: Continuously monitor and  Handling Updates:


maintain the program in Managing updates and
production to ensure it runs ensuring backward
smoothly. compatibility can be
challenging.
 Scaling: As user bases grow,
scaling the program may
require additional work.
10. User Training Provide training or Ensuring users understand and use
(If Applicable) documentation to end-users the software effectively can be
if the program is user-facing. challenging.
11. Documentation Keep documentation up to Maintaining documentation can be
Update date as code changes are time-consuming.
made.
12. Collaboration: …. if working in a team, coordinating
efforts, and merging code changes
can pose challenges, especially with
version control systems.
Authors Work

Gattapola Arachchilage Lahiru Shehan


40
Karunarathne
Role in Evaluating Efficiencies:

Big-O notation allows us to compare algorithms and assess their efficiency. Lower-order
complexities (e.g., O(n)) are generally more efficient than higher-order ones (e.g., O(n^2)).
Evaluating efficiency is crucial when dealing with large datasets or time-sensitive applications
because it helps choose the most appropriate algorithm for the task.

1.4 Fibonacci Series

The Fibonacci Series is a fascinating sequence of numbers with a rich mathematical history. It
begins with the numbers 0 and 1, and each subsequent number in the sequence is the sum of the
two preceding ones. In other words, it's a recursive sequence where each term relies on the
previous two. The sequence starts like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on, extending
infinitely.

The mathematical notation for the Fibonacci series often uses the variable 'Fn' to represent the
nth term of the sequence. It's defined by a recurrence relation: Fn = Fn-1 + Fn-2, where 'Fn-1'
and 'Fn-2' are the two preceding terms. This simple yet elegant mathematical concept has
captured the imagination of mathematicians, scientists, and artists for centuries.

The Fibonacci sequence has far-reaching implications in various fields, including mathematics,
computer science, art, and nature. It's a fundamental example of a recursive mathematical
process, and its beauty lies not only in its simplicity but also in its prevalence in the natural
world, seen in the arrangement of leaves on plants, the spiral patterns of seashells, and the
growth of populations in some biological systems.

In computer science and programming, the Fibonacci sequence is often used as a learning
exercise to understand recursion and dynamic programming. It also plays a role in algorithms

Gattapola Arachchilage Lahiru Shehan


41
Karunarathne
for tasks like optimizing certain search operations. Moreover, the Fibonacci numbers are
closely connected to the golden ratio, a mathematical constant with intriguing properties in art
and nature.

Understanding the Fibonacci Series serves as a bridge between the abstract world of
mathematics and the practical world of computer science, demonstrating how mathematical
principles can be applied to solve real-world problems.

Fibonacci Numbers and the Golden Section

Gattapola Arachchilage Lahiru Shehan


42
Karunarathne
1.4.1 Pseudocode for Fibonacci Series

This pseudocode outlines a step-by-step algorithm to generate and display the Fibonacci series
up to the specified number 'n.' It initializes two variables, 'a' and 'b,' with the initial values of 0
and 1, respectively, and then iterates to calculate and display each subsequent number in the
series until reaching 'n.'

Figure 2 Pseudocode for Fibonacci Series (authors work)

Gattapola Arachchilage Lahiru Shehan


43
Karunarathne
1.4.2 Pseudocode for Factorial Calculation.

Factorial calculation is a common mathematical operation used to find the product of all positive
integers from 1 to 'n.' In this pseudocode, we will outline an algorithm to calculate the factorial
of a given non-negative integer 'n.'

Figure 3 Pseudocode for Factorial Calculation (authors work)

Gattapola Arachchilage Lahiru Shehan


44
Karunarathne
1.4.3 Dry Run Example for Fibonacci Series (n = 5)

This dry run demonstrates how the algorithm generates the Fibonacci series up to the specified
value of 'n' by iteratively calculating each number in the sequence and updating the variables 'a'
and 'b' accordingly.

Figure 4 Dry Run Example for Fibonacci Series (n = 5) (authors work)

Gattapola Arachchilage Lahiru Shehan


45
Karunarathne
1.4.4 Dry Run Example for Fibonacci Series (n = 4)

Figure 51.3.5 Dry Run Example for


Fibonacci Series (n = 4) (authors work)

We begin with the initialization of 'a' and 'b' as


0 and 1, respectively, and 'i' set to 2 to track
the iteration.

 In the first iteration (i = 2), we calculate 'c' as the sum of 'a' and 'b,' resulting in 1. We
display 1 as the first number in the Fibonacci series. Then, we update 'a' to 1, 'b' to 1, and
'i' to 3 in preparation for the next iteration.

 In the second iteration (i = 3), 'c' is calculated as 2 (the sum of 'a' and 'b'). We display 2 as
the second number in the series. 'a' becomes 1, 'b' becomes 2, and 'i' becomes 4.
 In the third iteration (i = 4), 'c' is calculated as 3 (the sum of 'a' and 'b'). We display 3 as
the third number and update 'a' to 2, 'b' to 3, and 'i' to 5.

 In the fourth iteration (i = 5), 'c' is calculated as 5 (the sum of 'a' and 'b'). We display 5 as
the fourth number and update 'a' to 3, 'b' to 5, and 'i' to 6/

 Since 'i' exceeds 'n' (which is 4), we exit the loop. The Fibonacci series up to 4 is
displayed as 1, 2, 3, 5.

Gattapola Arachchilage Lahiru Shehan


46
Karunarathne
Gattapola Arachchilage Lahiru Shehan
47
Karunarathne
1.4.5 Big-O Notation.

Big-O notation is a way to describe the upper bound of the time complexity of an algorithm in
terms of the input size. It provides a simplified representation of how the algorithm's
performance scales as the input size grows.

 O (1): Constant time complexity, where the algorithm's runtime does not depend on the
input size.

 O (log n): Logarithmic time complexity, common in algorithms that divide the input in
half at each step.

 O (n): Linear time complexity, where the runtime grows linearly with the input size.

 O (n log n): Log-linear time complexity, often seen in efficient sorting algorithms.

 O(n^2): Quadratic time complexity, where the runtime grows with the square of the
input size.

 O (2^n): Exponential time complexity, indicating exponential growth in runtime.

Gattapola Arachchilage Lahiru Shehan


48
Karunarathne
1.5 Python Algorithm to Generate both Fibonacci and factorial Series in a Number.

Fibonacci Series: This algorithm generates the Fibonacci series up to a specified number 'n' and
returns the series as a list.

Factorial Calculation: This algorithm calculates the factorial of a non-negative integer 'n' and
returns the result.

Introduction:
The program is designed to provide a user-friendly way to calculate both the Fibonacci Series
and Factorial of a non-negative integer 'n'. It opens a GUI window with input fields, calculation
buttons, and result displays. This makes it more accessible and visually appealing compared to
a console-based program.

Key Components:

Tkinter GUI: The program starts by importing the Tkinter library and creating a main window
(root). This window serves as the interface for user interaction. It's given a title, dimensions,
and a light gray background.

Input and Buttons:

Within the window, there's a label instructing the user to enter a non-negative integer 'n'. An
entry widget allows users to input their value. Two buttons, "Calculate Fibonacci" and
"Calculate Factorial," trigger the respective calculations when clicked.

Gattapola Arachchilage Lahiru Shehan


49
Karunarathne
Result Display: A label is provided for displaying the results of the calculations. Initially, it
shows a message indicating where the results will be displayed.

Algorithm Implementation:
The program contains functions for calculating the Fibonacci Series and Factorial. These
functions use the same algorithms you provided earlier in the console-based version. When a
user clicks one of the calculation buttons, the corresponding function is called with the user-
provided 'n' value. The result is then displayed in the result label.

User Interaction:
Users can interact with the program by entering a non-negative integer 'n' into the entry field
and clicking either the "Calculate Fibonacci" or "Calculate Factorial" button. The program
takes the input, performs the calculations, and displays the results. This GUI-based approach
enhances user experience and makes the program more intuitive.

Gattapola Arachchilage Lahiru Shehan


50
Karunarathne
Figure 6 Python code for both Fibonacci and factorial Series generator(authors work)

Authors Work

Gattapola Arachchilage Lahiru Shehan


51
Karunarathne
Results

Figure 7 Fibonacci and factorial Calculator

Figure 8 Fibonacci Series for 20 is Calculated. (authors work)

Gattapola Arachchilage Lahiru Shehan


52
Karunarathne
Gattapola Arachchilage Lahiru Shehan
53
Karunarathne
Figure 2 Factorial of 20 is Calculated(authors work)

Gattapola Arachchilage Lahiru Shehan


54
Karunarathne
Activity 02

2.1 Programming Paradigms: An Overview

2.1.1 Definition of Programming Paradigms.

Programming paradigms are fundamental approaches or philosophies that guide the design and
structuring of computer programs. They represent distinct schools of thought in software
development, each offering a specific set of principles and conventions for writing code. These
paradigms serve as blueprints for organizing, managing, and reasoning about the logic and
structure of a computer program. By adhering to a particular paradigm, programmers can
effectively express their ideas and solve problems using a well-defined methodology.

One of the most prevalent programming paradigms is Procedural Programming. In this


paradigm, the focus is on creating procedures or functions that operate on data. It emphasizes
structured programming, breaking down complex tasks into smaller, more manageable
functions. Procedural programming is known for its simplicity and ease of understanding,
making it suitable for smaller programs and scripts. It promotes modularity, which allows
programmers to reuse code components and build maintainable software. However, it may
struggle to handle the complexity of larger systems and may not be the most efficient choice for
certain types of applications.

2.1.2 The Role of Paradigms in Software Development

Programming paradigms play a pivotal role in software development by providing a


fundamental framework and a set of guiding principles for designing, organizing, and
structuring computer programs. These paradigms influence how programmers approach

Gattapola Arachchilage Lahiru Shehan


55
Karunarathne
problem-solving, code organization, and the overall development process. Here are the key
roles that paradigms play in software development:

Problem-Solving Approach: Paradigms define how programmers’ approach and break down
complex problems into smaller, more manageable components. For example, in procedural
programming, the focus is on dividing tasks into procedures or functions, while in object-
oriented programming, problems are solved by modeling real-world entities as objects with
attributes and behaviors. The choice of paradigm can significantly impact the problem-solving
process.

Code Organization: Each paradigm introduces specific rules and conventions for structuring
code. For instance, object-oriented programming promotes the creation of classes and objects to
encapsulate data and behavior, fostering a clear and organized codebase. Procedural
programming emphasizes structured code using functions or procedures to improve code
modularity. This organization ensures that code is easier to read, maintain, and extend.

Reusability: Paradigms influence the reusability of code components. Object-oriented


programming, with its focus on encapsulation and inheritance, encourages the creation of
reusable classes and libraries. This allows developers to leverage existing code in new projects,
saving time and effort. Procedural programming also promotes code reuse through modular
functions.

Abstraction: Paradigms introduce different levels of abstraction. For example, object-oriented


programming abstracts real-world entities into classes and objects, making it easier to model
complex systems. Event-driven programming abstracts user interactions and system events into
event handlers, simplifying the design of interactive applications. Abstraction helps manage
complexity and simplifies problem representation.

Maintainability: The choice of paradigm can greatly impact the maintainability of software.
Object-oriented programming, by encapsulating data and behavior within objects, can lead to

Gattapola Arachchilage Lahiru Shehan


56
Karunarathne
code that is easier to maintain and extend over time. It also encourages a modular approach,
making it simpler to update specific components without affecting the entire system. Procedural
programming, when applied judiciously, can also lead to maintainable code through proper
structuring.

Scalability: Different paradigms have varying degrees of scalability. Object-oriented


programming is often preferred for building large and complex systems, as it provides a natural
way to manage and extend codebases. Event-driven programming excels in creating scalable
user interfaces and interactive systems. The choice of paradigm should align with the
scalability requirements of a project.

Software Architecture: Paradigms influence the overall architecture of a software system.


Object-oriented programming often leads to modular and well-organized architectures, while
event-driven programming naturally fits systems with user interfaces. Procedural programming
may be chosen for simpler, task-oriented software where architectural complexity is not a
primary concern.

"Clean Code" by Robert C

Gattapola Arachchilage Lahiru Shehan


57
Karunarathne
2.1.3 Importance of Choosing the Right Paradigm

Choosing the right programming paradigm is crucial in software development because it


directly impacts various aspects of a software project, including its design, maintainability,
scalability, and overall success. Key points highlighting the importance of selecting the
appropriate programming paradigm are shown below.

 Alignment with Project Goals: Different projects have different goals and requirements.
Choosing the right paradigm ensures that the software development approach aligns
with the project's objectives.

 Code Maintainability: The choice of paradigm affects how code is organized and
structured. An appropriate paradigm can lead to well-structured and maintainable code,
making it easier for developers to understand, modify, and extend the software over
time. This is essential for long-term sustainability and cost-effectiveness.

 Scalability: Certain paradigms are better suited for handling the scalability requirements
of a project

 Code Reusability: Some paradigms, such as object-oriented programming, promote


code reusability through the creation of classes and objects

 Team Collaboration: Consistency in programming paradigm choices within a


development team fosters effective collaboration.

 Efficiency: Certain paradigms may be more efficient than others for specific types of
tasks. For instance, low-level, procedural programming languages like C are often

Gattapola Arachchilage Lahiru Shehan


58
Karunarathne
chosen for system-level programming because of their efficiency in managing hardware
resources. Selecting the right paradigm can optimize performance.

 Domain Suitability: Different domains of software development may benefit from


specific paradigms.

 Ease of Debugging and Testing: The choice of paradigm can impact how easily code
can be debugged and tested. Well-structured code following a suitable paradigm may
have fewer bugs and be more straightforward to test, reducing development time and
costs.

 Future Maintenance: When considering the long-term life cycle of software, selecting
the right paradigm can ease future maintenance efforts. A paradigm that supports
modular and organized code allows for smoother updates and enhancements.

 User Experience: In the case of user-facing applications, the chosen paradigm can
influence the user experience.

Gattapola Arachchilage Lahiru Shehan


59
Karunarathne
2.2 Characteristics of Procedural Programming

2.2.1 Structured Programming

Procedural programming follows the principles of structured programming, which emphasize


the use of structured constructs like loops and conditional statements. This approach simplifies
program flow, making it easier to understand and maintain.

Figure 9 example of procedural code in Python that follows the principles of structured
programming. (authors work)

Gattapola Arachchilage Lahiru Shehan


60
Karunarathne
Figure 10 Results of a Structured Programming Procedural Code(authors work)

2.2.2 Basic GUI To Calculate Average. With Procedural Code.


Steps
 Import the necessary modules for creating the GUI, including tkinter, ttk (themed
Tkinter), and messagebox for message dialogs.

 Define a function, calculate_average, to calculate the average of user-entered numbers.

 Create the main application window and set its title.

 Create a main frame within the window and configure it to expand and fill available
space.

 Create a label and an entry widget for users to input numbers, placing them within the
main frame grid.

 Create a "Calculate Average" button that triggers the calculate_average function when
clicked, also placed within the main frame grid.

 Create a label to display the calculated average result, positioning it below the input
widgets in the grid.

 Run the main GUI loop to start the application.

Gattapola Arachchilage Lahiru Shehan


61
Karunarathne
Gattapola Arachchilage Lahiru Shehan
62
Karunarathne
Figure 12 Code Of My Simple GUI For Calculating Average With Procedural Programming

Figure 11 Code Of My Simple GUI Average Calculator with a procedural code in Python that
follows the principles of structured programming(authors work)

Gattapola Arachchilage Lahiru Shehan


63
Karunarathne
Figure 13 Results 1

Figure 14 Results 2(authors work)

Gattapola Arachchilage Lahiru Shehan


64
Karunarathne
2.2.3 Advantages and Disadvantages of Procedural Programming

Advantages Disadvantages

 Simplicity: Procedural code tends to  Limited Abstraction: Procedural


be straightforward and easy to programming may struggle with
understand, making it suitable for complex data structures and real-
smaller projects. world modeling.
 Efficiency: It often leads to efficient  Global Data: The reliance on global
code execution due to its linear flow. variables can lead to data access and
modification issues.

 Modularity: The modular nature  Scalability: It may become less


promotes code reuse and simplifies maintainable and challenging to scale
maintenance. for larger and more complex projects.

 Suitable for Low-Level Programming:  Reduced Readability: As programs


Procedural languages like C are grow, procedural code can become
widely used for system-level and less readable and harder to maintain.
hardware programming.

Figure 15 Advantages and Disadvantages of Procedural Programming(authors work)

Gattapola Arachchilage Lahiru Shehan


65
Karunarathne
2.2.4 Examples for Procedural Programming

Example 1: Calculating the Sum of Numbers

Figure 16 Calculating the Sum of Numbers(authors work)

Figure 17 results(authors work)

Gattapola Arachchilage Lahiru Shehan


66
Karunarathne
This code defines a function calculate sum that takes a list of numbers as input and calculates
their sum using a for loop. It then prints the total sum. This is a simple example of procedural
code for performing a mathematical operation.

Gattapola Arachchilage Lahiru Shehan


67
Karunarathne
Example 2: Reading and Writing Files.

Figure 18 Reading and Writing Files(authors work)

This code defines two functions, read file, and write file, for reading the content of a file and
writing modified content to a new file. It demonstrates procedural code for file operations,
emphasizing modularity and readability.

Gattapola Arachchilage Lahiru Shehan


68
Karunarathne
Example 3: User Authentication

Figure 19 User Authentication(authors work)

Figure 20 Results for User 1(authors work)

Gattapola Arachchilage Lahiru Shehan


69
Karunarathne
2.3 Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a programming paradigm that revolves around the


concept of objects, which are instances of classes representing real-world entities or concepts.

In OOP, code is organized into classes, encapsulating both data (attributes) and behavior
(methods), promoting the principles of encapsulation, inheritance, and polymorphism. This
paradigm enhances code reusability, maintainability, and scalability by modeling software in a
way that mirrors real-world structures.

Prominent programming languages that support OOP include Java, Python, and C++. OOP
enables the development of modular and extensible code, making it a fundamental approach in
modern software engineering and design.

2.3.1 Core Concepts of OOP

Object-Oriented Programming (OOP) is built upon core concepts that provide a structured and
organized approach to software development. These concepts include:

Classes: Classes serve as blueprints or templates for creating objects. They define the structure
and behavior that objects of a particular type will have. Classes encapsulate attributes (data)
and methods (functions) that operate on that data.

Objects: Objects are instances of classes. They represent real-world entities or concepts and
are created based on class definitions. Each object has its own set of data and can perform
actions defined by its class.

Gattapola Arachchilage Lahiru Shehan


70
Karunarathne
Inheritance: Inheritance is a mechanism that allows a new class (subclass or derived class) to
inherit properties and behaviors from an existing class (superclass or base class). It promotes
code reuse and hierarchy in class relationships.

Encapsulation: Encapsulation involves bundling data (attributes) and methods (functions) that
operate on that data into a single unit called a class. Access to the internal data of a class is
controlled through defined interfaces, enhancing data security and modularity.

Polymorphism: Polymorphism allows objects of different classes to be treated as objects of a


common superclass. It enables flexibility by providing a single interface for multiple types of
objects, facilitating method overriding and dynamic method dispatch.

"Unified Modeling Language (UML) - Version 2.5."

Gattapola Arachchilage Lahiru Shehan


71
Karunarathne
2.3.2 benefits and challenges of OOP in larger systems

Benefits Challenges

Code Reusability: OOP promotes the reuse of Complexity Management: Larger systems
classes and objects. In larger systems, this may involve numerous classes, leading to
reduces redundancy and development time as complex class hierarchies that can be
existing components can be leveraged. challenging to manage and understand.

Scalability: OOP allows for the modular Dependency Management: As the system
expansion of the system. New classes and grows, managing dependencies between
objects can be added with minimal impact on classes and objects becomes crucial.
existing code, making the system more Uncontrolled dependencies can lead to tight
scalable. coupling, making changes more difficult.

Maintenance Ease: Code organization through Testing and Debugging: In larger systems,
classes and encapsulation makes it easier to comprehensive testing becomes essential,
locate and modify specific functionalities, which can be time-consuming. Identifying
enhancing code maintainability. and debugging issues in a complex codebase
can be challenging.

Gattapola Arachchilage Lahiru Shehan


72
Karunarathne
Hierarchy and Abstraction: Inheritance and Performance Considerations: As the system
abstraction enable the modeling of complex scales, performance bottlenecks may arise.
systems by creating a clear hierarchy of Careful design and optimization are needed to
classes and focusing on essential properties ensure the system performs efficiently.
and behaviors.

Team Collaboration: OOP facilitates Version Control and Collaboration:


collaboration among development teams. Coordinating changes among team members
Different teams can work on different classes can be complex in larger projects. Effective
or modules independently, promoting parallel version control and collaboration strategies
development. are necessary.

Documentation and Communication: Larger


systems require robust documentation to
ensure that team members can understand and
work with the code. Effective communication
among team members is also crucial.

Security Concerns: As the system grows,


security becomes more critical. Ensuring data
integrity and preventing vulnerabilities
becomes a significant challenge.

Figure 21 benefits and challenges of using Object-Oriented Programming (OOP) in larger


software systems(authors work)

Gattapola Arachchilage Lahiru Shehan


73
Karunarathne
2.3.3 Example of OOP Code

In this code, we define an Animal class and two subclasses, Dog and Cat, each with a speak
method. Objects of these classes exhibit polymorphism as they respond differently to the same
method call.

Figure 22 Code and The Result For OOP Code(authors work)

Gattapola Arachchilage Lahiru Shehan


74
Karunarathne
2.4 Event-Driven Programming

Event-Driven Programming is a programming paradigm where the flow of a program is driven


by events or user actions rather than a predetermined sequence of execution. In this paradigm,
the program responds to various events, such as user input, sensor data, or messages from other
parts of the system, in an asynchronous and event-triggered manner.

Key components of Event-Driven Programming include:

 Events: Events are occurrences that trigger the execution of specific code (event
handlers). Events can be generated by user interactions like mouse clicks or keyboard
inputs, system events like timer ticks or data arriving from a network, or even custom
events within the program.

 Event Handlers: Event handlers are functions or methods designed to respond to


specific events. When an event occurs, the associated event handler is invoked to
perform a predefined action or process the event data.

 Event Loop: An event loop is a core part of event-driven programs. It continuously


checks for pending events and dispatches them to their respective event handlers. This
loop allows the program to remain responsive and handle multiple events concurrently.

 Callbacks: Callbacks are functions or methods that are registered to be called when a
specific event occurs. They are a common mechanism for implementing event handlers.

Gattapola Arachchilage Lahiru Shehan


75
Karunarathne
Figure 23 Code and Results for a Event-Driven Program (authors work)

Gattapola Arachchilage Lahiru Shehan


76
Karunarathne
2.4.1 Events and Event Handlers:

Events:
Events represent occurrences or happenings within a program. They can be thought of as
signals or notifications that inform the program that something of interest has occurred. Here
are some common types of events:

 User Interaction Events: These events are triggered by user actions, such as clicking a
button, pressing a key, moving the mouse cursor, or scrolling. For example, a button
click event occurs when a user clicks a button on a graphical user interface (GUI).

 System Events: System events are generated by the underlying operating system or
runtime environment. They can include timer events, which occur at regular intervals,
network events like data arrival, or hardware events such as device connections or
disconnections.

 Custom Events: In many programming environments, developers can define their own
custom events. These events are specific to the application and can be triggered based
on certain conditions or criteria within the program. For example, an application might
generate a custom event when a certain task is completed.

Gattapola Arachchilage Lahiru Shehan


77
Karunarathne
Event Handlers:
Event handlers are functions, methods, or callbacks that are associated with specific events.
They define how the program should respond when a particular event occurs

Here's how event handlers work:

 Registration: When an event handler is created, it is registered with a particular event


source (e.g., a button, a timer, a network socket). This registration establishes a
connection between the event and the handler.

 Triggering: When the event occurs (e.g., a button is clicked, a timer ticks, data arrives),
the event source detects it and triggers the associated event handler.

 Execution: The event handler's code is executed in response to the event. This code can
perform various tasks, such as updating the user interface, processing data, or triggering
other actions within the program.

 Completion: Once the event handler has completed its tasks, control is returned to the
program's main event loop, which continues to monitor and respond to other events.

Gattapola Arachchilage Lahiru Shehan


78
Karunarathne
2.4.2 Use Cases for Event-Driven Programming

 Event-Driven Programming is commonly used in various scenarios, including:

 Graphical User Interfaces (GUIs): Building interactive interfaces where user actions
(e.g., button clicks) trigger responses.

 Web Development: Handling user interactions on web pages, such as clicking buttons,
submitting forms, or handling asynchronous requests.

 Game Development: Managing game events like player input, collisions, and
animations.

 Real-Time Systems: Reacting to external events like sensor inputs, network data, or
hardware events.

 Multithreading: Coordinating and synchronizing actions among multiple threads or


processes.

Gattapola Arachchilage Lahiru Shehan


79
Karunarathne
Figure 24 Event Driven Architecture

Gattapola Arachchilage Lahiru Shehan


80
Karunarathne
2.4.3 User Interface Considerations.

In event-driven programming, user interface (UI) design plays a crucial role. When evaluating
event-driven code, consider the following UI-related aspects:

 UI Components: Identify the UI components used in the code, such as buttons, text fields,
labels, or graphical elements. Assess how they are created and configured.

 Layout and Design: Evaluate the layout and design of the user interface. Is it user-
friendly, intuitive, and visually appealing? Ensure that components are appropriately
positioned and sized.

 Responsiveness: Check if the user interface is responsive to user interactions. For


example, observe how quickly it updates in response to button clicks or other actions.

 Feedback: Assess whether the user receives adequate feedback. Does the interface
provide informative messages or visual cues when actions are performed or errors occur?

 Consistency: Look for consistency in UI elements and behavior. Consistency in button


placement, labeling, and behavior across the application enhances the user experience.

 Accessibility: Consider accessibility features. Ensure that the UI is usable by individuals


with disabilities and complies with accessibility standards.

 Usability Testing: If possible, conduct usability testing to gather feedback from users.
Usability testing helps identify any usability issues and areas for improvement.

Gattapola Arachchilage Lahiru Shehan


81
Karunarathne
Activity 3

3.1 Pseudocodes of Grifindo Toys Payroll System

3.1.1 Salary Component.

Figure 25 Salary Component(authors work)

Initialize Form:

 Create a form object for salary-related operations.

Load Employee Data:

 When the form is loaded, retrieve and display employee information based on the
provided employee ID.
 Display a message if no data is found for the given ID.

Calculate and Display Salary:

 On button click, obtain attendance and overtime data.

Gattapola Arachchilage Lahiru Shehan


82
Karunarathne
 Calculate the salary based on a custom logic that considers attendance, overtime, basic
salary, and allowances.
 Display the detailed calculation in the designated textbox.

Animate Final Salary Display:

 Animate the display of the final calculated salary, starting from 0 and reaching the
calculated amount over a 3-second interval.
 Update the displayed amount during the animation.

Animate Salary Label Color:

 Change the color of the salary label at regular intervals from a predefined list of light
colors.

Supporting Methods:

 Various supporting methods handle tasks such as fetching employee data from the
database, calculating daily pay rate, and rounding the calculated salary.

User Interface Updates:

 Update textboxes and labels with relevant information during different stages of the
salary calculation process.

GUI Elements:

 Utilize textboxes, labels, and date pickers to interact with and display information to the
user.

Error Handling:

 Implement basic error handling, notifying the user if invalid numeric values are entered
for attendance and overtime.

Gattapola Arachchilage Lahiru Shehan


83
Karunarathne
Database Interaction:

 Connect to a SQL database to retrieve employee information for salary calculation.

Gattapola Arachchilage Lahiru Shehan


84
Karunarathne
Figure 26 Salary Component Pseudo Code(authors work)

Gattapola Arachchilage Lahiru Shehan


85
Karunarathne
3.2: Overview of Visual Studio IDE.

Visual Studio IDE stands as a robust and comprehensive integrated development environment,
offering a suite of tools and features to facilitate efficient software development. Developed by
Microsoft, Visual Studio caters to various programming languages, including C#, making it a
versatile choice for a wide range of developers.

Figure 27 Visual Studio 2022 Interface along with Grifindo Toys Project(authors work)

The IDE incorporates design tools for creating user interfaces, such as Windows Forms and
WPF applications. The drag-and-drop interface simplifies UI design, and the integrated XAML
editor provides fine-tuned control over the layout. Visual Studio also supports data-driven
application development, enabling seamless integration with databases.

Gattapola Arachchilage Lahiru Shehan


86
Karunarathne
One of the key features of Visual Studio is its powerful code editor, providing syntax
highlighting, auto-completion, and real-time error checking, contributing to a more productive
coding experience. The IDE's integrated debugger allows developers to identify and fix issues
swiftly, ensuring the reliability of their code.

Visual Studio's project management capabilities streamline the development lifecycle. The
solution explorer organizes project files, and the built-in version control facilitates
collaboration among team members. The inclusion of templates for different project types
expedites the creation of new applications, saving developers valuable time.

3.1.2 Implementing Visual Studio IDE to the Components

Employee Component

Registering Employee Details:

 Used textboxes and input fields to capture employee details like name, ID, monthly
salary, overtime rates, and allowances.

 Implemented a button for the admin to register the employee.

 Buttons for Updating and Deleting Employee Details.

 Grid view of all employees with options to update and delete.

 Clicking on an employee opens a form for updating details.

 Added options to view individual employee details, all employees' details, and a search
functionality.

Gattapola Arachchilage Lahiru Shehan


87
Karunarathne
Settings Component

 Added User input fields or dropdowns for the admin to change parameters like date
range, salary cycle begin/end dates, and the number of leaves.

 Implemented a button to save changes made to the parameters.

Salary Component

 Added date pickers to input the salary calculation date range.

 Added Textboxes for entering the number of leaves, absent days, holidays, and overtime
hours.

 Added Textboxes and labels Display calculated values for No-pay, Base Pay, and Gross
Pay using labels or textboxes.

 Implemented logic for the calculations based on the provided formulas.

 Included buttons to generate reports for monthly salary, overall salary summary, No-pay,
base pay, and gross pay for a specified month range.

Gattapola Arachchilage Lahiru Shehan


88
Karunarathne
3.2 Creating Separate Classes for Components

In the Grifindo Toys system, employing separate classes for distinct components enhances code
organization, readability, and maintainability. Each class encapsulates a specific responsibility,
promoting a modular and efficient design.

Custom Class: ID Generator

The ID Generator class serves a crucial role in generating unique identifiers, ensuring data
integrity and avoiding conflicts within the system. In the context of Grifindo Toys, where
employee IDs are dynamically created, this class becomes instrumental. It provides a method to
generate IDs following a specific format, enhancing readability and systematic organization.

Figure 28 Custom Class: ID Generator(authors work)

The ID Generator class encapsulates the logic for creating unique IDs. A method, perhaps named
GenerateEmployeeID(), could be implemented to generate employee IDs based on a specified
format. For instance, using a combination of static characters like "GT" and a dynamically

Gattapola Arachchilage Lahiru Shehan


89
Karunarathne
generated number ensures uniqueness. This class promotes code modularity, making it easy to
adapt the ID generation logic if requirements evolve.

Custom Class: Theme Changer

In the Grifindo Toys system, the ThemeChanger class contributes to a personalized user
experience. It allows users to customize the visual aesthetics of the application, aligning with
modern design principles or accommodating individual preferences. Themes play a vital role in

Figure 29 Custom Class: ThemeChanger(authors work)


user engagement, and this class facilitates seamless theme transitions.

The ThemeChanger class could include methods like SetPrimaryColor() and


SetSecondaryColor(), enabling users to dynamically change the primary and secondary colors

Gattapola Arachchilage Lahiru Shehan


90
Karunarathne
of the application's interface. This promotes a dynamic and visually pleasing environment,
making the application more appealing to users with varying design preferences

Custom Class: TextAnimation

The TextAnimation class enhances the user interface of Grifindo Toys by providing smooth
text animations. This class encapsulates the logic for animating text changes, ensuring a
visually engaging experience for users. In the context of FormSalary, it is utilized to animate
the calculated salary display.

Gattapola Arachchilage Lahiru Shehan


91
Karunarathne
Figure 30 Custom Class: TextAnimation(authors work)

Gattapola Arachchilage Lahiru Shehan


92
Karunarathne
3.3 Database Structure Design.

3.3.1 Database Design Principles

Database Design Principles are fundamental guidelines that help in creating well-organized and
efficient databases. These principles include:

Normalization This process helps organize data in a database


to avoid redundancy and improve data
integrity. It involves breaking down large
tables into smaller, related tables to minimize
data duplication.
Entity-Relationship Diagrams (ERD) Creating an ERD helps visualize the
relationships between different entities in your
database. It's a useful tool for planning and
understanding the structure of your database.

Data Types Choosing the right data types for your columns
is crucial. It ensures efficient storage and
processing of data. For example, using integer
data types for whole numbers and date types
for date values.

Table 3 Database Design Principles(authors work)

Gattapola Arachchilage Lahiru Shehan


93
Karunarathne
3.3.2 Entities and Relationships in Employee System.

Figure 31 Grifindo Toys Employe and Salary Tables(authors work)

In the context of database design for an Employee System, entities and their relationships play a
pivotal role. Entities, such as "Employee" and "EmployeeSalary," represent distinct objects,
while relationships define how these entities are interconnected. The "Employee" entity
captures crucial personal and professional details, acting as a foundational building block.

Simultaneously, the "EmployeeSalary" entity delves into financial aspects, creating a bridge to
the monetary dimension of an employee's engagement. The common identifier, "empid,"

Gattapola Arachchilage Lahiru Shehan


94
Karunarathne
establishes a seamless link between these entities, ensuring a holistic representation within the
database

3.3.3 SQL Table Creation for Employee Information.

The SQL table creation for Employee Information is thoughtfully designed, adhering to
principles of normalization and efficiency.

The "Employee" table incorporates key attributes such as "empid," "firstname," "lastname,"
"work," "mobile," "email," "address," "gender," and "age." The primary key, "empid," ensures
uniqueness, and each attribute is chosen to provide a comprehensive overview of an employee's
profile.

The inclusion of both personal and professional details aligns with the principles of effective
database organization.

Gattapola Arachchilage Lahiru Shehan


95
Karunarathne
Figure 32 Employe table Expanded(authors work)

Gattapola Arachchilage Lahiru Shehan


96
Karunarathne
3.3.4 SQL Table Creation for Salary Information.

The SQL table creation for Salary Information, encapsulated in the "EmployeeSalary" table,
meticulously captures the financial aspects of an employee's engagement. Similar to the
Employee Information table, the "empid" serves as the primary key, establishing a link between
the two tables.

Attributes like "Leaves," "BasicSalary," "Overtime," and "Allowances" offer a detailed


breakdown of an employee's compensation structure.

The use of the "DECIMAL" data type for monetary values ensures accuracy in representation,
especially in scenarios where precision is crucial.

Figure 33 Salary Table Expanded(authors work)

Gattapola Arachchilage Lahiru Shehan


97
Karunarathne
Gattapola Arachchilage Lahiru Shehan
98
Karunarathne
3.4 Features of a Integrated Development Environment (IDE)

3.4.1 Code Editing and Autocompletion

Efficient code editing and autocompletion are integral aspects of a developer's toolkit. A robust
code editor enhances productivity by providing features such as syntax highlighting, code
folding, and autocompletion.

These tools assist developers in writing clean and error-free code. Autocompletion anticipates
the developer's intent, offering suggestions for functions, variables, and even entire code
snippets. This feature accelerates the coding process and reduces the likelihood of errors.

A well-integrated code editing environment ensures a smooth and enjoyable development


experience, fostering creativity and efficiency.

3.4.2 Debugging Tools

Debugging tools are the backbone of a developer's ability to identify and resolve issues within
their code. These tools provide a comprehensive set of features, including breakpoints, variable
inspection, and step-by-step execution.

Breakpoints allow developers to pause the execution of their code at specific points, enabling in-
depth examination of variables and program flow. Debugging tools also facilitate the
identification of runtime errors and help developers understand the behavior of their code in real-
time.

The integration of robust debugging tools is crucial for maintaining code quality and ensuring
the reliability of software applications.

Gattapola Arachchilage Lahiru Shehan


99
Karunarathne
3.4.3 GUI Design and Form Building

Graphical User Interface (GUI) design and form building tools empower developers to create
visually appealing and user-friendly applications. These tools often include drag-and-drop
functionality, allowing developers to design interfaces without delving deeply into code.

Form-building features simplify the creation of input forms, enabling developers to collect user
data seamlessly.

A well-integrated GUI design environment enhances the user experience and accelerates the
development of applications with intuitive interfaces.

Gattapola Arachchilage Lahiru Shehan


100
Karunarathne
3.5 Visual Studio IDE for Application Development.

3.5.1 Advantages of Using Visual Studio.

Visual Studio stands out as a premier Integrated Development Environment (IDE) for
application development, offering a plethora of advantages.

One key benefit is its comprehensive set of tools that cater to diverse programming languages,
making it a versatile choice for developers.

The IDE's intelligent code completion and suggestion features significantly enhance
productivity, enabling developers to write code more efficiently.

Visual Studio's extensive library of extensions further amplifies its capabilities, allowing
developers to customize their environment based on specific project requirements.

Additionally, the seamless integration with various third-party services and platforms simplifies
tasks such as version control, deployment, and testing.

Gattapola Arachchilage Lahiru Shehan


101
Karunarathne
3.5.2 Efficiency in Coding and Debugging.

Efficiency in coding and debugging is a hallmark of Visual Studio's capabilities. The IDE
provides an intuitive and user-friendly interface, streamlining the coding process.

Its robust code editor supports features like syntax highlighting, auto-indentation, and real-time
error checking, contributing to clean and error-free code development.

The integrated debugging tools offer a powerful set of features, including breakpoints, step-by-
step execution, and variable inspection. This not only simplifies the identification and
resolution of issues but also facilitates a deeper understanding of code behavior during runtime.

Visual Studio's emphasis on efficiency makes it a go-to choose for developers aiming to
optimize their workflow. Efficiency in coding and debugging is a hallmark of Visual Studio's
capabilities.

The IDE provides an intuitive and user-friendly interface, streamlining the coding process. Its
robust code editor supports features like syntax highlighting, auto-indentation, and real-time
error checking, contributing to clean and error-free code development.

The integrated debugging tools offer a powerful set of features, including breakpoints, step-by-
step execution, and variable inspection.
This not only simplifies the identification and resolution of issues but also facilitates a deeper
understanding of code behavior during runtime.

Visual Studio's emphasis on efficiency makes it a go-to choose for developers aiming to
optimize their workflow.

Gattapola Arachchilage Lahiru Shehan


102
Karunarathne
3.5.3 Integration with .NET Framework.

Visual Studio's seamless integration with the .NET Framework is a pivotal advantage for
developers working within the Microsoft ecosystem.

The IDE provides robust support for developing applications using various .NET technologies,
including ASP.NET for web development, Windows Forms for desktop applications, and
Xamarin for cross-platform mobile development.

This integration ensures that developers can leverage the full power of the .NET Framework,
accessing a rich set of libraries and tools to expedite application development.

Visual Studio's compatibility with the latest .NET releases underscores its commitment to
staying abreast of technological advancements.

Figure 34 Visual Studio Supporters

Gattapola Arachchilage Lahiru Shehan


103
Karunarathne
3.5.4 Visual Studio vs. Manual Development.

Feature Visual Studio Manual Development


Code Efficiency Intelligent code completion Relies on manual typing and
and suggestions coding
Debugging Tools Integrated debugging with Debugging requires manual
breakpoints effort
Automation Automated project setup and Manual configuration and
compilation compilation
Project Management Built-in project management Requires external tools for
and versioning version control
Language Support Versatile, supporting Limited by developer's
multiple languages expertise and tools
Productivity Streamlined workflow with Time-consuming tasks may
intuitive UI reduce productivity
Error Detection Real-time error checking and Relying on manual code
feedback Real-time error reviews
checking and feedback
Integration Seamless integration with Manual integration with
various services external tools Manual
integration with external
tools
Learning Curve Some learning curve due to Relies on developer's coding
feature richness proficiency

Table 4 Manual Development Vs Visual Studio(authors work)

Gattapola Arachchilage Lahiru Shehan


104
Karunarathne
Activity 4

4.1 GUI Grifindo Toys payroll System

Figure 35 Loading Screen(authors work)


4.1.1 Loading Screen

The loading screen serves as the first impression of the Grifindo Toys Payroll System,
contributing to a seamless user experience. Its purpose extends beyond functionality,
incorporating a visual appeal that ensures users feel engaged during the initial loading process.

This screen displays key company details, including the Grifindo Toys logo, a slogan capturing
the company's ethos, and possibly a brief mission statement. These elements not only introduce
users to the brand but also set a professional and welcoming tone for the entire application.

Gattapola Arachchilage Lahiru Shehan


105
Karunarathne
By maintaining this loading screen for a short duration, typically 10 seconds, it strikes a
balance between providing necessary loading time and swiftly transitioning to the main
interface.

Gattapola Arachchilage Lahiru Shehan


106
Karunarathne
4.1.2 Login Page

Figure 36 Login(authors work)

The login form is meticulously designed with modern aesthetics and a user-friendly layout. Its
sleek design incorporates intuitive input fields, contributing to an overall pleasant visual
experience.

Security is a paramount concern, and the system employs robust measures such as password
encryption to safeguard user credentials. The inclusion of a "Forgot Password" option enhances
security further. This feature triggers a secure process, users can securely reset their passwords
in case of any security concerns or forgotten credentials.

This holistic approach to design and security establishes a foundation for a reliable and user-
centric authentication process.
.

Gattapola Arachchilage Lahiru Shehan


107
Karunarathne
4.1.3 Main Form

Figure 37 Main Form(authors work)

At the core of the application, the main form serves as the central hub for navigation, offering a
seamless and intuitive user experience.

Structurally, it houses various child forms accessible through a thoughtfully organized menu.
The menu contains logically placed buttons corresponding to different components of the
Grifindo Toys Payroll System.

These buttons facilitate easy navigation between essential features such as Home, Employee,
Basic Salary, Settings, Salary, and View. Clicking on each button dynamically loads the
respective child form within the main form, ensuring a cohesive and user-friendly interaction
with the entire application.

Gattapola Arachchilage Lahiru Shehan


108
Karunarathne
4.1.4 Home

Figure 38 home(authors work)

The Home Form is the user's initial point of interaction, providing a personalized and
informative welcome. It dynamically greets the logged-in user, creating a sense of familiarity.

This form often includes important announcements or updates related to the payroll system,
ensuring that users are promptly informed of any critical information. Additionally, Home Form
acts as a launching pad, offering quick links or buttons that provide easy access to frequently
used features.

By combining personalized greetings, important updates, and convenient shortcuts, the Home
Form establishes itself as an efficient and welcoming starting point within the Grifindo Toys
Payroll System.

Gattapola Arachchilage Lahiru Shehan


109
Karunarathne
4.1.5 Employee Component.

Figure 39 Employee Form(authors work)

The Employee Form encompasses a comprehensive set of functionalities that empower the
system administrator.

This form allows the admin to efficiently register new employees, capturing crucial details such
as monthly salary, overtime rates, and allowances. Additionally, the system offers robust
capabilities for updating and deleting employee details, ensuring that the database remains
accurate and up to date.

A powerful search functionality further streamlines the admin's tasks, enabling quick and
efficient retrieval of specific employee records based on various criteria.

Altogether, the Employee Form stands as a vital component, providing the necessary tools for
effective employee management within the payroll system.

Gattapola Arachchilage Lahiru Shehan


110
Karunarathne
4.1.6 Employe Salary Information Form

Figure 40 Employe Salary Adding Form(authors work)

The Basic Salary Form represents the core of the salary calculation component within the
Grifindo Toys Payroll System. Its features are designed to facilitate precise salary calculations,
ensuring accuracy and fairness in remuneration.

Admin users input the date range for which salaries are to be calculated, defining the scope of
the salary cycle. The form also accommodates the recording of leaves, absent days, holidays,
and overtime hours, crucial elements for determining the base pay.

Complex algorithms and formulas are applied to calculate the base pay value, taking into
account the monthly salary, allowances, and overtime rates. This form, therefore, serves as a
critical interface for administrators to orchestrate precise and transparent salary computations.

Gattapola Arachchilage Lahiru Shehan


111
Karunarathne
Gattapola Arachchilage Lahiru Shehan
112
Karunarathne
4.1.7 Settings Component

Figure 41 Settings Component(authors work)

The Settings Form plays a pivotal role in providing administrators with the flexibility to tailor
the Grifindo Toys Payroll System according to specific organizational requirements. This
component allows the admin to finetune parameters essential for accurate salary calculations.

Key configurable elements include the date range for a salary cycle, providing flexibility in
aligning the system with the company's unique payroll structure. The admin can set the salary
cycle's beginning and end dates, ensuring synchronization with organizational policies.

Furthermore, the Settings Form facilitates the adjustment of critical factors such as the number
of leaves an employee is entitled to within a given year. In essence, the Settings Form
empowers administrators with the tools needed to customize the payroll system to meet the
specific needs of Grifindo Toys.

Gattapola Arachchilage Lahiru Shehan


113
Karunarathne
Gattapola Arachchilage Lahiru Shehan
114
Karunarathne
4.1.8 Salary Component

Figure 42 Salary Component(authors work)

The Salary Form represents the pinnacle of the Grifindo Toys Payroll System's functionality,
where intricate salary calculations are executed with precision.

This form orchestrates a multi-step process, involving the calculation of base pay,
determination of no-pay values in case of absenteeism, and the ultimate calculation of gross
pay. The base pay is derived from a complex formula considering monthly salary, allowances,
and overtime rates. Simultaneously, the system calculates the no-pay value if an employee has
been absent, ensuring fairness in remuneration.

The gross pay, the final outcome, is then determined by subtracting the sum of no-pay value
and government tax rates from the base pay. The calculated values, including no-pay, base pay,
and gross pay, are meticulously recorded in the database, forming a comprehensive record for
each employee for every month.

Gattapola Arachchilage Lahiru Shehan


115
Karunarathne
Gattapola Arachchilage Lahiru Shehan
116
Karunarathne
4.1.8 View

Figure 43 View(authors work)

The View Form acts as the analytical powerhouse of the Grifindo Toys Payroll System,
providing administrators with powerful tools for generating insightful reports. This form
enables the generation of detailed reports, including monthly salary reports for individual
employees and overall salary summaries spanning multiple months.

These reports offer a comprehensive view of each employee's remuneration, fostering


transparency and accountability within the organization. Additionally, the View Form displays
critical values such as no-pay, base-pay, and gross pay for all employees within a given month
range.

This holistic reporting functionality ensures that administrators can gain valuable insights into
the payroll data, facilitating informed decision-making and strategic planning for the
organization's financial management.

Gattapola Arachchilage Lahiru Shehan


117
Karunarathne
4.2 Debugging Process in Visual Studio.

Breakpoints allow developers to pause the execution of the code at a specific line,
Setting providing a snapshot of the program's state. By strategically placing breakpoints,
Breakpoint developers can inspect variables, identify potential security vulnerabilities, and ensure
the robustness of the application by understanding its behavior at critical points.

Visual Studio allows developers to inspect variables and values during runtime. This
Inspecting feature is invaluable for identifying unexpected behaviors, ensuring that variables
Variables contain the expected values, and mitigating security risks related to data manipulation
and Values or injection.

These windows in Visual Studio enable developers to monitor specific variables and
Watch and expressions. By using the Watch and Immediate windows, developers can evaluate
Immediate the correctness of code logic, identify potential security threats related to variable
Windows manipulation, and enhance the overall robustness of the application.

Role in Security and Robustness: Visual Studio provides robust exception handling
Exception features, allowing developers to catch and handle exceptions during debugging. By
Handling: examining exception details, developers can identify potential security risks and
Exception implement proper error handling mechanisms, enhancing the overall security and
Handling robustness of the application.

Gattapola Arachchilage Lahiru Shehan


118
Karunarathne
The Call Stack window in Visual Studio displays the sequence of method calls
leading to the current point in the code. This is crucial for understanding the
program's flow and identifying potential security vulnerabilities related to unexpected
Call Stack
method invocations or stack-related issues, contributing to a more robust application.
Role in Security and Robustness:

The Call Stack window in Visual Studio displays the sequence of method calls
leading to the current point in the code. This is crucial for understanding the
program's flow and identifying potential security vulnerabilities related to unexpected
method invocations or stack-related issues, contributing to a more robust application.

Table 5 Debugging Processes in Visual Studio

4..2.1 Debugging Grifindo Toys Project

Identifying Security Vulnerabilities:

Debugging played a critical role in uncovering potential security vulnerabilities within the
application. For instance, during the debugging process, breakpoints and variable inspection
revealed instances where user input lacked proper validation or sanitization.

Below Images Showcase the Error Encountered, But Was able to Fix after Debugging.

Figure 44 Correct Info is Entered(authors work)

Gattapola Arachchilage Lahiru Shehan


119
Karunarathne
Figure 45 But It Says Invalid(authors work)

Gattapola Arachchilage Lahiru Shehan


120
Karunarathne
Addressing Code Execution Issues:

The debugging process facilitated the tracing of the application's flow, revealing areas
susceptible to unauthorized code execution. By leveraging debugging features, specific instances
were identified and subsequently addressed, fortifying the application against potential security
risks.

Below Example Image Shows a Error faced and How Visual Studio Debugging Process Showed
the Error and Potential Fixes.

Figure 46 Visual Studio Warning Indicating there is an Error(authors work)

Gattapola Arachchilage Lahiru Shehan


121
Karunarathne
Exception Handling and Security.

Exception handling mechanisms were thoroughly tested and refined during the debugging
process. Instances where exceptions were discovered and handled appropriately were explored.
The debugging process contributed to robust exception handling, preventing potential security
breaches.

Figure 47 Visual Studio Error Handling(authors work)

The debugging process has proven instrumental in fortifying the security and robustness of the
application. The iterative nature of debugging, coupled with continuous improvement in
response to findings, has contributed to the development of a reliable and secure software
application.

Gattapola Arachchilage Lahiru Shehan


122
Karunarathne
4.3 Coding Standards and outline of Grifindo Toys System.

2.3.1 Loading Screen

Loading Texts and Initialization.

In the constructor, an array of loading texts is defined to provide dynamic messages during the
loading process. The InitializeTimer method sets up a timer, and the form is configured for a
borderless appearance, double buffering, and resizing.

Figure 48 Loading Screen(authors work)

Gattapola Arachchilage Lahiru Shehan


123
Karunarathne
Figure 49 Loading Texts and Initialization(authors work)

Figure 50 Loading Texts and Initialization(authors work)

Gattapola Arachchilage Lahiru Shehan


124
Karunarathne
Timer Tick Event
The Timer_Tick method is triggered at intervals. It rapidly updates two labels with loading
texts using the RapidLabelUpdate method. After 10 seconds, the timer stops, the loading screen
is hidden, and the login form is shown.

Figure 51 timer Tick Event(authors work)

Gattapola Arachchilage Lahiru Shehan


125
Karunarathne
Rapid Label Update.

RapidLabelUpdate cycles through loading texts for two labels, updating them with a red color.
The method uses BeginInvoke to update the UI on the main thread, ensuring thread safety.
Label indices are incremented to display different texts in subsequent calls

Figure 52 Simulating The Texts like a Loading Screen(authors work)


Rounded Edges Drawing

OnPaint, PictureBox1_Paint, and panel1_Paint methods handle drawing rounded edges for the
form, picture box, and panel, respectively. GraphicsPath is utilized to create a path with
rounded corners, and Region is set to apply the rounded shape. These methods contribute to a
visually appealing and modern user interface.

Gattapola Arachchilage Lahiru Shehan


126
Karunarathne
Figure 53 Round Edged Form(authors work)

2.3.2 Login Form.

Validating User Credentials.

This part defines two constants for a hardcoded valid username and password.
PerformLogin method checks if the entered username and password match the valid credentials.
If valid, it opens the FormMainMenu. If not, it displays error messages and clears the respective
textboxes.

Gattapola Arachchilage Lahiru Shehan


127
Karunarathne
Figure 54 Validate Login(authors work)

Gattapola Arachchilage Lahiru Shehan


128
Karunarathne
Figure 55 Login Form, (authors work)

Figure 56 If user input Invalid Info(authors work)

Gattapola Arachchilage Lahiru Shehan


129
Karunarathne
UI Elements and Styling.

In the constructor, initial settings for UI elements are configured.


lbluser and lblpass are set to be initially visible with green text.
The form is set to start in the center of the screen.

Figure 57 Styling(authors work)

Gattapola Arachchilage Lahiru Shehan


130
Karunarathne
2.3.3 Main Form

Figure 58 Main Form(authors work)


Random Color Selection

The SelectThemeColor method is responsible for choosing a random color from a predefined list
to be used as the theme color for buttons and panels. It employs a simple randomization
technique, ensuring that the same color is not selected consecutively to enhance visual variety.
This function is crucial for providing a visually appealing and diverse user interface.

Figure 59 Color 1(authors work) Figure 60 color 2(authors work)

Gattapola Arachchilage Lahiru Shehan


131
Karunarathne
Gattapola Arachchilage Lahiru Shehan
132
Karunarathne
Figure 61 Theme Class, Colors(authors work)

Figure 62 Color Selection(authors work)

Gattapola Arachchilage Lahiru Shehan


133
Karunarathne
Button Activation.

In the ActivateButton method, a button is dynamically styled when clicked. It changes the
button's background color, text color, font, and also adjusts the theme colors of the title bar and
logo panel. This function not only enhances the visual feedback for the user but also ensures a
consistent and aesthetically pleasing appearance in line with the chosen theme.

Figure 63 Button Activates upon Clicking(authors work)

Figure 64 Button Activation(authors work)

Gattapola Arachchilage Lahiru Shehan


134
Karunarathne
Button Deactivation

DisableButton is a utility method that resets the appearance of all buttons in the menu,
deactivating them. This function is called before activating a new button, ensuring that only the
clicked button stands out visually. Consistent styling is maintained, contributing to a coherent
and user-friendly interface.

Figure 65 Button Deactivation(authors work)

Figure 66 other Buttons Deactivate upon Clicking another button(authors work)

Gattapola Arachchilage Lahiru Shehan


135
Karunarathne
Opening Child Forms.

OpenChildForm is a versatile method used for displaying child forms within the main form. It
handles the closure of any existing child form, activates the corresponding button, sets up the
properties of the child form for display, and updates the title label. This method centralizes the
logic for opening child forms, promoting code reuse and maintainability.

Figure 67 Onpen Forms Withing another form(authors work)

Figure 68 Employe Form opened in Main Form(authors work)

Gattapola Arachchilage Lahiru Shehan


136
Karunarathne
Timer for Displaying Current Time

The timer1_Tick method is triggered periodically by a timer. It updates a label (label5) with the
current time in the format "HH:mm:ss". This real-time clock feature adds a dynamic element to
the form, providing users with up-to-date information. The timer enhances the user experience
by offering a continuously updated display of the current time.

Figure 69 Display Time(authors work)

Figure 70 Live time Can Be seen on Top(authors work)

Gattapola Arachchilage Lahiru Shehan


137
Karunarathne
2.3.4 Employe Component

Random ID Generator

This method generates a random employee ID in the format "GTXXX," where XXX is a three-
digit number. The generated ID is displayed in the empid TextBox.

Figure 71 Id Generator(authors work)

Figure 72 generated ID(authors work)

Gattapola Arachchilage Lahiru Shehan


138
Karunarathne
Database Operations (Add Employee)

Figure 73 Employe and Salary Details have Added Successfully(authors work)

Figure 74 Data View(authors work)

Gattapola Arachchilage Lahiru Shehan


139
Karunarathne
Database Operations (Update Employe)

Figure 75 Data Updated(authors work)

Database Operations (Delete Employe)

Gattapola Arachchilage Lahiru Shehan


140
Karunarathne
Figure 76 Data Deleted(authors work)

Database Operations (Search/Data Retrieve)

Figure 77 Data Retrieve / Search(authors work)

Gattapola Arachchilage Lahiru Shehan


141
Karunarathne
4.3.5 Settings Component

Figure 78 Settings Component(authors work)


Salary Summary Generation:

Figure 79 Salary Summary generation(authors work)

Gattapola Arachchilage Lahiru Shehan


142
Karunarathne
Generating and Displaying Salary Summary.

This method is triggered when the "Generate Summary" button is clicked. It collects input from
textboxes and date pickers, calls the GenerateSalarySummary method, and displays the
generated salary summary in the SummaryTextBox.

Figure 80 Generating and Displaying Salary Summary(authors work)

Gattapola Arachchilage Lahiru Shehan


143
Karunarathne
Setting Default Information.

This method is triggered when the "Set Default Info" button is clicked. It sets default values for
the date range, salary cycle begin date, salary cycle end date, and leaves, providing a
convenient way to reset the form to predefined settings.

Figure 81 Set Default information(authors work)

Figure 82 Generate Summary and Set Default info(authors work)

Gattapola Arachchilage Lahiru Shehan


144
Karunarathne
2.3.5 Salary Component.

Figure 83 Salary Component.(Authors Work)

Get info
This method is triggered when the "Get Info" button is clicked. It retrieves employee
information from the database based on the provided employee ID (empID). If data is found, it
updates various textboxes and date pickers with relevant information.

Gattapola Arachchilage Lahiru Shehan


145
Karunarathne
Figure 84 Retreve Employe information To the Salary Component (Authors Work)

Gattapola Arachchilage Lahiru Shehan


146
Karunarathne
Salary Calculation Logic:

This is a custom method (CalculateSalary) where you can implement your logic to calculate the
salary based on the provided dates attended, OT hours, and other relevant information.

Figure 85 Salary Calculated According to the Given info (Authors work)

Figure 86 Salary Calculation Code (authors Work)

Gattapola Arachchilage Lahiru Shehan


147
Karunarathne
Gattapola Arachchilage Lahiru Shehan
148
Karunarathne
2.4 Coding Standards in Software Development.

Coding standards play a pivotal role in shaping the landscape of software development,
impacting both teams and individual developers.

From enhancing code readability to fostering collaborative efficiency and minimizing errors,
the discussion will explore how coding standards contribute to the overall success and
sustainability of software projects.

Table 6 Coding Standards

Team Individual

Consistency and Readability: A coding standard ensures For an individual developer,


that all team members follow following a coding standard
a consistent style. This promotes consistency in their
consistency enhances code own code. It allows them to
readability, making it easier maintain a uniform and clear
for team members to structure, which aids
understand and collaborate readability and
on the codebase. understanding.

Maintainability: A consistent coding style For an individual,


simplifies maintenance tasks. maintaining their own code
When multiple team becomes more manageable.
members work on a project, The developer can revisit
adhering to a coding standard their code after some time
ensures that any team and quickly understand its
member can easily structure, reducing the
understand and modify code likelihood of introducing
written by others. errors during updates.

Collaboration: When team members follow An individual developer, by


a shared coding standard, adhering to a coding
collaboration becomes standard, ensures that their
smoother. Code reviews are code integrates seamlessly
more effective, and team with the work of others. This
members can seamlessly is particularly important
switch between tasks without when working on larger

Gattapola Arachchilage Lahiru Shehan


149
Karunarathne
struggling to adapt to projects with multiple
different coding styles. contributors.

Bug Prevention A coding standard can By following a coding


include rules that prevent standard, an individual
common programming developer incorporates
errors. This reduces the preventive measures into
chances of introducing bugs their code, minimizing the
or security vulnerabilities in risk of introducing errors.
the code.

Onboarding and Training: New team members can For an individual developer,
quickly adapt to the project adhering to a coding standard
environment when there is a aid in self-learning and skill
coding standard in place. It development. It becomes a
expedites the onboarding guide for writing better code
process and facilitates and learning from established
knowledge transfer. practices.

Code Reviews: Code reviews are more For an individual, regular


efficient and effective when participation in code reviews
team members are following provides valuable feedback.
the same coding standard. It It's an opportunity to learn
helps in focusing the review from others, improve coding
on logic and functionality practices, and contribute to a
rather than stylistic. collective code quality.

Gattapola Arachchilage Lahiru Shehan


150
Karunarathne
References

Algorithms - https://www.khanacademy.org/computing/computer-science/algorithms

Characteristics of a Good Algorithm - https://www.geeksforgeeks.org/characteristics-of-a-


good-algorithm/

Pseudo Codes - https://en.wikipedia.org/wiki/Pseudocode

Fibonacci Series - https://www.mathsisfun.com/numbers/fibonacci-sequence.html

Python Algorithm to Generate both Fibonacci and Factorial Series in a Number -


https://www.w3resource.com/python-exercises/data-structures-and-algorithms/python-
recursion.php

Programming Paradigms: An Overview - https://en.wikipedia.org/wiki/Programming_paradigm

Characteristics of Procedural Programming -


https://www.tutorialandexample.com/characteristics-of-procedural-programming/

Object-Oriented Programming (OOP) -


https://docs.oracle.com/javase/tutorial/java/concepts/index.html

Event-Driven Programming - https://docs.oracle.com/javase/tutorial/uiswing/events/index.html

Overview of Visual Studio IDE - https://docs.microsoft.com/en-us/visualstudio/ide/?view=vs-


2023

Creating Separate Classes for Components -


https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/classes

Database Structure Design - https://www.1keydata.com/database-normalization/

Database Design Principles - https://www.sqlshack.com/learn-sql-database-design-principles/

SQL Table Creation for Employee Information -


https://www.w3schools.com/sql/sql_create_table.asp

SQL Table Creation for Salary Information - https://www.sqlservertutorial.net/sql-server-


basics/sql-server-create-table/

Gattapola Arachchilage Lahiru Shehan


151
Karunarathne
Code Editing and Autocompletion -
https://en.wikipedia.org/wiki/Integrated_development_environment#Code_editing

Debugging Tools - https://docs.microsoft.com/en-us/visualstudio/debugger/?view=vs-2023

GUI Design and Form Building -


https://en.wikipedia.org/wiki/Graphical_user_interface_builder

Advantages of Using Visual Studio - https://visualstudiohacks.com/2019/01/28/top-6-


advantages-of-using-visual-studio/

Efficiency in Coding and Debugging - https://dev.to/shrutikapoor08/5-tips-for-efficient-coding-


and-debugging-20c7

Integration with .NET Framework - https://docs.microsoft.com/en-us/dotnet/standard/overview

Visual Studio vs. Manual Development - https://medium.com/@josalermo/visual-studio-code-


vs-manual-development-the-holy-war-67c687c87718

Visual Studio Code Overview - https://code.visualstudio.com/docs

Basics of C# Programming Language - https://docs.microsoft.com/en-us/dotnet/csharp/

Best Practices for Algorithm Design - https://betterprogramming.pub/5-important-algorithms-


in-c-e52265c6b1a3

Understanding Software Design Patterns - https://refactoring.guru/design-patterns

SQL Database Normalization - https://www.studytonight.com/dbms/database-


normalization.php

Introduction to Object-Relational Mapping (ORM) - https://docs.microsoft.com/en-us/ef/

Building Responsive User Interfaces in WinForms - https://www.telerik.com/winforms

Agile Software Development Methodology - https://www.atlassian.com/agile

Importance of Code Documentation -


https://www.codeproject.com/Articles/1276028/TheImportance-of-Code-Documentation

Gattapola Arachchilage Lahiru Shehan


152
Karunarathne
Introduction to Test-Driven Development (TDD) -
https://www.tutorialspoint.com/software_testing_dictionary/test_driven_development.html

Overview of .NET Framework - https://docs.microsoft.com/en-us/dotnet/framework/

Cloud-Based Development with Azure -


https://docs.microsoft.com/en-us/azure/devops/devops-projects/overview

Introduction to Git Version Control - https://git-scm.com/doc

Importance of Coding Standards - https://www.freecodecamp.org/news/why-coding-standards-


matter-8f4a557e3640/

Basics of Relational Databases - https://www.tutorialspoint.com/dbms/index.html

Code Review Best Practices - https://smartbear.com/learn/code-review/what-is-code-review/

Introduction to Windows Forms Applications -


https://docs.microsoft.com/en-us/dotnet/desktop/winforms/

Gattapola Arachchilage Lahiru Shehan


153
Karunarathne

You might also like