7388 Se06201 BD00338 Asm1 Huynhtanbinh

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

BTEC FPT INTERNATIONAL COLLEGE

INFORMATION TECHNOLOGY
ASSIGNMENT 1
UNIT: PROGRAMMING

STUDENT : HUYNH TAN BINH


CLASS : SE06201
STUDENT ID : BD00338
SUPERVISOR : NGUYEN HOANG ANH VU

Da Nang, June 2023


ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit: Programming

Date received (1st sub-


Submission date 12/06/2023 19/06/2023
mission)

Date received (2nd


Re-submission date
submission)

Student name Huynh Tan Binh Student ID BD00338

Class SE06201 Assessor name Nguyen Hoang Anh Vu

Student declaration

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

Student’s signature:

Tan Binh

Grading grid

P1 M1 D1
Summative Feedbacks: Resubmission Feedbacks:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

Signature & Date:

i
TABLE OF CONTENT

TABLE OF CONTENT.............................................................................................. ii

LIST OF TABLES AND FIGURES .......................................................................... iv

LIST OF ACRONYM................................................................................................ vi

INTRODUCTION ...................................................................................................... 1

CHAPTER 1 DEFINE BASIC ALGORITHMS TO CARRY OUT AN


OPERATION AND OUTLINE THE PROCESS OF PROGRAMING AN APPLICATION.(LO1)
2

1. Provide a definition of what an algorithm is and outline the process in building


an application (P1) ........................................................................................................... 2

1.1 Definition of algorithm ................................................................................... 2

1.1.1 Example of algorithm .............................................................................. 2

1.2 Ways to demonstrate algorithms .................................................................. 5

1.2.1 Using pseudocode .................................................................................. 5

1.2.2 Using flowchart ....................................................................................... 6

1.3 Characteristic of Algorithms .......................................................................... 9

1.3.1 Algorithm Advantages: ......................................................................... 10

1.3.2 Algorithm disadvantages: ..................................................................... 11

1.3.3 Step to write a good algorithm: ............................................................. 11

1.4 Steps in program development ................................................................... 13

2. Determine the steps taken from writing code to execute. (M1) ....................... 20

2.1 Step 1: Determine the content of the problem ............................................... 20

2.2 Step 2: Draw a functional diagram of the program ........................................ 20

2.3 Step 3: Code the program ............................................................................. 21

2.4 Step 4: Debug the code ................................................................................. 24

2.5 Step 5: Run the program ............................................................................... 25

ii
CONCLUSION ........................................................................................................ 27

REFERENCES ....................................................................................................... 28

iii
LIST OF TABLES AND FIGURES

Figure: 1- 1 Algorithm ............................................................................................... 2

Figure: 1- 2 Boil water ............................................................................................... 3

Figure: 1- 3 Prepare cup and tea .............................................................................. 3

Figure: 1- 4 Place tea bag in the teacup ................................................................... 3

Figure: 1- 5 Add sugar .............................................................................................. 4

Figure: 1- 6 Remove the tea bag .............................................................................. 4

Figure: 1- 7 Enjoy cup of tea ..................................................................................... 5

Figure: 1- 8 Pseudocode........................................................................................... 5

Figure: 1- 9 Flowchart Symbol .................................................................................. 7

Figure: 1- 10 Example............................................................................................... 7

Figure: 1- 11 Example............................................................................................... 8

Figure: 1- 12 Characteristics of algorithm ............................................................... 10

Figure: 1- 13 The software development cycle ....................................................... 14

Figure: 1- 14 Visual studio ...................................................................................... 15

Figure: 1- 15 Flowchart of quadratic equation ......................................................... 16

Figure: 1- 16 Code the program .............................................................................. 16

Figure: 1- 17 Code the program .............................................................................. 17

Figure: 1- 18 Code the program .............................................................................. 17

Figure: 1- 19 Error list ............................................................................................. 17

Figure: 1- 20 Code before fixing bug....................................................................... 18

Figure: 1- 21 Code after fixing bug ......................................................................... 18

Figure: 1- 22 Code before and after fixing bugs ...................................................... 18

Figure: 1- 23 No error ............................................................................................ 18

Figure: 1- 24 Results............................................................................................... 19

