0% found this document useful (0 votes)
84 views107 pages

Dishan Sanjaya - E007781 - Unit 01 Programming Assignment - Reworded 2021

Uploaded by

Charles Rodrigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views107 pages

Dishan Sanjaya - E007781 - Unit 01 Programming Assignment - Reworded 2021

Uploaded by

Charles Rodrigo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

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

Student’s name
List which assessment criteria Pass Merit Distinction
the Assessor has awarded.

INTERNAL VERIFIER CHECKLIST

Do the assessment criteria awarded match


those shown in the assignment brief? Y/N

Is the Pass/Merit/Distinction grade awarded


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

Assessor signature Date

Internal Verifier signature Date


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

Give details:

Assessor signature Date

Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
Higher Nationals - Summative Assignment Feedback Form
Student Name/ID
Unit Title
Assignment Number Assessor
Date Received 1st
Submission Date
submission
Date Received 2nd
Re-submission Date
submission
Assessor Feedback:

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

Pass, Merit & Distinction Descripts P1 M1 D1

LO2. Explain the characteristics of procedural, object-orientated and event-driven programming, conduct an analysis
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
Pearson Higher Nationals in
Computing
Unit 01: Programming
Assignment 01
General Guidelines

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

Word Processing Rules

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

Important Points:

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

Student Declaration

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

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


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

Student’s Signature: Date:


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

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, conduct an analysis of a suitable Integrated Development
Environment (IDE).

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.

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 Explain 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). you also need to
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.

Ayubo Drive is the transport arm of Ayubo Leisure (Pvt) Ltd, an emerging travel & tour
company in Sri Lanka. It owns a fleet of vehicles ranging from cars, SUVs to vans.

The vehicles that it owns are hired or rented with or without a driver. The tariffs are based on
the vehicle type. Some of the vehicle types that it operates are, small car, sedan car, SVUs, Jeep
(WD), 7-seater van and Commuter van. New vehicle types are to be added in the future.

Vehicle rent and hire options are described below.

1. Rent (With or without driver) – For each type of vehicle rates are given per day, per week
and per month. Rate for a driver also given per day. Depending on the rent period the total
rent amount needs to be calculated. For example: if a vehicle is rented for 10 days with a
driver, total amount to be calculated as follows:

Total rent = weeklyRent x 1 + dailyRent x 3 + dailyDriverCost x 10

2. Hire (with driver only) – These are based on packages such as airport drop, airport pickup,
100km per day package, 200km per day package etc. Standard rates are defined for a
package type of a vehicle typeif that is applicable for that type of vehicle.For each package
maximum km limit and maximum number of hours arealso defined. Extra km rate is also
defined which is applicable if they run beyond the allocated km limit for the tour. For day
tours if they exceed max hour limit,a waiting charge is applicable for extra hours. Driver
overnight rate and vehicle night park rate also defined which is applicable for each night
when the vehicle is hired for 2 or more days.

Activity 3

Function 1: Rent calculation.


Return the total rent_value when vehicle_no, rented_date, return_date, with_driver
parameters are sent in. with_driver parameter is set to true or false depending whether the
vehicle is rented with or without driver.

Function 2: Day tour - hire calculation.


Calculate total hire_value when vehicle_no, package_type, start_time, end_time,
start_km_reading, end_km_reading parameters are sent in. Should return base_hire_charge,
waiting_charge and extra_km_charge as output parameters.
Function 3: Long tour - hire calculation.
Calculate total hire_value when vehicle_no, package_type, start_date, end_date,
start_km_reading, end_km_reading parameters are sent in. Should return base_hire_charge,
overnight_stay_charge and extra_km_charge as output parameters.

