You are on page 1of 30

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing


Unit number and title Unit 1: Programming
Submission date 26/06/2022 Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Le Thanh Dat Student ID BH01028

Class SE06205 Assessor name Ngo Thi Mai Loan

Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature Dat
Grading grid

P1 M1 D1
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
TABLE OF CONTENT
A. Introduction............................................................................................................................................................1
B. Content.................................................................................................................................................................... 2
I. Algorithm..............................................................................................................................................................2
1. Definition.........................................................................................................................................................2
2. Algorithm characteristics................................................................................................................................3
3. Algorithm example...........................................................................................................................................4
II. Steps in program development...........................................................................................................................7
1.Requirement’s analysis:....................................................................................................................................7
2. Design:............................................................................................................................................................8
4. Documentation:...............................................................................................................................................9
5. Compiling and running the program:..............................................................................................................9
6. Testing:............................................................................................................................................................9
7.Maintenance:..................................................................................................................................................10
III. Solve problems using algorithms......................................................................................................................15
1. Content of the problem..................................................................................................................................15
2. Problem analysis...........................................................................................................................................15
3. Program menu...............................................................................................................................................15
4. Functional analysis........................................................................................................................................15
5. Functions.......................................................................................................................................................20
6. Program Execution........................................................................................................................................23
IV. Determine the steps taken from writing code to execution.............................................................................24
C. Conclusion.............................................................................................................................................................25
D. References............................................................................................................................................................26
TABLE OF FIGURE
Figure 1: Algorithm Definition.....................................................................................................................................2
Figure 2. Algorithm characteristics..............................................................................................................................3
Figure 3: Step 1 of cooking rice....................................................................................................................................4
Figure 4: Step 2 of cooking rice....................................................................................................................................4
Figure 5: Step 3 of cooking rice....................................................................................................................................5
Figure 6: Step 4 of cooking rice....................................................................................................................................5
Figure 7: Step 5 of cooking rice....................................................................................................................................6
Figure 8:Flowchart of the area of a rectangle..............................................................................................................6
Figure 9. Steps in program development.....................................................................................................................7
Figure 10: Software Development Models................................................................................................................11
Figure 11: Waterfall Model........................................................................................................................................11
Figure 12: V-Shaped Model.......................................................................................................................................12
Figure 13:Prototype Model.......................................................................................................................................12
Figure 14: Spiral Model..............................................................................................................................................13
Figure 15:Iterative Incremental Model......................................................................................................................13
Figure 16: Big Bang Model.........................................................................................................................................14
Figure 17: Agile Model...............................................................................................................................................14
Figure 18: Program menu..........................................................................................................................................15
Figure 19:Flowchart for solving linear equation........................................................................................................16
Figure 20:Flowchart solving quadratic equation.......................................................................................................18
Figure 21. Functions to solve first-order equations...................................................................................................20
Figure 22. Functions to solve quadratic equations....................................................................................................21
Figure 23. Menu structure function...........................................................................................................................22
Figure 24:The menu results are displayed on the screen..........................................................................................23
Figure 25. Option 1 results are displayed on the screen............................................................................................23
Figure 26. Option 2 results are displayed on the screen............................................................................................24
A. Introduction
In this world, everything operates by another thing. For example, universe operates the season, day and
night, … So, there is a sequence of some instructions to operate things. Let’s look at another side of it.

Since 1975, the digital revolution started. As a results of this digital revolution human began to use
information technology for make their works easier. So, they invented many technological equipments to
the modern world such as computers, smartphone… These technical equipments which are based on the
information technology are control by a code based program. In those smart devices, some code programs
are running in the device background. When we press a key or when we move the cursors likewise every
single simple task has code instructions to execute the tasks. Now you may wonder what is this coding
means.

Coding or programing is a method to instruct the computers to carry out the assigned tasks. So, a
computer program is a set of instructions that the computer executes.

All machines have their own language as our mother language. In machines, it is called machine language.
Machine language is consisted with only two states. They are 1 for on and 0 for off. Buth the thing is
human cannot understand this machine language. They want to build up a language which can understand
by both human and machines. As a result of this, humans invented the programming languages and
translator.

Programming languages are used to make computer programs in human language and translator are used
to convert those programs into machine language. This is how people build up computer programs to
make their daily work much easier.

