0% found this document useful (0 votes)
34 views55 pages

ASM1 Progaming

Uploaded by

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

ASM1 Progaming

Uploaded by

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

ASSIGNMENT FINAL REPORT

Qualification Pearson BTEC Level 5 Higher National Diploma in Computing

Unit number and title Unit 1: Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Pham Chien Thang Student ID BH01999

Class SE07103 Assessor name Nguyen Thi Hong Hanh

Plagiarism
Plagiarism is a particular form of cheating. Plagiarism must be avoided at all costs and students who break the rules, however innocently, may be
penalised. It is your responsibility to ensure that you understand correct referencing practices. As a university level student, you are expected to use
appropriate references throughout and keep carefully detailed notes of all your sources of materials for material you have used in your work,
including any material downloaded from the Internet. Please consult the relevant unit lecturer or your course tutor if you need any further advice.

Student Declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I declare that the work
submitted for assessment has been carried out without assistance other than that which is acceptable according to the rules of the specification. I
certify I have clearly referenced any sources and any artificial intelligence (AI) tools used in the work. I understand that making a false declaration is
a form of malpractice.
Student’s signature Thang

Grading grid

P1 P2 P3 P4 P5 P6 M1 M2 M3 M4 D1 D2 D3 D4
❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date:


Internal Verifier’s Comments:

Signature & Date:


Table of Contents
I. Algorithm Definition................................................................................................................................................................. 1
A. What’s Algorithm.................................................................................................................................................................... 1
B. Algorithm Characteristics........................................................................................................................................................ 1
C. Algorithm representation........................................................................................................................................................ 2
1. Natural language...................................................................................................................................................................... 2
2. Flowchart.................................................................................................................................................................................. 3
3. Pseudo code............................................................................................................................................................................. 4
D. Example................................................................................................................................................................................... 4
II. Step in program development................................................................................................................................................. 4
A. Defining or Analyzing the problem.......................................................................................................................................... 4
B. Degisn...................................................................................................................................................................................... 5
1. Modular Design........................................................................................................................................................................ 5
C. Coding..................................................................................................................................................................................... 5
D. Documenting the program...................................................................................................................................................... 5
E. Testing..................................................................................................................................................................................... 5
F. Debugging................................................................................................................................................................................ 5
G. Maintenance........................................................................................................................................................................... 5
III. Outline of given scenario........................................................................................................................................................ 6
A. Context.................................................................................................................................................................................... 6
B. Objective................................................................................................................................................................................. 6
C. Requirements.......................................................................................................................................................................... 6
D. Possible Challenges................................................................................................................................................................. 6
IV. Program Outline..................................................................................................................................................................... 6
A. Data types............................................................................................................................................................................... 6
B. Diagram................................................................................................................................................................................... 8
Table of figure
Figure 1: Algorithm Characteristics .................................................................................................................................................
1
Figure 2: Flowchart Example ...........................................................................................................................................................
3
Figure 3: Data types table ...............................................................................................................................................................
7
Figure 4: Program diagram ..............................................................................................................................................................
8
I. Algorithm Definition
A. ALGORITHM DEFINE
Algorithm is one of the foundations of programming. There are many definitions of algorithms, such as:

Algorithm can be defined as: “A sequence of activities to be processed for getting desired output from a given input.”

Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem.
To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”. There can be many ways to
solve a problem, so there can be more than one algorithm for a problem.

Now, if we take definition of algorithm as: “A sequence of activities to be processed for getting desired output from a
given input.” This is why algorithm refers to a set of rules/instructions that define step by step how to do work to
achieve an expected result.

Figure 1. What is algorithm?


Thus, the entire algorithmic flowchart will have three main components:

Table 1: CHARACTERISTICS OF ALGORITHM

B. CHARACTERISTICS OF ALGORITHM
1) Input: An algorithm must be provided with 0 or more number of input/data values or in some cases no external input is provided.

2) Output: After processing the statements in algorithm step-by-step statements will generate some result. Hence at least 1 output
must be produced. This enables us to verify the algorithm.

