Programming Assignmet (1) - 231101 - 100644
Programming Assignmet (1) - 231101 - 100644
Computing
Unit 01: Programming Assignment 01
Assignment title
Aliyar Mohommad Aadhil
Student’s name
List which assessment criteria Pass Merit Distinction
the Assessor has awarded.
Give details:
Internal Verifier
Date
signature
Programme Leader
Date
signature (if required)
LO2. Explain the characteristics of procedural, object-orientated and event-driven programming, conduct an analysis of a suitable
Integrated Development Environment (IDE).
LO4. Determine the debugging process and explain the importance of a coding standard.
Pass, Merit & Distinction Descripts P4 P5 M4 D4
* Please note that grade decisions are provisional. They are only confirmed once internal and external moderation has taken place and
grades decisions have been agreed at the assessment board.
Assignment Feedback
Action Plan
Summative feedback
Assessor Date
signature
Student Date
signature
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.
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.
[email protected] 28/12/2022
Student’s Signature: Date:
(Provide E-mail ID) (Provide Submission Date)
Unit Tutor
Issue Date
Submission Date
Submission Format
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.
LO1. Define basic algorithms to carry out an operation and outline the process of
programming an application.
LO4. Determine the debugging process and explain the importance of a coding
standard
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
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.
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.
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:
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
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
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.
ALGORITHMS
What is an algorithm?
Characteristics of an algorithm.
Unambiguous – algorithms must give only one meaning. Each of the steps must be
clear
Independent – It should have step-by-step directions.
Input – Algorithms should have inputs
Output – It should have one or more outputs.
Finiteness – Algorithms must stop eventually
Effectiveness - It should be feasible with the available resources.
Algorithms to display the Fibonacci series and the factorial value using
Pseudo code
Fibonacci series
The Fibonacci sequence is a collection of integers (the Fibonacci numbers) that goes from 0
to 1, then 1, then 1, then a series of numbers that increase continuously after that. Each
number in the series is equal to the sum of the two numbers before it.
2. Algorithm Design
In this stage all the instructions which are to be perform at different stages are listed. These
are in simple English language. We may call it as a strategy.
3. Flowchart
It is a graphical tool that shows the steps/stages which are to be executed in a program. All
the steps which are written in the second stage are now presented in a diagrammatic manner
so as to make it easily understandable. Making of flowchart helps us in increasing our process
of program development because it facilitates us to define the logic, detecting and removing
errors in a program design.
Types of flow chart
System Flowchart shows the processing of entire system. It describes the input/output
devices, the media being used and the flow of data in the system.
Program flowchart shows the complete steps involved in the execution of a program
including I/O, processing, loops and branching. It is more detailed than system
flowchart.
5. Debugging
In this stage we remove all the errors in the program because when we are coding, there are
chances that some mistakes may occur at that time. Here the program is executed manually,
called DRY RUN. This is done several times until all the errors are removed from the
program and the system become errors less.
6. Testing
In this stage we test the program by entering dummy data (includes usual, unusual and invalid
data) to check the behavior and result of the program towards the given data.
7. Final Output
After going through all the above stages, the program is given the TRUE DATA. Here the
programmer expects the positive results of the program and expects full efficiency of the
program.
10. Documentation
Most of the programmer neglect this stage by giving many reasons, but this is very important
because this will help the programmer to correct the problems that may occur in the program.
Step n A B I c Output
Initial 4 0 1 1 0 0
st
1 iteration 1 2 2 1 1
2nd iteration 2 3 3 2 1
3rd iteration 2 5 5 3 2
4th iteration 5 8 8 4 3
step n f
1 5 120
Big-O notation
From a programming concept, Big O notation is used as a sort of measurement unit that helps
programmers evaluate or estimate the efficiency of a written bloc of code, a script or an
algorithm: “What the amount of time it’s going to take to run? What is the complexity
depending on the variation of data to be processed by that piece of code”.
It’s hard to determine the exact runtime of a script or an algorithm. Which is also dependent
on other factors such as the speed of the processor and other specifications of the computer in
which that script or algorithm is running. So instead of evaluating the runtime directly, big O
notation is used to evaluate how quickly the runtime grows relative to the input data to be
processed by that algorithm.
Time complexity. The time complexity of an algorithm determines the number of steps taken
by the algorithm, measured with respect to n (input data to be processed), the size of the
input.
Constant | O(1)
Notice that in the scenario above, the pigeon would take the same amount of time to
carry 5KB, 10MB or 2TB of data stored in the USB drive. The pigeon will always
take the same amount of time to move any amount of data from office A to office B,
It just has to fly 50 miles — considering certain assumptions and simplifications of
course.
So in Big O Notation, the time the pigeon takes to move data from office A to office B is
referred to as constant time: O(1). Meaning the time is constant with respect to the size of the
input.
Linear | O(n)
Whereas, transferring data over the internet would take longer and longer as the
amount of data to be transferred increase.
So in Big O Notation, the time the internet takes to transferred data from office A to Office B
will grow linearly and in direct proportion to the size of the input data set and represented
as O(n). with n being the amount of data to be transmitted.
In computer programming, Big O favors the worst-case performance scenario; meaning, for
example, a case where we are looking for a matching number in an array of number which
could be found during any iteration of the for loop and the function would return early. Big O
notation will always assume the upper limit where the algorithm will perform the maximum
number of iterations to find the matching number (if the number was the last element stored
in the array).
Quadratic | O( n²)
Quadratic or O(N²) represents an algorithm whose performance is directly proportional to the
square of the size of the input data set.
A nested iteration over the data set ( such as nest for loop) is a common example of a script or
algorithm that involve quadratic runtime. Thus, deeper nested iterations will result in O(N³),
O(N⁴), etc
Exponential | O(2^n)
Logarithmic| O(log n)
Logarithmic time complexity is a bit trickier to get at first. So I’m going to use a common
example to explain it: Binary search concept.
Binary search is a technique used to search sorted data sets. It works by selecting the middle
element of the data set and compares it against a target value. If the values match it will
return success. If the searched value is higher than the value of the probe element it will take
the upper half of the data set and perform the same operation against it.
otherwise, if the searched value is lower than the value of the probe element it will perform
the operation against the lower half. this set of actions will continue to halve the data set with
each iteration until the searched value has been found or until it can no longer split the data
set:
A=0
B=1
C=0
if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence upto",n,":")
print(A)
else:
print("Fibonacci sequence:")
while n > C:
print(A)
I=A+B
A=B
B=I
C += 1
f=1
if num < 0:
print("Please enter a positive number")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
f = f*i
print("The factorial of",num,"is",f)
Event-driven Programming
Event-driven programming is a programming paradigm in which control flow of theprogram
is determined by the occurrence of events. For example a user action such as amouse click,
key press or a message from the operating system or another program.
#start
#to find the average of 3 numbers
#requsting user to insert the three numbers to input
x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))
z = int(input("Enter the third number: "))
#adding the three numbers
sum = x + y + z
#finding the average of the three numbers
avg = sum / 3
#displaying the numbers
print("first number: ", + x)
print("seocnd number: ", + y)
print("third number: ", + z)
#display the sum
print("sum of three numbers = ", + sum)
#display the average
print("Average = ", + avg)
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Program p0 = new Program();
Console.WriteLine("Enter the first number: ");
int number1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number: ");
int number2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the third number: ");
int number3 = Convert.ToInt32(Console.ReadLine());
p0.averageNumbers(number1, number2, number3);
}
int averageNumbers(int x, int y, int z)
{
int sum = x + y + z;
int avg = sum / 3;
Console.WriteLine("The Average is = " + avg);
return avg;
}
Critically evaluating the snippets of code given as example for Object oriented
programming
As shown in the code, I have made an instance named ‘averageNumbers’ to find the average
of 3 numbers. Inside this instance I have written a code to find the sum of the 3 numbers and
find the average by dividing it by 3. Then inside Main where the codes run, the user inputs
are asked for 3 variables. Then I call the instance ‘averageNumbers’
with the 3 inputs to find the average. In object oriented, we can make objects as above and
call them whenever necessary (we don’t have to write the whole code over and over again).
Here is another example,
In event-driven, as mentioned above, a program is executed after a user event like a mouse
click. The code I’ve given as an example is a code which gives a message “Welcome!” if the
user gives the correct username and password to login and “Invalid username or password” if
username or password is wrong. For this code to work, the user must insert the username and
password, then click login (mouse click and keyboard inputs).
Suitable algorithms for vehicle tariff calculation for rents and hires
Function Rent_calculation
Step 01 - Get values of vehicle_type, Rented_date, Return_date, Driver_parameters
Step 13 – end if
Function Day_tour_Hire
Function Long_tour_Hire
Programmers can compose their code, organize text sections, and automate repetitive
programming tasks using an IDE. IDEs, as opposed to standard code editors, combine the
capabilities of various programming processes into a single process. IDEs allow for the
insertion of the use of frameworks and component libraries to expand upon the basic code.
The primary advantage of IDEs is their built-in debuggers, which enable programmers to
quickly and readily find flaws or errors when they are triggered. Additionally, it enables the
assignment of grouped codes and the creation of hierarchies by many programmers. The
groups can then be connected, compiled, and constructed.(techopedia, 2022)
Features of IDEs
Text editor – Any IDE will have text editors which enables to write and
manipulate codes. Some IDEs have tools to drag and drop front-end components.
Debugger – This feature allows programmers to identify errors and bugs within
the code and fix them with ease. It also allows them to test different parts of the
application find errors to fix them.
The Visual Studio IDE is a creative launching pad that allows programmers to edit, debug,
build code and publish them as a application. Compared to a code editor or any other IDEs
that provide standard editor and debugger, Visual Studios IDE provides compliers, code
completion tools, graphical designers, and many other features which helps programmers
with the development process.
Code Cleanup - Code Cleanup format your code and apply any code fixes suggested
by your code style settings, editor config conventions, and Roslyn analyzers. (Note:
currently available for C# code only).
Example 1:
The code completion feature helped a lot to save time typing variable already declared and
calling names of tools to code.
Example 3:
Example 5:
Most errors are shown by a red line and once you hover on top of it, it shows the reason for
error as well which makes it much easier to find errors and debug before running the
program.
More uses of an IDE (debugging features) over not using an IDE are given under ‘Using the
debugging process to develop more secure, robust application’.
Login page
Add
Delete
Search
The process of Identifying and fixing/ removing of existing and potential errors/ bugs in a
software code that can cause it to behave unexpectedly or crash is called debugging.
Debugging helps to prevent faults in an software by identifying the problem and fixing it.
(techopedia, 2022)
The debugging process contains to steps namely “fault localization”, “fault repair/ bug
fixing”. A programmer sometimes duplicates the problem in a software code to find the error
and find the cause then modify or delete the code to prevent it from happening again. Both
the first and second steps are time consuming and are difficult. The first step is more
important since to fix an error, the problem must be found. (techopedia, 2022)
According to the site “The Economic Times”, the steps in a debugging process are,
“Reproduce the problem.
“Describe the bug. Try to get as much input from the user to get the exact reason.”
“Capture the program snapshot when the bug appears. Try to get all the variable
values and states of the program at that time”
“Analyze the snapshot based on the state and action. Based on that try to find the
cause of the bug.”
“Fix the existing bug, but also check that any new bug does not occur”
(techopedia, 2022)
There are many forms of debugging namely “Stepping through the code with a debugger”,
“investigating logs”, “unit testing”, “profiling”, and “analyzing dumps”. Visual studio
focuses on “interactive debugging”, which means “attaching to a running process with a
debugger, and investigating the program’s execution and state”.
Here are some features available in visual studios for debugging.
While in Break Mode – Navigate through code: when in break mode, it is possible to
you debug interactively and see the execution of codes. Some of the features of
navigation are,
“Continue (F5) will quit break mode and continue the program’s execution until the next
breakpoint is hit, entering break-mode again”.
“Step Over (F10) will execute the current line and break on the next line of code”
“Step Into (F11) is used when the next execution line is a method or a property. When
clicked, the debugger will step into the method’s code first line. By default, properties are
skipped. To enable stepping into property code, go to Tools | Options | Debugging and
uncheck Step over properties and operators”
“Run execution to here allows you to continue execution and break in a specified location
without a breakpoint. It’s like creating a breakpoint and removing it after first break. You
can do it in 3 ways,
Hover and click on the green arrow that appears on the start of each line and on the
desired line of code and click Ctrl + F10
Right click on the desired line of code and click on Set next statement
Run to a cursor location allows you to forcefully set the next line of code to execute.”
“The current (yellow) line will not be executed. It can be a line that was executed before
or after, but it’s best for the new line of code to stay in the current scope.
Investigate variables: When In break mode you can see the values of variables and class
members. Hovering over the variable lets you this via a pop-up, this is called “Data tip”.
DataTip and QuickWatch notable Features: this has useful features such as, “Pinning
DataTips – You can leave a DataTip pinned to the editor by clicking on the pin icon.
Useful when you hit the same breakpoint many times (maybe in a loop)”
Holding Ctrl will make the DataTip transparent by right clicking on an expression in
the DataTip, you can open a context menu with several options namely,
Copy – Copies to clipboard both Expression and Value
(alex={DebuggingPillars.Person})
Copy Expression – Copies expression (alex)
Copy Value – Copies expression ({DebuggingPillars.Person})
Edit Value – A useful feature where you can change the value during debugging.
Most useful for primitives (strings, integers, etc.)
Add Watch – Adds expression to Watch window (more on that later)
Add Parallel Watch – Adds expression to Parallel Watch window (more on that later)
Make Object ID – Creates a scope-independent expression that starts with ‘$’ ($1, $2,
and so on). You can evaluate this expression at any time, regardless of the current
scope, in Quick Watch, Watch Window or the Immediate Window. A very useful
feature and can be used to detect memory leaks.
Breakpoint advanced features: There are lesser-know features of breakpoint. To see the
context menu for it, you can right click a break. A few examples are given bellow,
Conditions allows you to break on this breakpoint only when a condition is met.
Actions allow you to log a message to the output window whenever the breakpoint is hit. You
can continue execution, without stopping on the breakpoint.
Edit labels… allows to categorize breakpoints into labels. This makes it easier later to
organize them in the breakpoints tool window.
Thanks to the features in Visual studios, it was easy to debug the application and make the
application a bug free secure application. As mentioned above, in the debugging process, the
most crucial part is “fault localization”. Using the “select Debug | Start Debugging”, I was
able to start debugging while running the application and find the errors in my application
and fix them. Here are a few instances as such,
Case 1
On the picture shown below, the variable ‘overnight’ is spelled in the coding but due the
debugger we could easily find the error of the codings.
In this case, the variable type for “nightpark” in the database was string and in the code was
double. I had to change the type in the database as float to fix the error after identifying it
Here hoursOnly variable was an double and maxhours was a int. Thanks to the error message,
I was able to identify it and fix it by converting hours only to int by using the code ‘int
totalhours = Convert.ToInt32(hoursOnly);’.
Here the variable rendate was not declared instead it was rendte. I was able to avoid the error
when the red line showed and was able to fix it. These are some of the many instances that I
used the debugging process to debug the application to develop more secure, robust
application.
Good Software Developers and development organizations maintain some well-defined and
standard style of coding called coding standards. Coding standards are made by organization/
programmer, depending on their needs, what suits their organization best and according to the
type of software developed. It is crucial to maintain coding standards because if coding
standards are not maintained, then the code maybe rejected during code review int the
organization.
Limited use of global – This is about which types of data that can be declared global
and the data that can’t be.
Standard headers for different modules – To understand and maintain the code in a
better way, the header of different modules should follow some standard format and
information. The header format must contain below things that is being used in
various companies,
Name of the module
Date of module creation
Author of the module
Modification history
Synopsis of the module about what the module does
Different functions supported in the module along with their input
output parameters
Indentation – To increase the code readability, proper indentation must be followed. Some
spacing/ indentation convections are,
A space must be left after giving a comma between two function arguments.
Each nested block should be properly indented and spaced
Proper Indentation should be there at the beginning and at the end of each block in the
program.
All braces should start from a new line and the code following the end of braces also
start from a new line.
Coding style – A code should understandable. If the code is too complex, debugging
is difficult. Using coding styles that is too difficult to understand must be avoided.
Do not using an identifier for multiple purposes - Descriptive and meaningful names
should be given for each variable that give the reason behind the name. If the same
variable name is used multiple times, it can lead to confusion and it would be difficult
to debug.
Document codes – The codes should be properly documented in a way that is easy to
understand. Comments regarding the statements increase the understandability of the
code. (techopedia, 2022)
As any programmer, I have used some coding standards to code my application. Some of
them are given below with examples,
Standard 1: Naming conventions –
The naming convections I have used in coding are,
For tools, I have named them in a way that it shows the page it belongs to as well as
the type of tool it is and every word has a capital letter in the first letter
(eg.waiting_charge_txt– this is the text box for Daily rates in rent packages page).
For local variable I’ve used names that are understandable and follow a pattern (eg.
drates – daily rates, wrates – weekly rates).
I have followed proper indentations and use of brackets for if else statements and others to
increase code readability and understandability.
I have made sure to place comments on all codes to give a clear idea on what the code is and
why it is used.
They increase the efficiency of the software and reduces the development time.
They help in identification of errors in an early stage.
They increase readability and understandability of a code while reducing the
complexity of the code.
It reduces the hidden cost for developing the software. (techopedia, 2022)
When developing programs, it is necessary to think about time, cost, debugging and future
updates of it. Having certain standards when coding helps in those criteria. As mentioned
above, coding standards increase the efficiency and reduces the development time of a
software while helping us identify errors on an early stage. These standards also make the
code more readable and understandable, especially for other developers who might do future
updates or debug the errors that were not found initially. By making it easier to read,
understand and debug, the cost is reduced which effects the company, group or individual in
a positive way. Therefore, as mentioned above, having certain coding standards help save
time, cost and make it easier to debug.