Write suable algorithms for vehicle tariff calculation for rents and hires. Ideally 3
functions should be developed for this purpose as above. Use the visual studio IDE
(using C#.net) to Implement the above algorithms and design the suitable database
structure for keeping the tariffs for vehicle types and different packages which must be
used for implementing the above functions.

Analyze the features of an Integrated Development Environment (IDE) and explain how
those features help in application development. Evaluate the use of the Visual
StudioIDE for your application development contrasted with not using an IDE.

Activity 4

4.1 Design and build a small system to calculate vehicle hire amounts and record them in a
database for customer billing and management reporting forAyubo drive. This includes the
completing the database design started in 3.2 and implementing one or more GUIs for
vehicle, vehicle type, and package add/edit/delete functions. It essentially requires an
interface for hire calculation and recording function described above. Generating customer
reports and customer invoices are not required for this course work.

4.2 Explain debugging process and the features available in Visual studio IDE for debugging
your code more easily. Evaluate how you used the debugging process to develop more
secure, robust application with examples.

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

P1Provide a definition of what an algorithm is and outline


the process in building an application.

M1Determine the steps taken from writing code to


execution.

D1 Evaluate the implementation of an algorithm in a suitable


language. Evaluate the relationship between the written
algorithm and the code variant
LO2 Explain the characteristics of procedural,
objectorientated and event-driven programming,
conduct an analysis of a suitable Integrated
Development Environment (IDE)

P2Give explanations of what procedural, objectorientated,


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

M2 Compare and contrast the procedural, object


orientated and event driven paradigms used in given
source code of an application

D2Critically evaluate the source code of an application which


implements the programming paradigms, in terms of the
code structure and characteristics.

LO3Implement basic algorithms in code using an IDE.


P3Write a program that implements an algorithm using an
IDE.

M3Use the IDE to manage the development process of the


program.

D3Evaluate 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

P4Explain the debugging process and explain the debugging


facilities available in the IDE.

P5Outline the coding standard you have used in your code.


M4Evaluate how the debugging process can be used to
help develop more secure, robust applications.

D4 Critically evaluate why a coding standard is necessary in


a team as well as for the individual.
Table of Contents

1. Acknowledgement ......................................................................................................... 26
Activity 1 ........................................................................................................................... 27
1. What is an algorithm? .................................................................................................... 27
1.1 Main Characteristics of a good algorithm ................................................................ 27
1.2 Types of Algorithms ................................................................................................ 28
1.2.1 Pseudocode........................................................................................................ 28
1.2.2 Flow charts ........................................................................................................ 29
1.3 Featured Characteristics of a good algorithm: ......................................................... 31
1.4 Algorithms with Examples .................................................................................. 31
1.4.1 The Fibonacci series: ........................................................................................ 31
1.4.2 Factorial: ........................................................................................................... 32
1.5 Programming Process .............................................................................................. 33
1.5.1 Defining the Problem ........................................................................................ 33
1.5.2 Planning the solution ......................................................................................... 33
1.5.3 Coding the Program .......................................................................................... 34
1.5.4 Testing the program .......................................................................................... 34
1.5.5 Documenting the Program ................................................................................ 35
1.6 Steps of executing a program: .................................................................................. 36
1.7 What is Big-O notation? .......................................................................................... 37
1.8 Algorithm Performance............................................................................................ 37
1.9 Analysis types .......................................................................................................... 38
1.9.1 Best-Case .......................................................................................................... 38
1.9.2 Worst case ......................................................................................................... 38
1.9.3 Average Case .................................................................................................... 38
1.10 Determine Complexities ........................................................................................ 39
1.10.1 Linear Complexity (O(n)) ............................................................................... 39
1.10.2 Constant Complexity (O(C)) ........................................................................... 39
1.11 Fibonacci Series Python Code ............................................................................... 39
1.11.1 Program execution .......................................................................................... 40
1.12 Python code for the Factorial: ................................................................................ 40

19 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.12.1 Program execution .......................................................................................... 40
Activity 2............................................................................................................................ 41
2. Programming Paradigm ................................................................................................. 41
2.1 Procedural Programming– ....................................................................................... 42
2.1.1 Key Features of Procedural Programming ........................................................ 43
2.1.2 Advantages of Procedural Programming .......................................................... 44
2.1.3 Disadvantages of Procedural Programming ...................................................... 45
2.2 Object Oriented Programming (OOP) – .................................................................. 45
2.2.1 Advantages of Object-Oriented Programming ................................................. 46
2.2.2 Disadvantages of Object-Oriented Programming ............................................. 46
2.3 Event-Driven Programming– ................................................................................... 47
2.3.1 Key Features and Characteristics of event-driven programming...................... 47
2.4 Object-Oriented Programming Vs Procedural Programming .................................. 49
2.5 Key Differences between Procedural & Object-Oriented Programming ................. 49
2.6 Object-Oriented Programming and Event Driven Programming ............................ 50
Activity 3............................................................................................................................ 51
3.1 Function 1: Rent calculation. ................................................................................... 51
3.2 Function 2: Day tour - hire calculation. ................................................................... 53
3.3 Function 3: Long tour - hire calculation. ................................................................. 55
3.4 Database structure for the tariffs for vehicle types and different packages, ............ 56
3.5 Features of an Integrated Development Environment (IDE), .................................. 57
3.6 How Visual Studio help to me develop my application,.......................................... 57
Activity 4............................................................................................................................ 60
4.1 Login Screen ............................................................................................................ 60
4.2 Main Screen ............................................................................................................. 62
4.3 About Screen ............................................................................................................ 64
4.4 Customers Screen ..................................................................................................... 65
4.5 Rent Screen .............................................................................................................. 69
4.6 Packages Screen ....................................................................................................... 73
4.7 Drivers Screen .......................................................................................................... 77
4.8 Vehicle Suppliers Screen ......................................................................................... 81
4.9 Vehicles Screen ........................................................................................................ 86
4.10 Bill Screen .............................................................................................................. 92

20 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.11 Database Design ..................................................................................................... 99
4.12 What is Debugging? ............................................................................................. 100
4.12.1 Debugging in MS Visual Studio ................................................................... 100
4.12.2 Error Detection and correction ...................................................................... 101
4.12.3 Breakpoints ................................................................................................... 102
5. References .................................................................................................................... 105

List of Figures

Figure 1 - Flow Chart Symbols .......................................................................................... 29


21 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 2 - Fibonacci series python code ............................................................................ 39
Figure 3 - Executed python code and output of Fibonacci series ...................................... 40
Figure 4 - Factorial python code ........................................................................................ 40
Figure 5 - Executed python code and output of Factorial .................................................. 40
Figure 6 - Programming Paradigms ................................................................................... 42
Figure 7 - Procedural Programming example (Written in C language) ............................. 43
Figure 8 - Object oriented Programming example (Written in Java language) ................. 45
Figure 9 - Event-Driven Programming example (Written in JavaScript language) .......... 47
Figure 10 - Visual Studio 2022 Community Edition IDE ................................................. 57
Figure 11 - Tool box of Visual studio 2022 ....................................................................... 58
Figure 12 - Visual Studio have Intellisence ....................................................................... 58
Figure 13 - Visual Studio have Intellisence ....................................................................... 59
Figure 14 - Visual Studio Database server explorer .......................................................... 59
Figure 15 - Login Screen ................................................................................................... 60
Figure 16 - Login Screen Code .......................................................................................... 61
Figure 17 - Main Screen..................................................................................................... 62
Figure 18 - Main Screen Code 01 ....................................................................................... 62
Figure 19 - Main Screen Code 02 ...................................................................................... 63
Figure 20 - About screen .................................................................................................... 64
Figure 21 - Ayubo Screen Code ......................................................................................... 64
Figure 22 - Customer screen .............................................................................................. 65
Figure 23 - Customer screen Code 01 ................................................................................ 65
Figure 24 - Customer screen Code 02 ................................................................................ 66
Figure 25 - Customer screen Code 03 ................................................................................ 66
Figure 26 - Customer screen Code 04 ................................................................................ 67
Figure 27 - Customer screen Code 05 ................................................................................ 67
Figure 28 - Customer screen Code 06 ................................................................................ 68
Figure 29 - Rent Screen ..................................................................................................... 69
Figure 30 - Rent Screen Code 01 ....................................................................................... 69
Figure 31 - Rent Screen Code 02 ....................................................................................... 70
Figure 32 - Rent Screen Code 03 ....................................................................................... 70
Figure 33 - Rent Screen Code 03 ....................................................................................... 71
22 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 34 - Rent Screen Code 04 ....................................................................................... 71
Figure 35 - Rent Screen Code 05 ....................................................................................... 72
Figure 36 - Package Screen ................................................................................................ 73
Figure 37 - Package Screen Code 01 ................................................................................. 73
Figure 38 - Package Screen Code 02 ................................................................................. 74
Figure 39 - Package Screen Code 03 ................................................................................. 74
Figure 40 - Package Screen Code 04 ................................................................................. 74
Figure 41 - Package Screen Code 05 ................................................................................. 75
Figure 42 - Package Screen Code 06 ................................................................................ 75
Figure 43 - Package Screen Code 07 ................................................................................. 76
Figure 44 - Drivers Screen ................................................................................................. 77
Figure 45 - Drivers Screen Code 01................................................................................... 77
Figure 46 - Drivers Screen Code 02 .................................................................................... 78
Figure 47 - Drivers Screen Code 03................................................................................... 78
Figure 48 - Drivers Screen Code 04................................................................................... 79
Figure 49 - Drivers Screen Code 05................................................................................... 79
Figure 50 - Drivers Screen Code 06................................................................................... 80
Figure 51 - Drivers Screen Code 07................................................................................... 80
Figure 52 - Vehicle suppliers’ screen ................................................................................ 81
Figure 53 - Vehicle suppliers’ screen Code 01 .................................................................. 81
Figure 54 - Vehicle suppliers’ screen Code 02 .................................................................. 82
Figure 55 - Vehicle suppliers’ screen Code 03 .................................................................. 82
Figure 56 - Vehicle suppliers’ screen Code 04 .................................................................. 83
Figure 57 - Vehicle suppliers’ screen Code 05 .................................................................. 83
Figure 58 - Vehicle suppliers’ screen Code 06 .................................................................. 84
Figure 59 - Vehicle suppliers’ screen Code 07 ................................................................. 84
Figure 60 - Vehicle suppliers’ screen Code 08 .................................................................. 85
Figure 61 - Vehicles Screen ............................................................................................... 86
Figure 62 - Vehicles Screen Code 01................................................................................. 86
Figure 63 - Vehicles Screen Code 02................................................................................. 87
Figure 64 - Vehicles Screen Code 03................................................................................. 87
Figure 65 - Vehicles Screen Code 04................................................................................. 88
23 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 66 - Vehicles Screen Code 05................................................................................. 88
Figure 67 - Vehicles Screen Code 06................................................................................. 89
Figure 68 - Vehicles Screen Code 07................................................................................. 89
Figure 69 - Vehicles Screen Code 08................................................................................. 90
Figure 70 - Vehicles Screen Code 09................................................................................. 90
Figure 71 - Vehicles Screen Code 10................................................................................. 91
Figure 72 - Bill Screen ....................................................................................................... 92
Figure 73 - Bill Screen Code 01......................................................................................... 92
Figure 74 - Bill Screen Code 02......................................................................................... 93
Figure 75 - Bill Screen Code 03........................................................................................ 93
Figure 76 - Bill Screen Code 05......................................................................................... 94
Figure 77 - Bill Screen Code 04......................................................................................... 94
Figure 78 - Bill Screen Code 07......................................................................................... 95
Figure 79 - Bill Screen Code 06......................................................................................... 95
Figure 80 - Bill Screen Code 08......................................................................................... 96
Figure 81 - Bill Screen Code 09......................................................................................... 97
Figure 82 - Bill Screen Code 10......................................................................................... 97
Figure 83 - Bill Screen Code 11......................................................................................... 98
Figure 84 - Database structure ........................................................................................... 99
Figure 85 - Visual Studio 2022 Debug Menu .................................................................. 100
Figure 86 - Visual Studio 2022 Debug tools.................................................................... 100
Figure 87 - Visual Studio 2022 Error list ......................................................................... 101
Figure 88 - Visual Studio 2022 Errors and suggestions................................................... 101
Figure 89 - Visual Studio 2022 Breakpoints .................................................................... 102
Figure 90 - C# Variable declaration ................................................................................. 103
Figure 91 - Intended Code structure ................................................................................ 103
Figure 92 - Short code lines ............................................................................................. 104
Figure 93 - Single statement in single line ....................................................................... 104

24 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
List of Tables

Table 1 - Dry run of Fibonacci series ................................................................................ 36


Table 2 - Dry run of Factorial series .................................................................................. 36
Table 3 - Algorithm Performance ...................................................................................... 37
Table 4 - Object-Oriented Programming Vs Procedural Programming ............................ 49
Table 5 - Key Differences between Procedural & Object-Oriented Programming ........... 50

25 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1. Acknowledgement

First of all, I want to thank ESOFT Metro Campus from the bottom of my heart for giving
me this chance.

This project's completion was made possible by the encouragement of our lecturer, Mr.
Thanuja Sandaruwan, for those who backed us wholeheartedly.

I am extremely grateful to him for providing such nice support and guidance. Because
without his help and support, this program would be a pipe dream, and ultimately, my
cherished family members, who stood with me through everything. I appreciate all of
your help.

Last but not least, I must state that the satisfaction of completing a task successfully
would be lacking without mentioning the individuals whose ongoing cooperation made it
possible and whose persistent direction and support crown all efforts with success. I'm
grateful to my project mentor, Mr. Thanuja Sandaruwan, for her advice, inspiration, and
helpful criticism as I put my project together.

26 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Activity 1

1. What is an algorithm?
Algorithm is a sequence of steps to be followed to solve a problem. A dangerous situation
in which a particular data set or set of data is used as an input to be understood as an
information output and to have a clear meaning. The mathematical process uses a limited
number of steps, and the algorithm solves problems using a limited number of steps.

1.1 Main Characteristics of a good algorithm

1. Input specified –
A well-defined input of an algorithm produces 0 or more inputs. The input is the
data that will be changed during the computation to make the output. At least one
of an algorithm's inputs should be clear. Input accuracy means knowing what kind
of data, how much, and what shape the data should be in.

2. Output specified –
An algorithm must have one or more well defined outputs. The data that comes
out of the calculation is called the output. For example, an algorithm should have
one or more clear outputs that match what is wanted. For output accuracy, you
also need to know what kind of data, how much, and what shape the output should
be.

3. Definiteness –
An algorithm all steps have well defined clearly. Algorithms must describe each
step and the order in which they should be done. Definiteness means that you can
say precisely how input is turned into output. Algorithms should be easy to
understand. Each step must also be explained in detail. It should have everything
that can be measured and nothing that can be described.

27 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4. Effectiveness –
The subtle steps required to obtain the output should be called principle and
should be implemented in a timely manner. For an algorithm to work, all of the
steps that must be taken to get to the output must be possible with the available
resources. However, it shouldn't have any actions that aren't needed or are
repeated because that would make the algorithm less useful.

5. Finiteness –
The algorithm should end after a limited number of steps. The algorithm will have
to stop at some point. When you stop, you might get the result you were hoping
for, or you might get a message that no solution is possible. Algorithms must end
when they reach a certain number of steps. An algorithm shouldn't go on forever;
it should end after several steps.
We don't need an algorithm that works forever, so there is no point in making one.

6. Independent –
An algorithm should have systematic instruction and be independent of its
duration reduction code. An algorithm should have step-by-step instructions that
are not tied to any specific programming code. Instead, it should be written so that
any programming language can run.
So, these are the things that an algorithm should have for it to work well.

1.2 Types of Algorithms


There are two main algorithm methods, they are,
1. Pseudocode
2. Flow charts

1.2.1 Pseudocode
Pseudocode is a simple step by step text code written by using simple English language
which is describing the solution how will going to solve the problem.
Ex: Pseudocode for calculate sum of 6 numbers you entered.

28 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
PROGRAM GetSummation:
SET Sum TO 0
FOR 6 times
DISPLAY “Enter a score”
GET Score
CALCULATE Sum = Sum + Score
ENDFOR
DISPLAY “The Sum of scores you entered is:”
DISPLAY Sum
END

1.2.2 Flow charts


Flow chart graphical representation of the steps to follow to solve the problem. When
we draw Flow charts, we use some standard symbols. Therefore, it is easy to understand
anyone who know the basic meaning of the symbols.

Figure 1 - Flow Chart Symbols

29 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Ex: Flow chart for calculate sum of 6 numbers you entered,

Start

Count = 0
Sum = 0

Input number

Is No
Count <6

Yes
Sum = Sum + Number

Input number

Stop

30 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.3 Featured Characteristics of a good algorithm:
• Algorithms should be clear, precise, and unambiguous steps.
• Algorithms should have finite amount of input and output data
• Algorithms should have finite number of steps to solve the problem in finite time.
• Algorithms should be independent from any programming language.

1.4 Algorithms with Examples

1.4.1 The Fibonacci series:


The Fibonacci series is a set of numbers where the first two numbers are either 1 and
1 or 0 and 1, depending on where the series starts, and each number after that is the
sum of the two numbers before it.
In mathematics, a sequence is the list of numbers that is in order and follows a
specific pattern. The terms are the numbers that make up the sequence. For example,
there are arithmetic, geometric, harmonic, and Fibonacci sequences.
The Fibonacci sequence also called the Fibonacci numbers, is a set of numbers
where each number is equal to the sum of the two numbers before it. This is how the
Fibonacci Sequence is written:

31 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
PROGRAM Fibonacci_series:
Count = 1
OldNumber1 = 0
OldNumber2 = 1
CurrentNumber = 0

INPUT N
PRINT OldNumber1
PRINT OldNumber2

WHILE Count < N


CurrentNumber = OldNumber2 + OldNumber1
OldNumber1 = OldNumber2
OldNumber2 = CurrentNumber
PRINT CurrentNumber
Count = Count + 1
END WHILE
END.

1.4.2 Factorial:
PROGRAM Factorial:
Total = 1
INPUT Number
WHILE Number > 0
Total = Total * Number
Number = Number - 1
END WHILE
PRINT Total
END.

32 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.5 Programming Process
Programming is putting an algorithm into a notation called a programming language so
that a computer can run it. Both the process and the data must be able to be written
down in a programming language. To do this, languages have control structures and
types of data.
Creating a program has steps similar to any other problem-solving task. The
programming process is made up of five main parts:
Steps of writing program:

Defining the problem : Go through the problem and identify it correctly.


Planning the solution : Plan a solution for identified problem.
Coding the program : Make a code according to the plan which do in
above Step.
Testing the program : Test the developed program using testing methods.
Documenting the program : Create a document for the developed system for
hand over to the customer.

1.5.1 Defining the Problem


Let's say someone calls you because they need your help as a programmer. First,
you meet with users from the client organization to figure out the problem, or
you meet with a systems analyst who explains the project.
In particular, the task of defining the problem is to write down what you know
(the input—given data) and what you want to get out of the problem (the
output—the result). Then, in the end, you come up with a written agreement that
says, among other things, what kind of input, processing, and output is needed.
This is not an easy thing to do.

1.5.2 Planning the solution


Creating a solution to a problem is often done by drawing a flowchart, writing
pseudocode, or sometimes doing both. A flowchart is a picture of how to solve a
problem step by step. It has arrows that show the program's direction and boxes
and other symbols that show what activities will happen. It is a road map that
shows what your program will do and how it will do it. It shows what your
software will do and how it will do it. For example, the American National
Standards Institute (ANSI) has developed a set of universal flowchart symbols.

33 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 1 shows the characters and how they can be used in a simplified flowchart
of a typical daily task: mailing a letter.
Pseudocode is a nonstandard language that is based on English. It let’s you say
things more precisely than you could in plain English, but it doesn't require as
much precision as a formal programming language. With pseudocode, you can
focus on a program's logic without worrying about a programming language's
syntax.

1.5.3 Coding the Program


The next step for you as a programmer is to "code" the program, which means to
write down your solution in a programming language. Then, you will turn the
flowchart, pseudocode, or another tool's logic into a programming language. As
we've already said, a programming language is a set of rules that tell the
computer what to do. There are many ways to write code. Some examples are
BASIC, COBOL, Pascal, FORTRAN, and C. So, you might work with one or
more of these at some point. Later in this chapter, we'll talk more about the
different kinds of languages.

Even though programming languages work like the English language in terms of
grammar, they are much more precise. To get your program to work, you must
follow the syntax of the language you are using exactly. For example, using the
language correctly isn't a guarantee that your program will work, just like using
correct grammar doesn't mean you know what you're talking about. So the point
is that the first step is to use the language correctly. Then, your coded program
must be typed so the computer can understand it. This can be done with a
terminal or a personal computer.

1.5.4 Testing the program


Some experts say that if a program is well-made, it can be written right the first
time. However, they say there are mathematical ways to show that a program is
correct.

34 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
But the world is still imperfect, so most programmers get used to the idea that
their new programs probably have a few mistakes. At first, this is a bit
discouraging since programmers tend to be careful, precise, and proud of their
work. Still, there are many ways to make mistakes in programs, and you will
probably find a few of them, just like those who have come before you.

Debugging
Debugging is a term used a lot in programming. It means finding and fixing bugs
(mistakes), usually by running the program. These bugs are mistakes in logic,
like telling a computer to do something repeatedly but not telling it how to stop.
So, you run the program with the test data you've created during this step. To
ensure you test every part of the program, you must carefully plan the test data.

1.5.5 Documenting the Program


Documenting is an ongoing, necessary task, even if, like many programmers,
you'd instead do more exciting things with your computer. Documentation is a
written description of the program's programming cycle and specific facts. The
source and nature of the problem, a short description of the program, logic tools
like flowcharts and pseudocode, data record descriptions, program listings, and
testing results are all standard parts of program documentation. People also think
that comments in the program itself are an essential part of the documentation. In
addition, many programmers write documentation as they write code. In a
broader sense, program documentation can be a part of the documentation for an
entire system.

The intelligent programmer keeps a program's record as it is designed, built, and


tested. Documentation is needed to help people remember things and maintain
organized program planning. Also, documentation is essential for
communicating with other people interested in the program, especially other
programmers who may be part of a programming team. And because there is a
lot of turnovers in the computer industry, there needs to be written
documentation so that the people who come after you can make any necessary
changes to the program or find any mistakes you missed.

35 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.6 Steps of executing a program:

Fetch : Fetching given instructions by control unit in CPU.


Decode : Decode the instructions by control unit in CPU for execute.
Execute : Run the instructions to do the task.
Store : The result of execution will store in memory

A. For 5 to N as input

Count = Count + 1
Print OldNumber1
Print OldNumber2

CurrentNumber =

CurrentNUmber
CurrentNumber

OldNumber1 +
OldNumber1

OldNumber2

OldNumber2

OldNumber1

OldNumber2
Count

Print
1 01 0 1 0 1 1 1 1 2
2 - 1 1 1 2 1 2 2 3
3 - 1 2 2 3 2 3 3 4
4 - 2 3 3 5 3 5 5 5
5 - - - - - - - - -

Table 1 - Dry run of Fibonacci series


Final output: 0 1 1 2 3 5

B. For 6 to Number as input


Total Total Number = Number -1 Print Total
1 6 5 -
6 30 4 -
30 120 3 -
120 360 2 -
360 720 1 -
720 - - 720
Table 2 - Dry run of Factorial series
Final output: 720

36 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.7 What is Big-O notation?
The Big O notation is the mathematical notation that shows how a function behaves as
its argument approaches a specific value or infinity. It is part of a group of notations
called the Bachmann–Landau notation or asymptotic notation made by Paul Bachmann,
Edmund Landau, and others.
Big-O notation is a method that evaluate the efficiency of an algorithm. Usually in Big-
O notation we use two main methods to evaluate the efficiency.
• Time Complexity (No of steps).
• Memory Complexity.

In time complexity, it describes that the how many steps in algebraic form which follow
to do the task.
In memory complexity, it describes that the how much memory space use the program.

1.8 Algorithm Performance


Algorithm potency is defined as 1) time and 2) area. The time potency is calculated for
the mistreatment of electronic equipment utilization. The area potency is calculated by
mistreatment memory and disk usage of a formula. The developer ought to grasp the
distinction between performance and quality. However, the quality of the analysis does
not rely on any PC resources. Instead, it should be a modification that supports the input
size. For example, the formula performance is machine freelance and doesn't rely on
another factors. These following table explains the various run times.