So, we will go through some main aspects in programming subject with a small project in this assignment.

B. Content

I. Algorithm

1. Definition
Algorithm is an unambiguous specification step by step of how to solve a mathematical problem.
Algorithm is used to carry out calculation, data processing and automated reasoning tasks.
As an effective method, algorithm is a sequence of finite instructions used for completing a task. Starting
from an initial state and initial input (perhaps empty), the instructions proceed through a well-defined
series of successive states to get desired outputs from the given inputs, eventually terminating in an end-
state.  The transition from one state to the next is not necessarily determined in some algorithms known
as probabilistic algorithms, incorporate randomness.
It’s also a step-by-step method to making decisions or diagnosis.

Figure 1: Algorithm Definition

2. Algorithm characteristics
An algorithm has the following characteristics:

Figure 2. Algorithm characteristics

1. Finiteness: An algorithm must terminate after a limited number of steps.

2. Unambiguous: An algorithm must be precisely defined; each step should be clear and their inputs,
outputs must lead to only one meaning.

3. Input: An algorithm should have zero or more well-defined inputs which are given to it initially
before the algorithm begins.

4. Output: An algorithm should have one or more well-defined outputs and should match the desired
output.

5. Effectiveness: All of the operations to be executed in the algorithm should be realizable that they
can be done exactly in a limited length of time.
3. Algorithm example
Practical example: Cooking rice

a. Step 1: Measure the rice and put into cooking pot

Figure 3: Step 1 of cooking rice

b. Step 2: Rinse the rice

Figure 4: Step 2 of cooking rice


c. Step 3: Measure the water

Figure 5: Step 3 of cooking rice

d. Step 4: Cook the rice in the rice cooker

Figure 6: Step 4 of cooking rice


e. Step 5: Fluff and serve

Figure 7: Step 5 of cooking rice

Algorithm example in math: Find the area of a rectangle.

Figure 8:Flowchart of the area of a rectangle


II. Steps in program development
The various stages in the development of a computer program are :

1. Problem Definition
2. Program Design
3. Coding
4. Debugging
5. Testing
6. Documentation
7. Maintenance

Figure 9. Steps in program development

1.Requirement’s analysis:
In this first step, business analysts gathering information about the needs of the user(client) by interview
or meeting. Then the document called the user requirements is created. The user requirements document
describes all information of the application: the interface, data, security, system ‘s functional,
performance. The users will carefully review this document because it would serve as the guideline for the
system designers in the system design stage. The user acceptance tests are also designed in this step.

2. Design:
2.1. System design:

After analyze and understand the detailed requirements document, it is the time to design the complete
system. System engineers calculate possibilities and techniques that can be performed follow the user
requirements. If any of the requirements are inappropriate, the user is notified of the problem. Then the
resolution is suggested and the requirements document is edited after that. In this step, the application
specification document is generated for the development stage. It contains the general, menu structures,
data structures system organization. The system test plan is developed in this step, the earlier the system
test plan is prepared, the more time for unit testing executed later.

2.2. Architecture design (High level design):

Based on the technical and financial possibility software architects would realize the system design by
broken down it into modules taking up different functionality, brief functionality of each module, their
interface relationships, dependencies, database tables, architecture diagrams, technology details. The
integration tests would be designed in this stage.

2.3. Module design (Low level design):

In this step, the designed system is broken up into smaller modules with the very specification details so
the developers can start coding. The module design document will contain a detailed functional of the
modules:

+ All elements of the database tables.

+ All interface details with complete API references.

+All dependency issues

+Error message listings

+Complete input and outputs for a module.

It is very important that the module designed is appropriate with the other modules in the system
construction and the other external systems. The unit tests can be developed in this stage based on the
internal module designs.
3.Coding:

All of the module’s design is convert into code by the developers in this step. The most suitable
programming language is decided according to the system and architecture requirements. The coding is
implemented based on the coding guidelines and standards. The code is went through numerous code
reviews and finally optimized for the best performance. Unit testing is executed by the developers on the
code written by them.

4. Documentation:
-It’s very importance for developers to write technical documentation precisely. The code documents
which is a part of source code (include README files or API documentation) or includes reference
manuals, algorithm descriptions, flowcharts. Documentation is very helpful for development,
maintenance, and knowledge transfer to other developers. It must be detailed but not verbose. Because if
the documentation is lengthy, it would become very time-consuming to read or difficult to maintain them.

