Nguyen Le Thanh Cong-Bs01057

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

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 1: Programming

Submission date 29/03/2024 Date Received 1st submission 29/03/2024

Re-submission Date Date Received 2nd submission

Student Name NGUYEN LE THANH CONG Student ID BS01057

Class SE07102 Assessor name TRUONG QUOC KHANH

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 Cong

Grading grid

P3 P4 P5 P6 M2 M3 M4 D2 D3 D4
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Contents
I. Introduction ................................................................................................................ 7
II. Explain programming paradigms ................................................................................ 7
1. Procedural programming:....................................................................................... 7
2. Event Driven programming: ................................................................................... 7
3. Object Orientated programming: ........................................................................... 8
4. Comparison between three programming paradigms: ........................................... 9
III. Explain about IDE (Integrated Development Environment) ..................................... 10
1. Definition: ............................................................................................................ 10
2. Features: .............................................................................................................. 10
3. Debugging: ........................................................................................................... 11
3.1. Definition: ...................................................................................................... 11
3.2. How it works: ................................................................................................. 11
3.3. Tools used: ..................................................................................................... 11
3.4. Process of debugging: .................................................................................... 12
IV. Coding Implementation ........................................................................................... 13
1. Design of program: ............................................................................................... 13
2. Flowchart of program: .......................................................................................... 15
3. Code of water bill application: .............................................................................. 16
3.1. Input, output of application: .......................................................................... 16
3.2. Algorithm for application: .............................................................................. 16
3.3. Requirement running program:...................................................................... 17
3.4. Code and result: ............................................................................................. 23
4. Coding standard ................................................................................................... 33
4.1. Definition: ...................................................................................................... 33
4.2. Coding standards I have used in the program: ............................................... 34
V. References ................................................................................................................ 35

List of Table:
Table 1: Relationship between three programming paradigms ........................................ 10

List of Figure:
Figure 1: The visual application before enter Submit button ............................................ 13
Figure 2: The visual application after enter Submit button ............................................... 14
Figure 3: Flowchart of program ........................................................................................ 15
Figure 4: Have to enter name for running the program .................................................... 17
Figure 5: Have to choose type for running the program ................................................... 18
Figure 6: Have to enter number of people in case of household customer ...................... 19
Figure 7: Can't enter number of people in case of customer is not household ................. 20
Figure 8: Have to enter last month's water uses for running the program ....................... 21
Figure 9: Have to enter this month's water uses for running the program ...................... 22
Figure 10: The program can not run if last month’s water uses more than this month .... 22
Figure 11: Let customer enter their Last month water's uses and This month water's uses
and enter their name ........................................................................................................ 23
Figure 12: Requirement for running program ................................................................... 23
Figure 13: Condition for bool isChecktype ........................................................................ 23
Figure 14: Function for printing water bill for customer who is Administrative agency,
public services and Production Units and Business Services ............................................. 24
Figure 15: Function for printing water bill for customer who is Household ...................... 24
Figure 16: Price to calculate water bill for customer who is Household............................ 25
Figure 17: Price to calculate water bill for customer who isn't Household ....................... 25
Figure 18: Declare variable Consume and Price to calculate total water bill ..................... 25
Figure 19: Calculate total price and printing water bill for customer who is Household and
having one person in family .............................................................................................. 26
Figure 20: Calculate total price and printing water bill for customer who is Household and
having more than 2 persons in family ............................................................................... 27
Figure 21: Calculate total price and printing water bill for customer who is Administrative
agency, public services or Production Units or Business Services ..................................... 28
Figure 22: Condition for import people number if customer who is household
requirement ..................................................................................................................... 29
Figure 23: Output total price and printing water bill for customer who is Administrative
agency, public services ..................................................................................................... 30
Figure 24: Output total price and printing water bill for customer who is Production Units
......................................................................................................................................... 30
Figure 25: Output total price and printing water bill for customer who is Business Services
......................................................................................................................................... 31
Figure 26: Output total price and printing water bill for customer who is Household and
having 1 person in family .................................................................................................. 32
Figure 27: Output total price and printing water bill for customer who is Household and
having more than 2 persons in family ............................................................................... 33
Figure 28: Meaningful variable names .............................................................................. 34
Figure 29: Comments ....................................................................................................... 34
Figure 30: Names representing types must be in mixed case starting with upper case .... 34
Figure 31: Variable names must be in mixed case starting with lower case...................... 35
I. Introduction
In this essay, I will show my project about calculating bill water application that was
produced using the IDE and was subject to Coding standards for a comprehensive business
problem. As a result, I have to write a WinForm application in the C# programming language
of Microsoft Visual Studio. I also introduce to three programming paradigms: Procedural
Programming, Object Orientated Programming, Event Driven Programming.

II. Explain programming paradigms

1. Procedural programming:
Procedural programming is a way of telling a computer what to do by giving it a list of
instructions. These instructions a grouped together into smaller tasks called procedures.
Procedural programming completes the task into step by step instructions. This style of
programming is focused on the steps themselves, rather than on the date the program
works with. It’s a good way to code for simpler tasks but this way couldn’t be suitable for
complex tasks.