3) Finiteness: An algorithm must always terminate after a finite number of steps. It means after
every step one reach closer to solution of the problem and after a finite number of steps algorithm
reaches to an end point.

For example
1. Let a = 10

2. If a >10 then go to step 5

3. x=y*z

4. Print x and go to step 2

5. Stop.

Here we notice that in algorithm the value of a is not changed, which happens to be controlling the flow and hence never
terminates. Such statement must be avoided. The finiteness property ensures that the unambiguity in the flow.

4) Definiteness: Each step of an algorithm must be precisely defined. An algorithm must be unambiguous and clear. Each step
of algorithm and input/outputs must be clear. There is only one meaning of each step of algorithm.

5) Effectiveness: Algorithms to be developed/written using basic operations. It must be possible that every step of the
algorithm to be carried out by a person manually using only pencil and paper. The statements of algorithm must be feasible to convert
in computer program.

6) Language-independent may refer to:

Language-independent specification, a programming language specification applicable toward


arbitrary language bindings

Language independent arithmetic, a series of ISO/IEC standards on computer arithmetic


C. Algorithm representation
o The algorithm can be representation in the following ways:

1. Natural language
▪ List sequentially the steps in natural language to represent the algorithm

a) Advantage:
• Simple, no knowledge of representation (pseudocode, flowchart,...)

b) Disadvantage
• Long, unstructured. Sometimes it's hard to understand, can't express the algorithm
2. Flowchart
▪ Flowchart is a diagrammatic representation of an algorithm. It uses
different symbols to represent the sequence of operations, required to
solve a problem, serves as a blueprint or a logical diagram of the solution
to a problem. Unlike algorithm, flowchart uses different symbol to design
a solution to a problem
▪ It is another commonly used programming tool. By looking at a flowchart
one can understand the operations and sequence of operations
performed in a system. Flowchart is often considered as a blueprint of a
design used for solving a specific problem

a) Advantage
• Flowchart is excellent way of communicating the logic of a
program.
• Easy and efficient to analyze
problem using flowchart.
• During program development cycle, the flowchart plays the role
of a blueprint, which makes program development process easier.
• After successful development of a program, it needs continuous timely maintenance during the
course of its operation. The flowchart makes program or system maintenance easier.
• It is easy to convert the flowchart into any programming language code.

b) Disadvantage
• Cause waste of time on small projects.
• As algorithm become more complex, diagrams can become messy and difficult to follow. This can
lead to confusion and misunderstanding.
• On algorithm change, flowcharts need to be updated. This can be a time-consuming and error-
prone process.

3. Pseudo code
▪ Pseudo code is basically short English phrases used to explain specific tasks within a
program’s algorithm. It should not contain any specific computer languages.
▪ If you can not write it in Pseudo code you won’t be able to write it in C++ or Java a)

Advantage

• It is used as a frame for programmers to use to write code based on it b)

Disadvantage

• Unlike actual code, pseudocode cannot be directly compiled and run. This means you
can't use it to test the logic or identify specific errors that might arise in actual code

D. Example
- Here is an example of algorithm:
Ex 1: Calculate the area of a rectangular garden:

o Step 1: Get user


input including side a
and side b of the garden o Step 2: Calculate: area = a * b
o Step 3: Returns area value to the user
Ex 2: Go across the road past the crosswalk with traffic light

o Step 1: Look to see if the pedestrian traffic light is


green o Step 2: If the light is red, wait, if green go to step
3
o Step 3: Cross the street calmly and watch out for
people running red lights o Step 4: Success goes to the
other side

II. Step in program development


2.1 Analyzing Or Defining The Problem
Analyzing or defining a problem is a crucial step in problem-solving and decision-making processes. Whether you are facing a
complex issue or trying to improve a situation, a well-defined problem statement lays the foundation for finding effective solutions.
Here are key steps and considerations for analyzing or defining a problem:

• The various steps involved are

Problem Definition Analyzing


• Algorithm Development

• Coding & Docometation

• Problem analysis

• Testing and Debugging

• Maintenance