5. Compiling and running the program:


-When developers create a program, they first write the program in source code form which is written in a
specific programming language. Those code files in a text form that can be opened and edited by
developers. Because the source code can’t be performance directly by computers. So, it must be converted
from source code into machine code for computer can understand, this process is called “Compiling”.

-Execution in computer programs is the process in which a program is loaded into the computer’s memory
and then program ‘s instructions are executed. Most of the programs is executed with the support of an
operating system and specific run-time libraries.

6. Testing:
6.1. Unit Test Plans (UTPs) are developed in module design step would performance now. The unit tests
are a very necessary part of any application develop procedure and helps eliminate most of errors that can
generate at a very early phase.

A unit like a program module is the smallest entity in the whole system. Unit testing check that the
module can execute exactly when isolated from the rest of the units of system.

6.2. Integration testing:

Integration Test Plans are developed in the Architectural Design step. Integration Testing performed to
make sure that all of the modules created before which tested independently in UTPs can coexist and
communicate among themselves within the system. Then Test results are shared with the client ‘s team.

6.3. System testing:


System testing is strictly related with the system design stage. Unlike Unit and Integration Testing, System
Test Plans are constructed by client's team. System Test plan ensures that all of the client ’s expectations
are met. The entire application ’s system is tested for its functionality, interdependency and
communication. System Testing authenticates those functional and non-functional requirements are met.
Load and performance testing, stress testing, regression testing. Most of the problems about the
compatibility between hardware and software can be discovered during this step.

6.4. Acceptance testing:

User Acceptance Test (UAT) Plans are developed in the Requirements Analysis step. Test Plans are
constructed by the user. UAT is executed in user environment and using realistic data to find out the
incompatibility with the other systems. UAT confirms that complete system meets all the requirement of
user and ready for use in actual time. It also detects the non-functional errors such as load and
performance defects in the real time user environment.

* Debugging: is a process of detecting and fixing the problems that prevent the program operating
correctly. Developers can use debugging tools to check and correct errors in the program. In case of large
program, the source code is divided into many small components which are debugged separated. Next
stage is the whole program.

7.Maintenance:
In computer programming, the concept of maintenance is referred to modify a software product after
deployment step to correct errors, improve performance and attributes. But in reality, maintenance is more
similar to enhance functionality of the system or fixing faults. Its purpose is to meet the changing with
new technologies and requirements.

Software Development Models

Figure 10: Software Development Models


Software Development Life Cycle Model is a formal and clear description which is represented the
software development life cycle. There are eight models.

Waterfall Model

Figure 11: Waterfall Model

V-Shaped Model
Figure 12: V-Shaped Model

Prototype Model

Figure 13:Prototype Model

Spiral Model

Figure 14: Spiral Model


Iterative Incremental Model

Figure 15:Iterative Incremental Model

Big Bang Model

Figure 16: Big Bang Model

Agile Model
Figure 17: Agile Model

III. Solve problems using algorithms

1. Content of the problem


I have made a program that allows the user to select the appropriate programs from the menu as follows:

Press key 1: Solve the linear equation.

Press key 2: Solve the quadratic equation.

Press key 3: Exit.

2. Problem analysis
1. Menu options:
 Press 1: Solve a linear equation
 Press 2: Solve a quadratic equation
 Press 3: Exit
2. Task analysis:
 Press 1: The program should prompt the user to enter the coefficients of a linear equation (e.g., ax
+ b = 0) and solve it
 Press 2: The program should prompt the user to enter the coefficients of a quadratic equation (e.g.,
ax^2 + b + c = 0) and solve it
 Press 3: The program should be terminate and exit

3. Program menu

Figure 18: Program menu


This is a menu of the program with 3 main functions that require user to choose 1 of the 3 above functions
to use.

4. Functional analysis
The program menu is divided into 3 main functions:

Press key 1: Solve the first order equation.

Press key 2: Solve quadratic equation.

Press key 3: Exit.

Press key 1: Solve the linear equation

The Solve Linear Equation function solves a linear equation of the form "ax + b = 0". It prompts the user
to enter the values of coefficients 'a' and 'b', and then calculates the solution 'x' that satisfies the equation.
The function handles different scenarios, including cases where 'a' is zero or 'b' is zero
Figure 19:Flowchart for solving linear equation

 Inputs:

- Coefficient 'a': The user is prompted to enter the value of coefficient 'a' in the linear equation.

- Coefficient 'b': The user is prompted to enter the value of coefficient 'b' in the linear equation

 Outputs:

- Solution 'x': The function calculates the value of 'x' that satisfies the linear equation.

 Steps:
1. Display a prompt to the user, asking them to enter the value of coefficient 'a' in the linear equation.
2. Read the value of coefficient 'a' from the user.
3. Display a prompt to the user, asking them to enter the value of coefficient 'b' in the linear
equation.
4. Read the value of coefficient 'b' from the user.
 Check if 'a' is equal to zero: If 'a' is zero, check if 'b' is also zero: - If 'b' is zero, display a message
indicating that the equation has infinitely many solutions.
 If 'b' is not zero, display a message indicating that the equation has no solution. –
 If 'a' is not zero, calculate the solution 'x' using the formula: x = -b / a.

5. Display the solution 'x' to the user.

Press key 2: Solve quadratic equation.

The Solve Quadratic Equation function solves a quadratic equation of the form "ax^2 + bx + c = 0". It
prompts the user to enter the values of coefficients 'a', 'b', and 'c', and then calculates the solutions 'x1' and
'x2' that satisfy the equation. The function handles different scenarios based on the discriminant value (b^2
- 4ac) to determine the nature of the solutions (real, complex, or no real solutions).
Figure 20:Flowchart solving quadratic equation

 Inputs:

- Coefficient 'a': The user is prompted to enter the value of coefficient 'a' in the quadratic equation.

- Coefficient 'b': The user is prompted to enter the value of coefficient 'b' in the quadratic equation.

- Coefficient 'c': The user is prompted to enter the value of coefficient 'c' in the quadratic equation.

 Outputs:

- Solutions 'x1' and 'x2': The function calculates the values of 'x1' and 'x2' that satisfy the quadratic
equation.

 Steps:
1. Display a prompt to the user, asking them to enter the value of coefficient 'a' in the quadratic
equation.
2. Read the value of coefficient 'a' from the user.
3. Display a prompt to the user, asking them to enter the value of coefficient 'b' in the quadratic
equation.
4. Read the value of coefficient 'b' from the user.
5. Display a prompt to the user, asking them to enter the value of coefficient 'c' in the quadratic
equation.
6. Read the value of coefficient 'c' from the user.
7. Calculate the discriminant value using the formula: discriminant = b^2 - 4ac.
8. Check the value of the discriminant:

- If the discriminant is negative, display a message indicating that the equation has no real solutions.

- If the discriminant is zero, calculate the solution 'x' using the formula: x = -b / (2a), and display the
solution to the user.

- If the discriminant is positive, calculate the solutions 'x1' and 'x2' using the formulas: x1 = (-b +
sqrt(discriminant)) / (2a) and x2 = (-b - sqrt(discriminant)) / (2a), and display the solutions to the user.

9. Display the solutions 'x1' and 'x2' to the user.

Press key 3: Exit.

The third function of the menu is exit, the following is the flowchart of the program:

When we enter the key 1, the program will solve the first-order equation, enter the key 2, the program will
solve the quadratic equation, enter the key 3, the program will end and automatically exit.

If you enter 1 correctly  the program will solve the first order equation.

If it is wrong, it will switch to key 2  if it is true, the program will solve the quadratic equation.

If later, it will switch to key 3, if it is correct, the program will automatically exit, if it is wrong, it will
automatically print on the screen the words "The option does not exist, please re-enter the value from 1 -
3. "

5. Functions
The first function : Solve Linear Equation
Figure 21. Functions to solve first-order equations
1. The function starts by displaying a message to the user indicating that it will solve a linear
equation of the form "ax + b = 0".
2. The user is prompted to enter the value of coefficient 'a'. The value is then read from the console
and stored in the variable 'a'.
3. The user is prompted to enter the value of coefficient 'b'. The value is read from the console and
stored in the variable 'b'.
4. The function checks if 'a' is equal to zero.
5. If 'a' is zero, it further checks if 'b' is also zero. If both 'a' and 'b' are zero, it means the equation has
infinitely many solutions. In this case, the function displays a message indicating that.
6. If 'a' is zero but 'b' is not zero, it means the equation has no solution. The function displays a
message indicating that.
7. If 'a' is not zero, the function proceeds to calculate the solution 'x' using the formula: x = -b / a.
8. Finally, the function displays the solution 'x' to the user.