2. Event Driven programming:

Instead of following a step by step instructions, event-driven programming lets programs


respond to things happening around them. These "things" are called events, and they can
come from various sources:

 Users interacting with the program (clicks, swipes, key presses)


 Sensors in the environment
 Other programs sending messages
 The network (data arriving or being sent)

The program constantly listens for these events, and when one happens, it triggers a
specific piece of code designed to handle that situation. This makes event-driven
programming useful for programs that need to be flexible and react to unexpected changes.
EDP is particularly useful for programs that need to handle many things at once, or that
need to react to unpredictable events from the outside world. For example, user interfaces,
video games, and network servers all heavily rely on event-driven programming.

3. Object Orientated programming:


Instead of just telling the computer what to do step-by-step (like a recipe), Object-oriented
programming (OOP) lets you organize programs around real-world things. These things are
called objects, and they bundle together data (like what they are and their properties) and
instructions (what they can do). This makes OOP easier to understand and manage,
especially for big and complex programs.

OOP has 4 basic properties:

 Encapsulation
 Abstraction
 Inheritance
 Polymorphism
4. Comparison between three programming paradigms:

Paradigms Focus Structure Control Advantages Disadvantages


Flow
Procedural Focuses on Code is The Simple and Can become
the organized into program easy to learn, difficult to manage
breakdown of procedures flow is good for for large projects
tasks into (functions, sequential, smaller tasks. as code becomes
step-by-step subroutines) following less organized.
instructions that perform one
(procedures) specific tasks. instruction
for the after
computer to another in
follow. the order
they are
written.
OOP Focuses on Code is Control Promotes Can lead to overly
organizing organized into flow can be code complex code
code around classes that more reusability, structures if not
real-world define the dynamic as modularity, designed carefully.
entities blueprint for objects and
(objects) that objects. interact maintainability
contain data Objects are with each for complex
(properties) instances of other projects.
and classes and through
functionalities contain data method
(methods) to and methods calls.
operate on specific to
that data. that object.
EDP Focuses on Code is Control Highly Debugging event-
how structured flow is responsive to driven programs
programs around event event- user input and can be challenging
react to listeners that driven, external due to the
events (user wait for meaning it changes, ideal asynchronous
interactions, specific depends on for user nature of events.
sensor data, events and the order interfaces and
network then execute and timing network
activity) corresponding of events applications.
rather than code to that the
following a handle those program
rigid list of events. encounters.
instructions.

Table 1: Relationship between three programming paradigms

III. Explain about IDE (Integrated Development Environment)

1. Definition:
An IDE stands for Integrated Development Environment. It's basically a software application
that combines a bunch of different tools that programmers use to write computer
programs.

2. Features:

 Source code editor: This is where programmers write their code. IDEs typically
have features like syntax highlighting, which makes the code easier to read, and
code completion, which can help programmers write code faster.
 Build automation tools: These tools help programmers automate the process of
building their programs. This can save programmers a lot of time and effort.
 Debugger: This tool helps programmers find and fix errors in their code.
 There are also many other features that IDEs may have, such as version control
integration, unit testing frameworks, and code profilers.
 IDEs can be used for a variety of programming languages, including Python, Java,
C++, and web development languages like HTML, CSS, and JavaScript.

3. Debugging:

3.1. Definition:
Debugging refers to the process of identifying and fixing errors, or bugs, in software. It's a
vital part of software development to ensure the final product works as intended.
Debugging involves finding and resolving issues that cause a program to malfunction,
perform poorly, or generate incorrect results. These issues are often called bugs.

3.2. How it works:


Debuggers typically involve a systematic approach to pinpoint the source of the problem.
This may involve examining the code, inspecting variables, and tracing the program's
execution step-by-step.

3.3. Tools used:


Programmers often use specialized software debuggers that provide features like:

 Stepping through code: Allows examining the program line by line, seeing variable
values at each step.
 Setting breakpoints: Pauses the program execution at specific points to analyze its
state.
 Inspecting variables: Viewing the values of variables in the code at any point.
3.4. Process of debugging:
1. Identify the Error: This initial step involves recognizing that something isn't
working as expected. This could be through program crashes, unexpected
outputs, incorrect results, or unusual behavior.
2. Reproduce the Error: Once you identify an error, it's crucial to be able to
reproduce it consistently. This allows you to isolate the root cause more
effectively. Sometimes specific steps or conditions might trigger the bug, so
pinpointing these helps in debugging.
3. Isolate the Error Location: With the error reproduced, you can narrow down
the part of the code that's causing the issue. Debuggers come in handy here.
They allow you to step through the code line by line, examining variable values
at each stage. This helps pinpoint the specific line or section where the error
occurs.
4. Analyze the Error: Now that you know where the error is happening, it's time
to understand why. Analyze the code logic and identify what's causing the
unexpected behavior. This might involve reviewing the code itself, checking
variable assignments, and understanding the flow of data.
5. Fix the Error (Implement a Solution): Once you understand the root cause,
you can fix the bug. This might involve correcting a syntax error, fixing a logical
mistake in the code, or handling unexpected inputs differently.
6. Test the Fix: After implementing the fix, thoroughly test the program again.
Verify that the error is resolved and no new issues are introduced. Sometimes,
fixing one bug might uncover another, so it's important to retest
comprehensively.
7. Document the Fix: It's good practice to document the bug, the solution
implemented, and any relevant notes for future reference. This helps maintain
the codebase and can be valuable for other developers working on the project.
IV. Coding Implementation