2.2 Algorithm Development (Design)


• Developing Algorithmic Thinking via Solving Puzzles:

Solving puzzles and brain teasers helps enhance logical reasoning and problem-solving skills.

Analyse patterns used to solve puzzles and identify already defined algorithms like greedy algorithms, dynamic programming, or
recursion.

For example, solving Sudoku puzzles can improve logical reasoning, and identifying the backtracking algorithm used in solving
Sudoku can enhance algorithmic thinking.

• Developing Algorithmic Thinking via Practicing Steps of Problem-Solving:

Understand the problem statement, and identify inputs, and desired output.

Break down the problem into smaller subproblems to handle complexity.

Determine the logic needed to solve each subproblem efficiently.

Combine the solutions of subproblems to solve the main problem.

For instance, in a maze-solving problem, breaking it down into finding a path from start to end in
smaller sub-mazes simplifies the overall task.
Algorithm Development

2.3 Coding And Documentation


Coding
An algorithm expressed in programming languages is called Program

Writing a program is called Coding

The logic that has been developed in the algorithm is used to write program

Documentation
• Document explains
How the program works and how to use the program (user
manual). How to maintain the program (developer manual).
• Details of particular programs, or particular pieces of programs, are easily forgotten or confused without suitable
documentation.
Forms of documentation
• Documentation comes in two forms
+) External documentation, which includes things such as reference manuals, algorithm descriptions, flowcharts, and project
workbooks.
+) Internal documentation, which is part of the source code itself (essentially, the declarations, statements, and comments).

Compiling using GCC compiler


We use the following command in the terminal for compiling our filename.c source file We can pass many
instructions to the GCC compiler to different tasks such as:
-The option -Wall enables all compiler’s warning messages. This option is recommended to generate better code.
-The option -o is used to specify the output file name. If we do not use this option, then an output file with the name a.out is
generated.
-If there are no errors in our C program, the executable file of the C program will be generated.

2.4 Tetsting And Debugging


Testing: Testing is the process of verifying and validating that a software or application is bugfree, meets the technical
requirements as guided by its design and development, and meets the user requirements effectively and efficiently by
handling all the exceptional and boundary cases.

Debugging: Debugging is the process of fixing a bug in the software. It can be defined as identifying, analyzing, and
removing errors. This activity begins after the software fails to execute properly and
concludes by solving the problem and successfully testing the software. It is considered to
be an extremely complex and tedious task because errors need to be resolved at all stages
of debugging.
Tetsting And Debugging

2.5 Maintenance
Maintenance in English is defined as follows: the work needed to keep a road, building, machine, etc. in good condition (roughly translated:
work necessary to keep roads, buildings, machinery, etc. in good condition). Maintenance is translated into Vietnamese as maintenance, protection,
preservation. In the engineering industry, Maintenance is understood as maintenance. Maintenance is defined in the Vietnamese dictionary as
follows:
Maintenance is maintenance and repair to ensure that a system or part of it operates well and is highly reliable in use. In engineering , maintenance
is a process, not a specific job, this process helps maintain the best condition for equipment and machinery. Maintenance includes the following
steps: - Checking the functionality of equipment and machinery - Repairing or replacing equipment, machinery or parts of equipment, machinery,
building infrastructure and utilities installed at businesses, government agencies, and damaged communities. Maintenance has two forms as
follows: - Predictive maintenance - Preventive maintenance or Planned preventive maintenance plan
III. Outline of given scenario
A. Context
- You are a software developer working for ABC software, an independent company that designs and builds bespoke software
solutions for various clients. And this time the customer wants calculate monthly water bill program.

B. Objective
- Develop a program that allows users to enter their customer type, last month's meter reading, current month's
meter reading, and the number of people in the household (if applicable).
- The program should then calculate the water bill based on the following criteria: o The price of water is
determined by the customer type and water usage according to a provided table. o An environmental protection
fee of 10% is added to the water cost. o The program should then calculate the VAT (Value Added Tax) on the
total fee.