The second function : Solve Quadratic Equations.


Figure 22. Functions to solve quadratic equations
1. Main method:

- The Main method is the entry point of the program. It calls the SolveQuadraticEquation function to solve
the quadratic equation.

2. SolveQuadraticEquation method:

- This method solves a quadratic equation of the form 'ax^2 + bx + c = 0'. - It prompts the user to enter the
coefficients 'a', 'b', and 'c'.

- The coefficients are stored in variables 'a', 'b', and 'c' using double.Parse to convert the user input into
double values.

3. Discriminant calculation:

- The discriminant of the quadratic equation is calculated using the formula: b^2 - 4ac

4. Handling different cases based on the discriminant:

- If the discriminant is less than 0, it means the equation has no real solutions. The program displays a
message indicating that.

- If the discriminant is equal to 0, it means the equation has one real solution. The program calculates the
solution using the formula: x = -b / (2a) and displays it.
- If the discriminant is greater than 0, it means the equation has two real solutions. The program calculates
both solutions using the formulas: x1 = (-b + sqrt(discriminant)) / (2a) and x2 = (-b - sqrt(discriminant)) /
(2a), and displays them.

5. Math.Sqrt:

- Math.Sqrt is used to calculate the square root of the discriminant.

The third functions : Exit.

Figure 23. Menu structure function


If we want to exit the program, you must press Key 3. But if you press any key except key number 3 it will invalid

6. Program Execution
When the program is executed, the Program Menu will be displayed as follows:
Figure 24:The menu results are displayed on the screen
It is can be choose 3 options, let’s try first option:

Figure 25. Option 1 results are displayed on the screen

Input coefficient a and b and it will show the result

With Option 2 we will do the same.

Enter any 3 numbers a, b, c and the program will be launched and solve the quadratic equation.
With Option 3, when we enter the key num 3. The program will stop and exit to the main screen
immediately.

IV. Determine the steps taken from writing code to execution.


1. Analyze the problem: You need to define the problem.

2. Design a solution: Find the algorithms to solve the problem.

3. Write Pseudocode: Pseudocode is not executed on computer but it is more convenient for developer to
developing algorithms. A good Pseudocode may be easily converted to programming language.

4. Draw a flow chart: Like Pseudocode, a flow chart represents the order of an algorithm will be written.
Like previous example:

5. Write code: Write your solution for the problem in a programming language.

6. Test and debug: Using an IDE (Integrated Development Environment) to run your code. It also helps to
check errors in your code.

C. Conclusion
In this aassignment, I define basic algorithms to carry out an operation and outline the process of
programming an application The first step is to research and analyze the requirements. By clearly
understanding user requirements and program goals, we can determine the scope and functionality
required.

Programming requires logical thinking, problem-solving skills, and attention to detail. It involves
understanding the problem, designing a solution, implementing it using programming constructs, and
testing and debugging the code to ensure its correctness. Collaboration and continuous learning are also
important aspects of programming, as developers often work in teams and need to stay updated with the
latest technologies and practices.
D. References

Wikipedia Contributors (2019). Object-oriented programming. [online] Wikipedia. Available at:


https://en.wikipedia.org/wiki/Object-oriented_programming.

Prabhu, R. (2019). Introduction to Algorithms. [online] GeeksforGeeks. Available at:


https://www.geeksforgeeks.org/introduction-to-algorithms/.

What Is SDLC (Software Development Life Cycle) Phases & Process (2023). Available at:
https://www.softwaretestinghelp.com/software-development-life-cycle-%20sdlc/.

QArea Blog. (2018). 7 Stages of Software Development Cycle. [online] Available at:
https://qarea.com/blog/7-stages-software-development-cycle [Accessed 11 Jun. 2018]

characteristics, A., characteristics, A., work?, H., Prevention, M., DBAs, H. and Oracle, C.
(2018). Algorithm and its characteristics. [online] Biyani Institute of Science and Management
for Girls. Available athttp://bisma.in/algorithm-and-its-characteristics/[Accessed 11 Jun. 2018].

30

You might also like