Performence Name Description


O (1) Constant Does not depend on the size of the input
O(log(N) Logarithmic Commonly found in operations on binary
trees
O(N) Linear Running time increases linearly with the
size of the input
O(N log(N) Super linear Not allowed prior assumptions on the
input
O(N!) Factorial All the permutation of a list

Table 3 - Algorithm Performance


37 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
An Algorithm Associate in Urinalysis has to be compelled to be based on an Olympian
machine in a freelance manner. The RAM model is the memory model analysis that
measures the run time by tallying the number of steps involved in computing the formula.
It ought to vary, supported by the input size. However, the formula analysis does not rely
on the kind of computer. The worst-case analysis helps the formula behave in worst-case
situations and is beneficial in understanding the formula performance. For example, the
Large Buckeye State notation simplifies the formula analysis by providing
straightforward inquiries to understand the formula's performance. Large o notation
facilitates the comparison of algorithms.

1.9 Analysis types


The formula complexes AR's best, average, or worst-case analyses. The formula analysis
is expressed as a practiced large O notation. The best, average, and worst cases of a given
formula categorical what the resource usage could be a minimum of, at the forefront and
on the common, severally.

1.9.1 Best-Case
Best-case performance is utilized in engineering to elucidate the Associate in Nursing
algorithm’s behavior under the best conditions—for example, the array of things that are
already sorted.
Worst-case performance is utilized to analyze the formula behavior beneath worst-case
input and is the least accomplishable to unravel the matter. Then, it determines when the
formula will perform worst for the given information.
Average case Performance is the measured practice of the everyday best conditions to
unravel the matter. Example: kind, kindred things practice insertion type

1.9.2 Worst case


Worst-case performance is used to analyze the algorithm behavior under worst-case input
and the least possible solution. It determines when the algorithm will perform worst for
the given information.

1.9.3 Average Case


The average optimal conditions to solve this problem are used to measure the average
case performance. Using insertion sort, you can sort items that have already been partially
sorted.

38 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.10 Determine Complexities

The formula complex ignores the constant value in formula analysis. If the formula takes
n^2+13n+43 time to calculate all the steps, the formula analysis ignores all the constants
and takes a time of O (n^2).

1.10.1 Linear Complexity (O(n))


Complexity in terms of time means that the algorithms take the same amount of time to
finish as the number of inputs grows. Here are some examples of linear time algorithms:
Find the highest or lowest value in an array.

1.10.2 Constant Complexity (O(C))


The complexity of an algorithm is considered to be constant if the steps required to
complete its execution remain constant regardless of the number of inputs. For example,
constant complexity is denoted by O(c), where c might be any constant number.

1.11 Fibonacci Series Python Code


Python code for the Fibonacci series:

Figure 2 - Fibonacci series python code

39 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
1.11.1 Program execution

Figure 3 - Executed python code and output of Fibonacci series

1.12 Python code for the Factorial:

Figure 4 - Factorial python code

1.12.1 Program execution

Figure 5 - Executed python code and output of Factorial

40 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Activity 2

2. Programming Paradigm

what is meant by a programming paradigm?


A paradigm can also be termed as a method to solve some problem or do some tasks.
For example, a programming paradigm is an approach to solving problems using some
programming language. We can also say it is a method to solve a problem using tools
and techniques available to us, following some approaches. Many programming
languages are known, but all of them need to follow some strategy when implemented,
and this methodology or process is called a paradigm. Apart from the wide variety of
programming languages, there are many paradigms to fulfill every demand.
A programming paradigm is a classification that describe a style or a way of
programming which can use to solve the problem using programming language.
Ex:
• Procedural
• Object oriented
• Event-Driven

Some other common paradigms are:


1. Imperative
Programming with an explicit sequence of commands that updates the state.
2. Declarative
Programming by specifying your desired result, not how to get it.
3. Structured
Programming with clean, go to-free, nested control structures.
4. Flow-Driven
Programming processes communicate with each other over predefined channels.

41 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 6 - Programming Paradigms

2.1 Procedural Programming–


Procedural programming may be the first way a new developer learns to code. At its core,
procedural code is the code that tells a device, in a logical order, how to finish a task. This
model works from the top down and treats data and procedures as two separate things.
Based on the idea of a "procedure call," procedural programming divides a program into
"procedures," which are also called "routines" or "functions." Each procedure is just a list
of steps that need to be taken.

Simply put, procedural programming means writing down a list of instructions that tell
the computer what to do step-by-step to finish the task.

Procedural Programming which is based on concept of procedure calls. Statements are


organized into procedures in this method. Further the instructions will give to the
computer step by step.

Ex: Pascal, C

42 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 7 - Procedural Programming example (Written in C language)

• This is an example for procedural paradigm wrote in C language. This code is


written for show that it works of basic library functions in C.

2.1.1 Key Features of Procedural Programming

1. Predefined functions:
Most of the time, a predefined function is an instruction with a name. Most of the
time, predefined functions are built into higher-level programming languages, but
they come from the library or registry instead of the program. One example of a
predefined function is 'charAt' (), which searches a string for a specific character.

2. Local Variable:
A local variable is declared in the main structure of a method and can only be
used in the local area. This local variable can only be used in the methodology
where it is defined. If it is used outside of the method where it is specified, the
code will stop working.

43 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
3. Global Variable:
A global variable is declared outside of every other function in the code. Because
of this, global variables, unlike local variables, can be used in all functions.

4. Modularity:
Modularity is when two separate structures, each with its own set of tasks, are
combined or grouped to complete a single more significant task. Each group of
systems would have its own set of functions, which would be completed one by
one until the last task was completed.

5. Parameter Passing:
Parameter passing is a method for passing parameters to functions, subroutines,
and procedures. For example, "Pass by value," "pass by comparison," "pass by
the result," "pass by value-result," and "pass by the name" are all methods for
passing parameters.

2.1.2 Advantages of Procedural Programming

• Procedural programming is excellent for general-purpose programming.


• The coded simplicity and the ease of implementation of compilers and interpreters
• Many books and online course materials are available on tested algorithms,
making learning easier along the way.
• Through the Procedural Programming technique, the memory requirement is also
slashed.
• The program flow can be tracked easily.
• Since the source code is portable, it can also be used to run on a different CPU.
• It is easier to track the flow of the codes in a program written in the procedural
programming paradigm.
• You don't have to copy the code to use it in other parts of the program.
• The programming paradigm is regarded as the best for general programming to
learn and implement.

44 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
2.1.3 Disadvantages of Procedural Programming

• Data is exposed to the whole program, so there is no security for data.


• It isn't easy to relate to real-world objects.
• The difficulty of creating new data types reduces extensibility.
• Importance is given to the operation of the data rather than the data itself.
• The procedural code is often not reusable, which may pose the need to recreate the
code if it is needed to be used in another application.
• You don't have to copy the code to use it in other parts of the program.

2.2 Object Oriented Programming (OOP) –


Object-oriented programming is a way of writing the code that sees the world as a
collection of objects that work together to solve the problem. The most important thing to
know about OOP is encapsulation, which is the idea that each entity that holds a program
is self-sustaining, which means that all the parts that make up the object are inside the
object itself. Since each module in this paradigm can run independently, objects from one
program can be taken and used to solve a different problem with little or no changes.
Object oriented programs based on objects which contains data and codes which have
own behavior.
• Ex: C#, Java, C++

Figure 8 - Object oriented Programming example (Written in Java language)


45 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
• This is an example for Object Oriented Programming paradigm wrote in C++
language. This code is written for show that how the object and classes create and
implement those in C++.

2.2.1 Advantages of Object-Oriented Programming

• OOP is quicker and easier to put into action.


• OOP gives programs a straightforward way to be put together.
• OOP allows the creation of complete reusable applications with less code and
shorter development time.
• Over-generalization

2.2.2 Disadvantages of Object-Oriented Programming

• The relationship among all the available classes may become artificial, which may
cause difficulties in development.
• Due to the program's large size, there is a need to execute more instructions.
• Effort: Object-oriented programs require a lot of work to create.
• Speed: Object-oriented programs are slower than other programs because of their
size.

46 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
2.3 Event-Driven Programming–
Event-driven programming is a computer programming paradigm that uses events'
occurrences to determine the program's control flow. This application is designed to
detect events as they occur, and use an appropriate event-handling procedure to deal with
them, which usually uses a callback function or method.
Theoretically, the event-driven programming style is supported in all programming
languages, but they may be different in how it is implemented; for example, it's easier to
implement in languages that provide high-level abstractions, such as closures. Besides,
other programming environments, such as Adobe Flash, are specifically tailored for
triggering program code by events.
Event driven paradigm is controlling the program flow by events like mouse click, key
press.

Figure 9 - Event-Driven Programming example (Written in JavaScript language)

• This is an example for Event driven Programming paradigm wrote in Java Script
language. This code is written for show hidden CSS block in a website.

2.3.1 Key Features and Characteristics of event-driven programming


1. Service Oriented
Service-oriented Programming is a critical feature in event-driven programming
and is used to write programs made for services. However, it does not slow down
the computer as service-oriented programming only consumes a small part of the
computer's processing power. Usually, services run in the background of the OS.

2. Time Driven
In event-driven programming, a time-driven paradigm is a piece of code that
runs when a certain amount of time has passed. Time-driven can be a piece of
code that runs at a particular time, like once an hour, once a week, or once a
month. This means it's on your list of things to do. For example, Windows
Update is a time-driven program because users can choose when to update or
check for and download updates.

47 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
3. Event Handlers
Event handlers are functions or methods that perform a specific action when a
particular event is triggered. For an example, it could be a button that, when the
user clicks it, will display a message and close the message when the user clicks
the button again; this is an event handler.

4. Trigger Functions
In event-driven programming, trigger functions decide what code to run when a
specific event occurs. These are used to select which event handler to use for the
event when a particular event occurs.

5. Events
Events include mouse, keyboard, and user interface, in which events need to be
triggered in the program to happen, which means the user has to interact with an
object in the program, for example, clicking a button with a mouse, using the
keyboard to select a button, etc.

6. Simplicity of Programming and Ease of Development


Event-driven programming is simpler and more straightforward than other types
of programming, as it is very visual; for an example, you can place a button by
selecting it, putting it onto a form, and writing code. Event-driven programming
is also easy for users to insert pre-written code scripts into an existing
application because it allows users to pause the code while it’s running. This
makes development using event-driven programming easy.

48 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
2.4 Object-Oriented Programming Vs Procedural Programming

Procedural programming aims to break down a program into a collection of variables and
data structures. In contrast, the main aim of object-oriented programming is to break
down a programming task into objects. For example, procedural programming uses
procedures to operate on data structures, while object-oriented programming uses objects.
In both programming paradigms, the vocabulary is different, though they have similar
semantics:

Procedural Programming Object-Oriented Programming

Procedure Method

Record Object

Module Class

Procedure Call Message

Table 4 - Object-Oriented Programming Vs Procedural Programming

2.5 Key Differences between Procedural & Object-Oriented Programming


Procedural Programming Object-oriented Programming

It focuses on the process and functions. It focuses on the data and classes.

It is not easy to maintain. It is easy to maintain.

In this paradigm, if a sub-procedure has to be


In this paradigm, it is easy to maintain code
modified, it becomes difficult to find and
and modify existing code.
maintain it.

Due to its complexity, development time Due to easy maintenance, development


increases. time reduces.

Procedural programming languages are not The object-oriented programming


as faster as object-oriented. languages are faster and more effective.

Procedural uses procedures, modules, Object-oriented uses objects, classes,


procedure calls. messages.

It focuses on procedure rather data which has It focuses on data rather than procedures.

49 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
priority in data-driven systems.

In procedural programming, designs cannot


In object-oriented programming, designs
be reused and recycled throughout the
can be reused throughout the program.
program.

While solving issues in procedural In object-oriented programming, objects


programming, issues need to be addressed and classes can be referenced throughout
individually. the program.

Table 5 - Key Differences between Procedural & Object-Oriented Programming

2.6 Object-Oriented Programming and Event Driven Programming


Object-oriented programming focuses on performing actions and manipulating data
encapsulated in objects within a sequential series of steps. At the same time, event-driven
is more dynamic and relies on event triggering and event handling to determine the
sequencing of the program. Event-driven programs can have threads that perform actions
based upon triggers or events in your program.

With multi-threading, you can have more than one thread interact with your code
simultaneously. Multi-threading can use all of your CPU's cores, making it faster, but it
can also cause problems, like thread locking, when multiple threads try to access the same
object simultaneously.

Event-driven programming will still have objects, but it will also have threads that are
only initialized once an event has been triggered. For example, in a fire sprinkler system,
let's say there is a sensor for detecting a fire and a sprinkler system used to extinguish the
fire.

If we used only object-oriented, we would create an endless loop that constantly checks
the sensor's status. For example, if it detects a fire, we turn on the sprinkler, and the
program would work, but it would not be much use for any other task. For example, in an
event-driven program, we could set an event that triggers a thread when the fire sensor
activates, and we could create an event handler that would process the thread to tell the
sprinkler system to turn it on. In this fashion, our event program could also have other
functions as it is not stuck in an endless loop.
50 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Activity 3

3.1 Function 1: Rent calculation.


PROGRAM Rent_Calculation:
total_rent_value = 0
vechicel_no = 0
rented_date = 0
return_date = 0
with_driver = 0
no_of_day = 0
no_of_weeks = 0
no_of_months = 0

driver_rate Fetch from Database

INPUT vechicel_no
daily_rent_rate Fetch from Database according to vechicel_no
weekly_rent_rate Fetch from Database according to vechicel_no
monthly_rent_rate Fetch from Database according to vechicel_no

INPUT rented_date
INPUT return_date
INPUT with_driver

no_of_days = return_date - rented_date


no_of_months = no_of_days DIV 30
no_of_weeks = (no_of_days MOD 30) DIV 7
no_of_days = (no_of_days MOD 30) MOD 7

IF with_driver ==1 THEN


total_rent = no_of_months*monthly_rent_rate + no_of_weeks*weekly_rent_rate +
no_of_days* daily_rent_rate + driver_rate* no_of_days
ELSE

51 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
total_rent = no_of_months*monthly_rent_rate + no_of_weeks*weekly_rent_rate +
no_of_days* daily_rent_rate

END IF
PRINT total_rent
END.

52 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
3.2 Function 2: Day tour - hire calculation.
PROGRAM Day_tour_hire_Calculation:
total_hire_value = 0
base_hire_charge = 0
waiting_hire_charge = 0
extra_km_charge = 0

no_of_extra_km = 0
no_of_extra_hours = 0

INPUT vehicle_no
INPUT package_type
packge_price = Fetch from Database according to package_type and vehicle_no
max_km_limit = Fetch from Database according to package_type
extra_km_rate = Fetch from Database according to package_type
max_hour_limit = Fetch from Database according to package_type
extra_hourly_rate = Fetch from Database according to package_type

INPUT start_time
INPUT end_time
INPUT start_km_reading
INPUT end_km_reading
no_of_extra_km = (end_km_reading - start_km_reading) - max_km_limit
no_of_extra_hours = (end_time - start_time) - max_hour_limit

IF no_of_extra_km > 0 THEN


extra_km_charge = no_of_extra_km * extra_km_rate
END IF
IF no_of_extra_hours > 0 THEN
waiting_hire_charge = no_of_extra_hours * extra_hourly_rate
END IF
base_hire_charge = packge_price
total_hire_value = base_hire_charge + waiting_hire_charge + extra_km_charge
53 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
PRINT base_hire_charge
PRINT waiting_hire_charge
PRINT extra_km_charge
PRINT total_hire_value
END.

54 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
3.3 Function 3: Long tour - hire calculation.
PROGRAM Long_tour_hire_Calculation:
total_hire_value = 0
base_hire_charge = 0
overnight_stay_charge = 0
extra_km_charge = 0

no_of_extra_km = 0

INPUT vehicle_no
INPUT package_type
packge_price = Fetch from Database according to package_type and vehicle_no
max_km_limit = Fetch from Database according to package_type
extra_km_rate = Fetch from Database according to package_type
overnight_driver_rate = Fetch from Database according to vehicle_no
overnight_vehicle_rate = Fetch from Database according to vehicle_no

INPUT start_date
INPUT end_date
INPUT start_km_reading
INPUT end_km_reading

no_of_extra_km = (end_km_reading - start_km_reading) - max_km_limit

overnight_stay_charge = (end_date - start_date) * (overnight_driver_rate+


overnight_vehicle_rate)

IF no_of_extra_km > 0 THEN


extra_km_charge = no_of_extra_km * extra_km_rate
END IF
base_hire_charge = packge_price
total_hire_value = base_hire_charge + overnight_stay_charge + extra_km_charge

55 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
PRINT base_hire_charge
PRINT overnight_stay_charge
PRINT extra_km_charge
PRINT total_hire_value
END.

3.4 Database structure for the tariffs for vehicle types and different packages,
• hire_package (package_ID, package_name, vehicle_type, package_price,
max_km_limit, max_hour_limit, extra_km_rate, extra_hour_rate,
overnight_vehicle_rate, overnight_driver_rate)

• rent (vehicle_type, daily_rate, weekly_rate, monthly_rate, driver_rate)

• driver (driver_ID, driver_name, availability, driver_rate, joined_date, age,


address, telephone, NIC, no_of_hires)

• vehicle (vehicle_no, reg_no, vehicle_type, vehicle_model, rented_date,


rent_expire_date, monthly_rent, with_driver, driver_ID, owner_ID)

• vehicle_owner (owner_ID, owner_NIC, owner_name, address, telephone)

• customer (customer_ID, customer_name, hire_ID, rent_ID, address, telephone,


price, package_ID, vehicle_no, with_driver, driver_ID)

• hired (hire_ID, hired_date, hired_time, hire_end_date, hire_end_time, price,


no_of_km, no_of_hours, no_of_days, driver_ID, vehicle_no, customer_ID)

• rented (rent_ID, driver_ID, vehicle_no, start_date, start_time, end_date, end_time,


no_of_km, no_of_hours, price, customer_ID)

56 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
3.5 Features of an Integrated Development Environment (IDE),
• Include good code editor with color schemes to identify code types. Like variables
in one color methods are represent with another color etc.
• IDE contains all features what want to do development such as compiler,
interpreter, and debuggers.
• Can use for not only for one programming language and frameworks. Ex: Visual
studio can handle C#, C++, VB.Net, java script etc. and .net framework, xmarine
and react.
• Many IDEs have performance managing tools to detect and optimize program
performance.

3.6 How Visual Studio help to me develop my application,

Figure 10 - Visual Studio 2022 Community Edition IDE

• In Visual Studio I could design my program interfaces easily using win forms and
their own widgets(controls).

57 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 11 - Tool box of Visual studio 2022

• In the newer version of Visual Studio have Intelligence which helps to do coding
faster, because it auto completes codes, suggest the better code standards etc.

Figure 12 - Visual Studio have Intellisence

• Visual Studio can work together with one or more languages at the same time in
the same project.

58 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 13 - Visual Studio have Intellisence

• Visual Studio also can use as a database management system for the project
databases.

Figure 14 - Visual Studio Database server explorer

59 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Without IDE,
• Without using an IDE, I couldn’t detect so many errors and correct them
efficiently.
• Further it is so hard to design interfaces without IDE.
• If I use plan text editor for coding, I can’t go through code segments easily and
manage them.

Activity 4

4.1 Login Screen

Figure 15 - Login Screen

60 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Code

Figure 16 - Login Screen Code

61 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.2 Main Screen

Figure 17 - Main Screen

Code

Figure 18 - Main Screen Code 01

62 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 19 - Main Screen Code 02

63 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.3 About Screen

Figure 20 - About screen


Code

Figure 21 - Ayubo Screen Code

64 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.4 Customers Screen

Figure 22 - Customer screen

Code

Figure 23 - Customer screen Code 01

65 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 24 - Customer screen Code 02

Figure 25 - Customer screen Code 03

66 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 26 - Customer screen Code 04

Figure 27 - Customer screen Code 05

67 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 28 - Customer screen Code 06

68 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.5 Rent Screen

Figure 29 - Rent Screen


Code

Figure 30 - Rent Screen Code 01

69 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 31 - Rent Screen Code 02

Figure 32 - Rent Screen Code 03

70 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 33 - Rent Screen Code 03

Figure 34 - Rent Screen Code 04

71 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 35 - Rent Screen Code 05

72 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.6 Packages Screen

Figure 36 - Package Screen

Code

Figure 37 - Package Screen Code 01

73 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 38 - Package Screen Code 02

Figure 39 - Package Screen Code 03

Figure 40 - Package Screen Code 04

74 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 41 - Package Screen Code 05

Figure 42 - Package Screen Code 06

75 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 43 - Package Screen Code 07

76 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.7 Drivers Screen

Figure 44 - Drivers Screen

Code

Figure 45 - Drivers Screen Code 01

77 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 46 - Drivers Screen Code 02

Figure 47 - Drivers Screen Code 03

78 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 48 - Drivers Screen Code 04

Figure 49 - Drivers Screen Code 05

79 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 50 - Drivers Screen Code 06

Figure 51 - Drivers Screen Code 07

80 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.8 Vehicle Suppliers’ Screen

Figure 52 - Vehicle suppliers’ screen

Code

Figure 53 - Vehicle suppliers’ screen Code 01

81 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 54 - Vehicle suppliers’ screen Code 02

Figure 55 - Vehicle suppliers’ screen Code 03

82 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 56 - Vehicle suppliers’ screen Code 04

Figure 57 - Vehicle suppliers’ screen Code 05

83 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 58 - Vehicle suppliers’ screen Code 06

Figure 59 - Vehicle suppliers’ screen Code 07

84 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 60 - Vehicle suppliers’ screen Code 08

85 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.9 Vehicles Screen

Figure 61 - Vehicles Screen

Code

Figure 62 - Vehicles Screen Code 01

86 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 63 - Vehicles Screen Code 02

Figure 64 - Vehicles Screen Code 03

87 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 65 - Vehicles Screen Code 04

Figure 66 - Vehicles Screen Code 05

88 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 67 - Vehicles Screen Code 06

Figure 68 - Vehicles Screen Code 07

89 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 69 - Vehicles Screen Code 08

Figure 70 - Vehicles Screen Code 09

90 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 71 - Vehicles Screen Code 10

91 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.10 Bill Screen

Figure 72 - Bill Screen

Code

Figure 73 - Bill Screen Code 01

92 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 74 - Bill Screen Code 02

Figure 75 - Bill Screen Code 03

93 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 77 - Bill Screen Code 04

Figure 76 - Bill Screen Code 05

94 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 79 - Bill Screen Code 06

Figure 78 - Bill Screen Code 07

95 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 80 - Bill Screen Code 08

96 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 81 - Bill Screen Code 09

Figure 82 - Bill Screen Code 10

97 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Figure 83 - Bill Screen Code 11

98 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.11 Database Design

Figure 84 - Database structure

99 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.12 What is Debugging?

Debugging is the process of finding and removing coding mistakes/errors in computer


programs codes. The word 'bug' is use for representing the word 'error.' By debugging we
hope to develop more accurate and more correct (errorless) program.

4.12.1 Debugging in MS Visual Studio

Debugging in MS Visual Studio

Figure 85 - Visual Studio 2022 Debug Menu

Figure 86 - Visual Studio 2022 Debug tools

100 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
• We use above options for debugging in MS Visual Studio.

4.12.2 Error Detection and correction

• Using Error List we can identify where is errors were occurring and goto the code
lines which containing errors quickly.

Figure 87 - Visual Studio 2022 Error list

• We can fix errors by using suggestions provided by MS Visual Studio Debugger.

Figure 88 - Visual Studio 2022 Errors and suggestions

101 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
4.12.3 Breakpoints
Breakpoints are used to examine code that you want when you know the line of code or
the section in detail at runtime.

Figure 89 - Visual Studio 2022 Breakpoints

102 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
• General Naming guidelines – I have use general naming guidelines with naming
functions and variables. Like I used lower case to variable names and used
underscore instead spaces.

Figure 90 - C# Variable declaration


• Beautiful code structure – I have use indentations to make code beautiful for easy
to read.

Figure 91 - Intended Code structure

103 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
• Line lengths - I tried to use 80–100-character count in every code line as well as.

Figure 92 - Short code lines

• One statement per line - I have only type one statement in one line.

Figure 93 - Single statement in single line

Using coding standers, it is easy to understand, manage and edit to any programmer not
only who started the coding in the project but also another programmer who involved to
the same project. Therefore, using coding standards is very effective and best practice
for every programmer.

104 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
5. References

Techopedia.com. 2022. What is an Algorithm? - Definition from Techopedia. [online]


Available at: <https://www.techopedia.com/definition/3739/algorithm> [Accessed 27
July 2022].

Medium. 2022. Characteristics of an Algorithm. [online] Available at:


<https://medium.com/@bhattshlok12/characteristics-of-an-algorithm-49cf4d7bcd9>
[Accessed 27 July 2022].

GeeksforGeeks. 2022. Introduction of Programming Paradigms - GeeksforGeeks.


[online] Available at: <https://www.geeksforgeeks.org/introduction-of-programming-
paradigms/> [Accessed 27 July 2022].

Hackr.io. 2022. [online] Available at: <https://hackr.io/blog/procedural-programming>


[Accessed 27 July 2022].

Mathsisfun.com. 2022. Factorial Function !. [online] Available at:


<https://www.mathsisfun.com/numbers/factorial.html> [Accessed 27 July 2022].

Quora. 2022. What is a pseudocode for fibonnaic series?. [online] Available at:
<https://www.quora.com/What-is-a-pseudocode-for-fibonnaic-series> [Accessed 27 July
2022].