C. Requirements
- The program must allow users to enter the specified information.
- The program must calculate the water bill accurately based on the provided criteria.
- The program should be user-friendly and easy to use.

D. Possible Challenges
- Determining the most efficient way to calculate the water bill based on the customer type and water usage. -
Ensuring the accuracy of the calculations.
- Designing a user-friendly interface for the program.

IV. Program Outline


- The company "Ninh Binh Electricity and Water Equipment" requires you to calculate this month's electricity and water bills. To do this, you must
first plan and understand the formula for calculating your electricity bill. This amount includes the amount of electricity multiplied by the price and
taxes. If you use a lot of electricity, the price will automatically increase and to do all that, we need 4 steps:
1.First: The input.

2.Seconde: Calculate the water bill

3.Third: Calculate fees, tax, and the total bill.


4.Fifth: The output

- We are going to solve mese problems step-by-step to design a seamless solution for ABC Software's requirement of calculating monthly water
bills. The development process is meticulously structured, focusing on five distinct challenges that need to be addressed comprehensively.

4.1 The input


- We need to give information to customers:
+The water consumed in m3.
+Customers type( household, sewing company, supermarket, aonemall).

- The flowchart will be like this:

Table 3: THE INPUT


+The first customer must fill in his or her name
+Enter water consumption data from this month
+Choose customer type

-We have to show customers the price of water:


+ Household customer

Fisrt price

0 → 10 : 5.973 VND/m3 at most 57.73 VND/m3.

Second price

10 → 20 : 7.052 VND/m3 at most 70.52 VND/m3.

Thirt price

20 → 30 : 8.699 VND/m3 at most 86.99 VND/m3.

Over price

30→ ... : 15.929 VND/m3.

+ Sewing company:

Price NC: 9,955 VND/m3.

+Supermarket:

Price S: 11.615 VND/m3 + Aone Mall:


Price AM: 22.068 VND/m3

+ Fee enviroment protection : 10% bill

+ Fee VAT: 10% bill

Table 4: THE INPUT

4.2 Calculate The Water Bill


Calculate water bills is : WaterCustomed * type price
Table 5: CALCULATE THE WATER BILL

Ex1 : Choose type customer: Household customer; AA, PS; PU; BS:

With “Household customer”


WaterCustomed = 15 (m3) (Second price)

=> Waterbill = (max fisrt price + WaterCustomed * Second price) + Fee enviroment protection + Fee VAT = (59.73
+ 15 * 7.052) + (59.73 + 15 * 7.052)/10 + (59.73 + 15 * 7.052)/10 = 165.51 + 16.551 + 16.551 = 496.612 (VND) And WaterCustomed = 40

(m3) (Over price)

=> Waterbill = (max fisrt price + max second price + max thirt price + waterCustomed * over price) + Fee enviroment protection + Fee
VAT = (59.73 + 70.52 + 86.99 + 40*15.929) + 85.44 + 85.44 = 854.4 + 85.44 + 85.44 = 1025.28 (VND)
Table 6: CALCULATE THE WATER BILL

Ex2 : With “ Aone Mall”


WaterCustomed = 27 (m3)

 Waterbill = WaterCustomed * Aone + Fee enviroment protection + Fee VAT =Mall


27 * 22.068 + (27 * 22.068)/10 + (27 * 22.068)/10 = 715.0032 VND
Table 7: CALCULATE THE WATER BILL

4.3 Calculate Fees, Tax, And the Total Bill

4.3.1: Calculate fees


- Waterbill all = waterbill( 1 + 2 + 3 + 4 ) + fees VAT + fees Enviroment

Or