Figure: 1- 25 Results............................................................................................... 19
iv
Figure: 1- 26 Results

Figure:2- 1 Flowchart .............................................................................................. 20

Figure:2- 2 Code the program ................................................................................. 21

Figure:2- 3 Code the program ................................................................................. 21

Figure:2- 4 Code the program ................................................................................. 22

Figure:2- 5 Code the program ................................................................................. 22

Figure:2- 6 Code the program ................................................................................. 22

Figure:2- 7 Code the program ................................................................................. 23

Figure:2- 8 Error list ................................................................................................ 24

Figure:2- 9 Code before fixing bug ......................................................................... 24

Figure:2- 10 Code after fixing bug .......................................................................... 24

Figure:2- 11 Code before fixing bug........................................................................ 24

Figure:2- 12 Code after fixing bug .......................................................................... 24

Figure:2- 13 No error .............................................................................................. 25

Figure:2- 14 Result ................................................................................................. 25

Figure:2- 15 Result ................................................................................................. 25

Figure:2- 16 Result ................................................................................................. 26

................................................................................................................................ 19

v
LIST OF ACRONYM

IT Information Technology

vi
INTRODUCTION

Programming plays an extremely important role in life. Coming to this report, we will
learn about algorithms, problems related to algorithms and basic programming. It will help
us understand more deeply what is an algorithm, how is an algorithm defined? What is the
process of building an algorithm, and how does the algorithm work? Let's find out in this
assignment!

❖ This report includes the following:


Chapter 1: Define basic algorithms to carry out an operation and outline the process
of programming an application(LO1)
1. Provide a definition of what an algorithm is and outline the process in building
an application (P1)
2. Determine the steps taken from writing code to execute. (M1)
3. Examine the implementation of an algorithm in a suitable language. Evaluate
the relationship between the written algorithm and the code variant.( D1)

Perfomed Student: HUYNH TAN BINH 1


CHAPTER 1 DEFINE BASIC ALGORITHMS TO CARRY OUT AN OPERA-
TION AND OUTLINE THE PROCESS OF PROGRAMING AN APPLICA-
TION.(LO1)

1. Provide a definition of what an algorithm is and outline the process in


building an application (P1)

1.1 Definition of algorithm

A well-defined and precise set of step-by-step instructions or rules designed to solve


a given problem or achieve a certain activity is referred to as an algorithm. It is a methodical
technique that specifies the steps to take in order to accomplish a specific result.

Algorithms are used in many different domains, including mathematics, computer sci-
ence, engineering, and everyday life. They serve as a blueprint for issue resolution and can
be applied in a variety of methods, including computer languages, pseudocode, flowcharts,
and even in human-readable form.

Figure: 1- 1 Algorithm
1.1.1 Example of algorithm

❖ Algorithm for making tea

Step 1: Boil water in a kettle or a pot

Perfomed Student: HUYNH TAN BINH 2


Figure: 1- 2 Boil water
Step 2: While the water is boiling, gather a teacup, a tea bag, and any additional
ingredients like sugar or milk

Figure: 1- 3 Prepare cup and tea


Step 3: Place the tea bag in the teacup

Figure: 1- 4 Place tea bag in the teacup


Step 4: Once the water has boiled, pour it into the teacup over the tea bag

Perfomed Student: HUYNH TAN BINH 3


Step 5: Let the tea steep for the recommended time ( 2-5 minutes ) to to extract the
flavors

Step 6: While the tea is steeping, add sugar or milk to taste, if desired

Figure: 1- 5 Add sugar


Step 7: After the steeping time, remove the bag from the cup and discard it

Figure: 1- 6 Remove the tea bag


Step 8: Stir the tea gently to mix in any added ingredients

Step 9: Allow the tea to cool down for a few moments before drinking, if necessary

Step 10: Enjoy your cup of tea

Perfomed Student: HUYNH TAN BINH 4


Figure: 1- 7 Enjoy cup of tea

1.2 Ways to demonstrate algorithms

1.2.1 Using pseudocode

Pseudocode is a high-level, informal description of a computer program or algorithm


that combines normal language with programming-like structures. It is not intended to be
run on a computer, but rather to sketch and express the logic of a program or algorithm in a
human-readable format.

