ASM1 Progaming
ASM1 Progaming
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:
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.
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
3. x=y*z
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.
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
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:
• Problem analysis
• Maintenance
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.
Understand the problem statement, and identify inputs, and desired output.
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
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).
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.
- 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.
Fisrt price
Second price
Thirt price
Over price
+ Sewing company:
+Supermarket:
Ex1 : Choose type customer: Household customer; AA, PS; PU; BS:
=> 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
=> 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
Or
- Waterbill = Price ((AA, PS; PU; BS) + fees VAT + fees Enviroment
2. Fees Enviroment
E = 10% bill
+ 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.
• .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.
• 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.
- 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
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
•
• 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].
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].
[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].