- Waterbill = Price ((AA, PS; PU; BS) + fees VAT + fees Enviroment

Table 8: CALCULATE FEES


4.3.2: Tax
1. VAT (Value – Added Tax)

VAT = 10% bill

Ex: Bill = 110.000 VND => VAT = 10.000VND

2. Fees Enviroment

E = 10% bill

Ex : bill = 110.000VND => Fees E = 10.000 VND

4.3.3: Total Bill


Total bill have:

+ Total money

+ VAT

+ Enviroment
4.4 Output
Table 9: OUT PUT

-Provide the amount the customer needs to pay, accompanied by an invoice showing value added tax, environmental tax and time at that
time.

Flowchart Full:
Table 10: FULL FLOWCHART
V. Introduction to C# language
• C# is a high level object-oriented programming language

• C# is very similar to Java in terms of syntax and is very easy to use for users with knowledge of C, C+
+ or Java.

VI. Introducing Visual Studio Community


2022
• Visual Studio is an Integrated Development Environment (IDE) developed by Microsoft, will be used by me to
develop my C# program.
1. Visual Studio’s strength in C#
programming
• Language understanding: This IDE have features like advanced code completion, real-time error checking,
and refactoring capabilities tailored specifically for C#.

• .NET framework support: As the official IDE for the .NET framework, Visual Studio provides seamless
integration with all its libraries and tools. This includes automatic project setup, debugging tools optimized
for .NET applications, and easy access to .NET documentation and resources.

• Some other strengths of Visual Studio include:


Debugging, Crossplatform development,…
2. Visual Studio’s weakness in C#
programming
• Resource Intensity: As a full-featured IDE, Visual Studio can be resource-hungry, especially on older
machines or complex projects. This can lead to slower loading times, responsiveness issues, and higher
power consumption.

• Memory Management: Some users report encountering memory


leaks or crashes, especially in larger projects or when using specific plugins.

3. Why Visual Studio?

• Because Visual Studio has Community edition and it's free. Unlike JetBrains Rider, which requires a
subscription to use.

• Both C# and Visual Studio are developed by Microsoft, so it can be said to be a specialized IDE for C#
and .NET Framework.

VII. Program development process


1. Create new project
- I will create new
console app
Naming project

- I named
this project

Assignment1
Choose framework
- In this project
I will use .NET
8.0
2. Coding process
A. Utilities class used in
program
a) ConsoleUtils.cs(part 1)
• currentLineisvariable used to determine the
line where the cursor is
• ClearAll()method clears the entire console
screen by filling it with spaces and resetting
the cursor position to the top-left corner.
• ClearLine(int line)method is similar to
ClearAll()method but the difference is that it
only fills the specified line with spaces
• is a
Write(params FormattedText[] text)
method used to write out elements in the
text array
• WriteLine(params FormattedText[] text)is
the
same as the Write() method above but add a
line break at the end

• Note: The FormattedText struct explain in


next page

a) ConsoleUtils.cs
(part2)
• is
WriteAt(int line, params FormattedText[] text)
a method used to write out the elements in
the text array at the specified line
• WriteLineAt(int line, params FormattedText[]
text) same as above but add line break at the
end
• FormattedText struct contains:
• object text: Use as value to print on console
• ConsoleColor color: color of text on console
• Formatter class: Extension of object class
• Format() method user to get FomattedText
from object

b) Database.cs (part 1)
• This class is used to perform file
operations
• and deserializer are fields
serializer
imported from the YamlDotNet
dependency
• Initialize() database initialization method
• GetUsers()method use to get
unchangeable list of user
• GetUsers(SortMethod method)similar to
the above method but sorted by
SortMethod
• FindUsers(string? name, SortMethod method)
returns an unchangeable list that Username of
its elements contains name

b) Database.cs
(part 2)
• use to delete all user data
ClearAll()
from the database
• Remove(string username, UserType
type, double lastMonth, double
thisMonth) this method deletes a
user with input arguments from the
database
• Add(User user) add users to the
database
• Add(params User[] users)similar
to
above but can add more than 1
user in one call
• Load() load database from file
• Save() save database to file
• SortMethod is an enum that provides algorithms
for sorting list of users
• SortMethodCompareris an
extension class of SortMethod.
Returns Comparison for use in
List.Sort()
• User is POCO class contains user data • UserType
is an enum that provides additional methods
corresponding to each User type
• UserTypeShortName returns the shortened
name of UserType
• UserTypeDescription returns the description of UserType
• Extension class of UserType
returns the method to
calculate water bill