Homepage.cs.uri.edu. 2022. Computer Programming. [online] Available at:


<https://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm> [Accessed 27
July 2022].

freeCodeCamp.org. 2022. What is Big O Notation Explained: Space and Time


Complexity. [online] Available at: <https://www.freecodecamp.org/news/big-o-notation-
why-it-matters-and-why-it-doesnt-1674cfa8a23c/> [Accessed 27 July 2022].

Ukessays.com. 2022. Event-Driven Programming Features. [online] Available at:


<https://www.ukessays.com/essays/computer-science/eventdriven-programming-features-
6167.php> [Accessed 27 July 2022].

Dev, A., Prep, A., Learning, D., Mining, D., Learning, M., Experiences, I. and Dev Ruby
React JavaScript, W., 2022. Difference: Procedural & Object-Oriented Programming –
Coding Ninjas Blog. [online] Coding Ninjas Blog. Available at:
<https://www.codingninjas.com/blog/2020/12/18/difference-procedural-object-oriented-
programming/> [Accessed 27 July 2022].

Edureka. 2022. What is Debugging? Different Stages of Debugging | Edureka. [online]


Available at: <https://www.edureka.co/blog/what-is-debugging/> [Accessed 27 July
2022].

105 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
Docs.microsoft.com. 2022. First look at the debugger - Visual Studio (Windows). [online]
Available at: <https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-
tour?view=vs-2019#advance-the-debugger-out-of-the-current-function> [Accessed 27
July 2022].