Pseudocode bridges the gap between plain language and actual computer code,
allowing programmers to convey their thoughts and intents before delving into a
programming language's unique syntax. It provides a step-by-step exposition of the
algorithm's logic, making the overall structure and flow of the program easier to understand
and evaluate.

Figure: 1- 8 Pseudocode

Perfomed Student: HUYNH TAN BINH 5


❖ Example of pseudocode for a simple program that that checks if a number is posi-
tive, negative, or zero
- Start the program
- Prompt the user to enter a numner
- Read the input number and store it in a variable called ‘num’
- If ‘num’ is greater than 0, do the following: print “‘num’ is a negative number.”
- Otherwise, if ‘num’ is less than 0, do the following: Print “’num’ is a negative
number.”
- Otherwise, do the following: Print “’num’ is zero.”
- End the program.

1.2.2 Using flowchart

A flowchart is a graphical depiction of a process or algorithm that depicts the se-


quence of steps, decisions, and actions inside the process using various symbols and ar-
rows. It provides a visual depiction of a program's or process's logical flow, making it easier
to understand and analyze. Flowcharts employ various shapes to depict various parts of a
process.

1.2.2.1 Flowchart symbols that are regularly used include:

• Oval or rounded retangle: Denotes the beginning or end of a process.


• Rectangle: Represents a process phase or action
• Diamond: A decision or branching point where a condition is examnined is
represented by a diamond
• Arrows: Show the sequence of phases by indicating the flow or direction of the
process

Flowcharts aid in visualizing a program's or process's control flow and logic, making
it easier to discover potential bottlenecks, inefficiencies, or places for improvement. They
are often used in software development, process engineering, and problem-solving tasks to
clearly describe and communicate complicated processes.

Flowcharts help individuals comprehend the structure and flow of a program or pro-
cess by providing a visual depiction, assisting in the development, analysis, and document-
ing of various systems and procedures.

Perfomed Student: HUYNH TAN BINH 6


Figure: 1- 9 Flowchart Symbol
Example 1: Flowchart represents a simple decision-making process

Figure: 1- 10 Example

Perfomed Student: HUYNH TAN BINH 7


❖ Explanation:

This flowchart represents a simple decision-making process. Here's the explanation


of the symbols and steps in the flowchart:

• Start: This is the starting point of the process.


• Gather Information: The process begins by gathering relevant information.
• Is Information Complete?: This step checks whether the gathered information
is complete or not.
• Information Incomplete: If the information is incomplete, the process proceeds
to request more information.
• Request More Information: Additional information is requested to complete the
decision-making process.
• Information Complete: If the information is complete, the process moves on to
making a decision.
• Make a Decision: Based on the complete information, a decision is made.
• End: This is the end point of the process.
Example 2: Flowchart represents a simple ordering process

Figure: 1- 11 Example
Perfomed Student: HUYNH TAN BINH 8
❖ Explanation:

This flowchart represents a simple ordering process. Here's the explanation of the
symbols and steps in the flowchart:

• Start: This is the starting point of the process.


• Receive Order: The process begins by receiving an order from a customer.
• Check Inventory: Inventory is checked to determine if the ordered item is in
stock.
• Out of Stock: If the item is out of stock, the process moves to notify the customer
about the unavailability.
• Notify Customer: The customer is informed that the item is currently out of stock.
• In Stock: If the item is in stock, the process proceeds to prepare the shipment.
• Prepare Shipment: The ordered item is prepared for shipment to the customer.
• End: This is the end point of the process.

1.3 Characteristic of Algorithms

Algorithms have various distinguishing qualities that define their nature and function-
ality. Here are some significant algorithm characteristics:

Well-defined inputs and outputs: Algorithms have well-defined input requirements


and outputs. They process certain input data to produce the required output.

Precise and unambiguous: Algorithms are written with explicit, step-by-step instruc-
tions that eliminate ambiguity and multiple interpretations. Each step must be carefully de-
fined in order for predictable execution to occur.

Finiteness: Algorithms have a clear beginning and end point. They are made up of
a finite number of steps that culminate in the intended result.

Definiteness: Each step of an algorithm must be properly described and unambigu-