Full code :
• Main(string[] args) is the main method of the program •
ChoiceAction() is a method for users to choose the desired
operation. Here include Add, Remove and Query actions
• The AddUser() method is responsible for adding the
User to the database
• The RemoveUser() method use to remove User from the
database
• The QueryUser() is a complex method used
to query and find users from a list

The Chooser() method provide the user with a simple


chooser using Tab and Enter
• TypeChooser() is submethod of Chooser()
• GetNumberInput() is used to get number
from input with type int or double
VIII. Tesing
Now the police department's data has
disappeared from the database
Input Expected output Actual output
Username: PCT Type: Error Message: NaN Error Message: NaN (Not a Number)
Household Last (Not a Number)
Month: hmm? Request user to re-enter value
This Month: Not yet reached Request user to re-
enter value
Username: PCT Error Message: This Error Message: This month must NO
Type: Household month must NOT be than or equal to last month
Last Month: 32 less than or equal to
This Month: 10 last month Request user to re-enter value

Request user to re-


enter value
Username: PCT Add to database Added to database sucessfully
Type: Household sucessfully
Last Month: 32
This Month: 40
• Problem Definition: The first step in writing code is to clearly define the problem
that you are trying to solve. This involves understanding the requirements of the
project, the users, and the system. It is important to break down the problem\
into smaller, more manageable tasks.
• Design: Once you have a clear understanding of the problem, you can start to
design the code. This involves choosing the right programming language,
algorithms, and data structures. It is also important to consider the
maintainability, scalability, and performance of the code.
• Implementation: This is the stage where you actually write the code. It is
important to write clean, efficient, and well-documented code. You should also
test your code as you go to ensure that it is working correctly.
• Testing: Once you have written all of the code, you need to test it thoroughly.
This involves testing all of the different parts of the code to make sure that they
work as expected. You should also test the code under different conditions to
make sure that it is robust.
• Deployment: Once the code is tested and debugged, it can be deployed to
production. This involves moving the code to a live server where it can be used
by users.
• Maintenance: Even after the code is deployed, you will need to maintain it. This
involves fixing bugs, adding new features, and updating the code to keep it up-to-
date with the latest technologies.
X. Analyse the process of writing code, including the
potential challenges faced.

• Complexity: Code can be very complex, especially for large projects. This can
make it difficult to understand, write, and maintain.
• Errors: It is very common to make errors when writing code. These errors can be
difficult to find and fix, and they can cause the code to not work correctly.
• Source code: This is the human-readable code you write.
• Preprocessor: This processes the code before
compilation.
• Compiler: This translates the code into assembly
language.
• Assembler: This translates assembly language into
machine code.
• Linker: This combines machine code modules into
an executable program.
• Loader: This loads the executable program into
memory and starts it running.

https://www.researchgate.net/publication/319716548_SOFTWARE_DEVELOPMENT_LIFE_CYCLE_SDLC_ANALYTIC
AL_COMPARISON_AND_SURVEY_ON_TRADITIONAL_AND_AGILE_METHODOLOGY [Accessed 10 10 2021].

Mahdi, A. y., 2013. ALGORITHM AND FLOW CHART | Lecture 1. [Online]


Available at: https://faradars.org/wp-content/uploads/2015/07/Algorithm-and-Flow-Chart.pdf [Accessed 29 9 2021].

Tutorial, D. S., December 04, 2020. What is algorithm and characteristics of good algorithm. [Online] Available at:
https://www.codingtutorial4u.com/2020/12/what-is-algorithm-and-characteristics.html [Accessed 29 9 2021].

Ullman, A. A. a. J., 2021. Computer Science. [Online] Available at:


https://ncert.nic.in/textbook/pdf/kecs104.pdf [Accessed 4 10 2021].

[Accessed 29 9 2021].
Tutorial, D. S., December 04, 2020. What is algorithm and characteristics of good algorithm. [Online] Available at:

https://www.codingtutorial4u.com/2020/12/what-is-algorithm-and-characteristics.html

[Accessed 29 9 2021].

You might also like