GeeksforGeeks. 2022. Introduction of Programming Paradigms - GeeksforGeeks.


[online] Available at: <https://www.geeksforgeeks.org/introduction-of-programming-
paradigms/> [Accessed 27 July 2022].

Wcs.smartdraw.com. 2022. [online] Available at:


<https://wcs.smartdraw.com/flowchart/img/basic-symbols.jpg?bn=15100111839>
[Accessed 27 July 2022].

Cite this for Me | Free Reference Generator – Harvard, APA, MLA, Chicago...
2022. FREE Harvard Referencing Generator | Cite This For Me. [online] Available at:
<https://www.citethisforme.com/citation-generator/harvard> [Accessed 30 July 2022].

Technologyuk.net. 2022. Event-driven Programming. [online] Available at:


<https://www.technologyuk.net/computing/software-development/software-design/event-
driven-programming.shtml> [Accessed 30 July 2022].

Gofpatterns.com. 2022. Big O Notation [Computer Science Case Study]. [online]


Available at: <https://www.gofpatterns.com/design-patterns/module2/big-O-
notation.php> [Accessed 30 July 2022].

Coursehero.com. 2022. paradigm-1.docx - Introduction of Programming Paradigms


Paradigm can also be termed as method to solve some problem or do some task. | Course
Hero. [online] Available at: <https://www.coursehero.com/file/84366685/paradigm-
1docx/> [Accessed 30 July 2022].