ous, indicating the specific operation to be performed.

Effectiveness: Algorithms are supposed to be efficient and to solve problems. They


must produce the desired result in a reasonable amount of time and resources.

Determinism: Algorithms are deterministic in the sense that they always produce the
same output given the same input. There is no chance or variation in their execution.

Perfomed Student: HUYNH TAN BINH 9


Modularity: Algorithms can be broken down into smaller, more manageable modules
or subroutines, making them easier to comprehend, implement, and maintain. This also en-
courages code repetition and increases readability.

Time and space efficiency: Algorithms are designed to be time and space efficient.
They aim to do the assignment with the fewest resources possible.

Correctness: For all legitimate inputs, algorithms must generate the proper output.
They must solve the problem as planned while also dealing with all possible edge cases and
exceptions

.
Figure: 1- 12 Characteristics of algorithm
1.3.1 Algorithm Advantages:

❖ Efficiency: Algorithms enable the development of efficient solutions by providing a


systematic approach to issue solving. They concentrate on reducing time and space
complexity, which results in speedier execution and better resource use.
❖ Reproducibility: Algorithms are deterministic, which means they always produce the
same output when given the same input. This feature ensures dependability and pre-
dictability by allowing for consistent and reproducible outputs.
❖ Clarity and Understanding: Algorithms provide an organized and straightforward
manner to depict complex processes or problem-solving procedures. They give a
step-by-step depiction that increases developer knowledge, communication, and co-
operation.
❖ Modularity and reusability: Algorithms can be modular and reusable. Once con-
ceived and implemented, an algorithm can be utilized in numerous settings or inte-
grated into different programs, encouraging code reuse and eliminating redundant
development efforts.

Perfomed Student: HUYNH TAN BINH 10


❖ Scalability: Well-designed algorithms can handle larger data sets or more difficult
issues successfully. Algorithms can manage increasing demands without sacrificing
performance by enhancing efficiency and resource consumption.

1.3.2 Algorithm disadvantages:

❖ Complexity: Creating sophisticated algorithms can be difficult and time-consuming.


Advanced knowledge of algorithmic techniques and computational thinking may be
required for designing efficient algorithms for difficult tasks.
❖ Limitations: Algorithms are only as good as the assumptions and design that under-
pin them. They may have constraints or limitations in terms of the types of problems
they can tackle. Certain challenges may necessitate the use of specific algorithms or
techniques.
❖ Input Sensitivity: Some algorithms may be sensitive to the quality or features of the
input data. Small changes in input values or data distributions can have a big impact
on an algorithm's performance or output.
❖ Resource Constraints: While algorithms strive towards efficiency, some situations
may have intrinsic computational complexity that cannot be eliminated fully. Certain
algorithms may necessitate substantial computing resources, such as memory or
processor power, which can be a constraint in resource-constrained contexts.
❖ Upkeep and adaptability: As requirements change or new scenarios emerge, algo-
rithms may require updates or alterations. Maintaining and adapting sophisticated
algorithms can be difficult, especially when there are several dependencies or inter-
actions.

1.3.3 Step to write a good algorithm:

❖ Recognize the issue: Acquire a thorough understanding of the issue at hand. De-
termine the input, desired output, limitations, and any special needs or edge situa-
tions.
❖ Break it down as follows: Break the problem down into smaller, more manageable
tasks or subproblems. Determine the major stages required to solve the problem and
consider the algorithm's logical flow.
❖ Select the best algorithmic approach: Based on the problem requirements and
restrictions, choose the best algorithmic technique. Consider issues such as time
complexity, space complexity, and problem domain suitability.

Perfomed Student: HUYNH TAN BINH 11


❖ Plan the algorithm: Outline the steps required to solve the problem in order to plan
the algorithm. To represent the logic and structure of the algorithm, use pseudocode
or a flowchart.
❖ Consider efficiency: Aim for efficiency by optimizing the time and space complexity
of the algorithm. Analyze the performance of the algorithm and make any necessary
tweaks or improvements.
❖ Test and validate: To confirm the algorithm's correctness and robustness, run it
through several test cases, including edge cases and boundary conditions. Check
that the algorithm returns the anticipated result for all valid inputs.
❖ Iterate and refine: As needed, review and refine the algorithm. To make improve-
ments and increase the algorithm's effectiveness, consider feedback, performance
data, and probable edge cases.
Example of an algorithm that calculates the sum of two numbers:
- Start
- Prompt the user to enter the first number and store it in 'num1'
- Prompt the user to enter the second number and store it in 'num2'
- Add 'num1' and 'num2' together and store the result in 'sum'
- Print 'sum' as the output
- Stop