1. Design of program:
The program was designed by a window form, in the context of Windows Forms
development, is the foundation of a graphical user interface (GUI) for desktop applications.

The visual application before enter Submit button:

Figure 1: The visual application before enter Submit button


The visual application after enter Submit button:

Figure 2: The visual application after enter Submit button


2. Flowchart of program:

Figure 3: Flowchart of program


3. Code of water bill application:

3.1. Input, output of application:


 Input:
1. Name of customer
2. Type of customer
3. People number of customer (for customer is household)
4. Last month water’s uses index
5. This month water’s uses index
 Ouput:
1. Name of customer
2. Type of customer
3. People number of customer (for customer is household)
4. Last month water’s uses
5. This month water’s uses
6. Consumption of water
7. Total price

3.2. Algorithm for application:

Step 1: Let customer enter their name

Step 2: Let customer choose their type

Step 3: Let customer enter last month water’s uses

Step 4: Let customer enter this month water’s uses

Step 5: Calculate total price for each customer’s type


Step 6: Print water bill for each customer’s type included:

 Customer’s name
 Type of customer
 People number (for customer is household)
 Last month water’s uses
 This month water’s uses
 Consumption of water
 Total price

3.3. Requirement running program:


 Customer have to enter their name for running the program

Figure 4: Have to enter name for running the program


 Customer have to choose their type for running the program

Figure 5: Have to choose type for running the program


In case of customer is household, they must enter number of people for running the
program

Figure 6: Have to enter number of people in case of household customer


In case of customer is not household, they mustn’t enter number of people

Figure 7: Can't enter number of people in case of customer is not household


 Customer have to enter their last month’s water uses and this month’s water uses
for running the program

Figure 8: Have to enter last month's water uses for running the program
Figure 9: Have to enter this month's water uses for running the program

 The program can not run if last month’s water uses more than this month’s water
uses

Figure 10: The program can not run if last month’s water uses more than this
month
3.4. Code and result:
 Code

Figure 11: Let customer enter their Last month water's uses and This month water's uses
and enter their name

Figure 12: Requirement for running program

Figure 13: Condition for bool isChecktype


Figure 14: Function for printing water bill for customer who is Administrative agency,
public services and Production Units and Business Services

Figure 15: Function for printing water bill for customer who is Household
Figure 16: Price to calculate water bill for customer who is Household
(include 10% fee protect environment)

Figure 17: Price to calculate water bill for customer who isn't Household
(included 10% fee protect environment)

Figure 18: Declare variable Consume and Price to calculate total water bill
Figure 19: Calculate total price and printing water bill for customer who is Household and
having one person in family
Figure 20: Calculate total price and printing water bill for customer who is Household and
having more than 2 persons in family
Figure 21: Calculate total price and printing water bill for customer who is Administrative
agency, public services or Production Units or Business Services
Figure 22: Condition for import people number if customer who is household
requirement
 Result

Figure 23: Output total price and printing water bill for customer who is Administrative
agency, public services

Figure 24: Output total price and printing water bill for customer who is Production Units
Figure 25: Output total price and printing water bill for customer who is Business Services
Figure 26: Output total price and printing water bill for customer who is Household and
having 1 person in family
Figure 27: Output total price and printing water bill for customer who is Household and
having more than 2 persons in family

4. Coding standard

4.1. Definition:
A coding standard, also sometimes called a coding convention or programming style
guide, is a set of rules and best practices that programmers follow when writing code.
These rules define how the code should be formatted, structured, and documented.
4.2. Coding standards I have used in the program:
 Meaningful variable names: Variable names like LastMonthWaterUse,
ThisMonthWaterUse and UserName are descriptive and make the code
easier to understand

Figure 28: Meaningful variable names


 Comments: The code includes comments to explain the purpose of the const price

Figure 29: Comments


 Names representing types must be in mixed case starting with upper case: Like
variable names LastMonthWaterUse, ThisMonthWaterUse, UserName and
NumberOfPeople

Figure 30: Names representing types must be in mixed case starting with upper case
 Variable names must be in mixed case starting with lower case: Like variable
names isChecktype, checkType

Figure 31: Variable names must be in mixed case starting with lower case

V. References
(No date) What is procedural programming? A beginner’s guide. Available at:
https://programiz.pro/resources/what-is-procedural-programming/ (Accessed: 24
March 2024).

Event-driven programming (2024) Wikipedia. Available at:


https://en.wikipedia.org/wiki/Event-driven_programming (Accessed: 24 March
2024).

Gillis, A.S. and Lewis, S. (2021) What is object-oriented programming (OOP)?, App
Architecture. Available at:
https://www.techtarget.com/searchapparchitecture/definition/object-oriented-
programming-OOP (Accessed: 24 March 2024).

You might also like