Eliason, K., 2022. Difference Between Object-oriented Programming and Procedural


Programming Languages. [online] NeONBRAND. Available at:
<https://neonbrand.com/websites/development/procedural-programming-vs-object-
oriented-programming-a-review/> [Accessed 30 July 2022].

Lucidchart. 2022. What is a Flowchart. [online] Available at:


<https://www.lucidchart.com/pages/what-is-a-flowchart-tutorial> [Accessed 30 July
2022].

Eliason, K., 2022. Difference Between Object-oriented Programming and Procedural


Programming Languages. [online] NeONBRAND. Available at:
<https://neonbrand.com/websites/development/procedural-programming-vs-object-
oriented-programming-a-review/> [Accessed 30 July 2022].

En.wikipedia.org. 2022. Multiple comparisons problem - Wikipedia. [online] Available


at: <https://en.wikipedia.org/wiki/Multiple_comparisons_problem> [Accessed 30 July
2022].

106 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781
• Please download Ayubo Drive Management System Programming
Assignment Project files here.

https://drive.google.com/drive/folders/1jO5BS6FnrrGosMV8yGZUfB02
ewOstmMy?usp=sharing

Ayubo Drive Management System Login

User Name: Dishan


Password: Dishan123

107 | P a g e
Dishan Sanjaya UNIT 01: Programming
E007781

You might also like