Figure: 1- 13 Example of an algorithm that calculates the sum of two numbers


Perfomed Student: HUYNH TAN BINH 12
Figure: 1- 14 Flowchart of an algorithm that calculates the sum of two numbers
1.4 Steps in program development

To produce a software program, numerous critical processes are involved in the pro-
gram development process. The following are the typical steps:

❖ Problem Analysis: Understand the problem domain and program requirements.


Determine the goals, restrictions, and intended functionalities.
❖ Preparation: Make a strategy for the program development process. Define the
program's scope, goals, and overall structure. Establish your resources, schedules,
and milestones.
❖ Algorithm Design: Create an algorithmic solution to the problem. Divide the

Perfomed Student: HUYNH TAN BINH 13


problem into smaller jobs and design the program's logic and flow. Take into account
data structures, control flow, and any relevant algorithms.
❖ Coding: Write the code in accordance with the algorithm. Use a programming lan-
guage to implement the logic and functionalities. For readability and maintainability,
adhere to coding standards, naming conventions, and documentation techniques.
❖ Testing and debugging: Test and debug the program to ensure it works as
planned. Check that the code fits the requirements and achieves the expected re-
sults. Unit tests, integration tests, and system tests are all performed.
❖ Documentation: Describe the program's goal, functionality, and usage instructions.
Include comments throughout the code to clarify tricky portions and increase code
comprehension. As needed, create user manuals, technical guides, or API docu-
mentation.
❖ Deployment: Get the program ready for deployment. Package the code and any
dependencies that are required. Take into account platform compatibility and instal-
lation methods. Deploy the software to the target environment or make it available
to end users
❖ Maintenance: Keep an eye on the application in action and address any difficulties
or errors that develop. Make any necessary upgrades, enhancements, or bug fixes.
Keep documentation and track of changes.
❖ Continuous optimization: Continuously improve the program's performance, effi-
ciency, and scalability. Identify bottlenecks or opportunities for improvement and
apply improvements to increase the program's capabilities.
❖ Iteration and Enhancement: Gather feedback from users and stakeholders to
identify program enhancement opportunities. Based on feedback and growing re-
quirements, plan and implement updates and new features.

Figure: 1- 15 The software development cycle

Perfomed Student: HUYNH TAN BINH 14


Example of steps in program development: Solve quadratic equations

Step 1: Identify the issues

The task at hand is to write a program that solves quadratic equations.

Step 2: Planning

I program in C# using the Microsoft Visual Studio IDE.

Figure: 1- 16 Visual studio


Step 3: Analysis

Examine the issue. The computer user must first identify the problem, then decide
how to address it - selecting a program. In this example, we must solve quadratic equations
using the keyboard inputs a, b, and c. Solve simple equations if a==0.

Otherwise (a! =0), compute the equation's delta. The equation has no solution if delta
is 0. The equation has a double solution if delta == 0. If delta is greater than zero, the equa-
tion has two unique solutions.

Step 4: Design the program.

A flowchart is essential. This is a visual representation of the program's flow. This


phase will assist you in breaking down the problem.

Perfomed Student: HUYNH TAN BINH 15


Figure: 1- 17 Flowchart of quadratic equation
Step 5: Code the program

Figure: 1- 18 Code the program


Perfomed Student: HUYNH TAN BINH 16
Figure: 1- 19 Code the program

Figure: 1- 20 Code the program


Step 6: Debug the code

If any issues are discovered during testing, the code must be debugged to rectify
them. The IDE Microsoft Visual Studio in this software indicates that there are certain mis-
takes in the code of my program. As a result, I must identify and resolve the following issues:

Figure: 1- 21 Error list


The first issue is a syntactic error; I left out a ";" at the end of the 59th line.

Perfomed Student: HUYNH TAN BINH 17


Figure: 1- 22 Code before fixing bug

Figure: 1- 23 Code after fixing bug


The second is that on the 38rd line, I misspelled "Maht" instead of "Math."

Figure: 1- 24 Code before fixing bug

Figure: 1- 25 Code after fixing bug


We can see that there is no problem on the screen after we have fixed all faults. The
program is finished.

Figure: 1- 26 No error

Testing is the sixth step.

To guarantee that the code gives the right output for a variety of quadratic equations,
it should be tested with various input values.

Perfomed Student: HUYNH TAN BINH 18


Figure: 1- 27 -Results

Figure: 1- 28 Results

Figure: 1- 29 Results

Perfomed Student: HUYNH TAN BINH 19


2. Determine the steps taken from writing code to execute. (M1)

2.1 Step 1: Determine the content of the problem

The problem requires building a user account management program in C#. This pro-
gram allows users to create accounts, log in and display account information.

2.2 Step 2: Draw a functional diagram of the program

Figure:2- 1 Flowchart

Perfomed Student: HUYNH TAN BINH 20


2.3 Step 3: Code the program

Figure:2- 2 Code the program

Figure:2- 3 Code the program

Perfomed Student: HUYNH TAN BINH 21


Figure:2- 4 Code the program

Figure:2- 5 Code the program

Figure:2- 6 Code the program


Perfomed Student: HUYNH TAN BINH 22
Figure:2- 7 Code the program
The program starts with the Main method, where we use a while loop to display the
menu and process the user's selection. This loop will continue until the user selects option
"4" to exit the program.

The CreateAccount method is used to create user accounts. It asks the user for a
username and password and then creates a new UserAccount object with this information.
The UserAccount object is added to the accounts list to store account information.

The Login method is used to log into the account. User is required to enter username
and password. The program then searches the list of accounts to see if there are any ac-
counts that match the login information. If found, the program announces successful login
and displays the username. If it is not found, the program reports that the login failed.

The DisplayAccountInfo method is used to display the account information. The user
is asked to enter the username of the account to be displayed. The program then searches
the list of accounts to see if there are any accounts with the corresponding username. If
found, the program displays account information, including username and password. If not
found, the program says that the account cannot be found.

The UserAccount class represents a user account. It has two properties Username
and Password to store information respectively.

Perfomed Student: HUYNH TAN BINH 23


2.4 Step 4: Debug the code

If any issues are discovered during testing, the code must be debugged to rectify them.
The IDE Microsoft Visual Studio in this software indicates that there are certain mistakes in
the code of my program. As a result, I must identify and resolve the following issues:

Figure:2- 8 Error list


The first issue is a syntactic error; I left out a ";" at the end of the 46th line

Figure:2- 9 Code before fixing bug

Figure:2- 10 Code after fixing bug

The second is that on the 39rd line, I misspelled "WriteLien" instead of "WriteLine."

Figure:2- 11 Code before fixing bug

Figure:2- 12 Code after fixing bug


We can see that there is no problem on the screen after we have fixed all faults. The
program is finished.

Perfomed Student: HUYNH TAN BINH 24


Figure:2- 13 No error
2.5 Step 5: Run the program

To ensure that the code provides the right output for a variety of information, the code
needs to be tested with different input values.

Figure:2- 14 Result

Figure:2- 15 Result

Perfomed Student: HUYNH TAN BINH 25


Figure:2- 16 Result

Perfomed Student: HUYNH TAN BINH 26


CONCLUSION

After completing this report, I understood and grasped how to build a basic algorithm,
the process to execute a program, the life cycle of an algorithm, how to draw a flow chart
to explain How does the algorithm work?

Programming is really amazing! thanks to it I understand how the devices around us


work.

This is very interesting and fantastic. Thankyou my Mentor!

Perfomed Student: HUYNH TAN BINH 27


CRITICAL EVALUATION

Perfomed Student: HUYNH TAN BINH 28


REFERENCES

https://www.techtarget.com/whatis/definition/algorithm

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

https://www.techtarget.com/searchsoftwarequality/definition/systems-de-
velopment-life-cycle

Perfomed Student: HUYNH TAN BINH 29

You might also like