You are on page 1of 55

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND 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 Tran Minh Quan Student ID GCH200753

Class GCH0905 Assessor name Do Tien Thanh

1.1
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 Quan

Grading grid

P2 P3 P4 P5 M2 M3 M4 D2 D3 D4

1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

2
Contents
I. Introduction ........................................................................................................................................................................................ 5
II. Programming Paradigms..................................................................................................................................................................... 5
1. Procedural paradigm........................................................................................................................................................................ 5
2. Object-oriented paradigm (OOP)..................................................................................................................................................... 6
3. Event-driven paradigm .................................................................................................................................................................... 8
4. Comparison ...................................................................................................................................................................................... 9
III. Program results ................................................................................................................................................................................... 9
1. Scenario – Problem – Solution ......................................................................................................................................................... 9
a. Scenario - problem ....................................................................................................................................................................... 9
b. Solution ..................................................................................................................................................................................... 9
2. Designing ........................................................................................................................................................................................ 10
a. Use case diagram ....................................................................................................................................................................... 10
b. Flow chart ............................................................................................................................................................................... 11
3. Explanation of Codes ..................................................................................................................................................................... 17
4. Program.......................................................................................................................................................................................... 32
IV. IDE usage in development ................................................................................................................................................................ 41
1. What is IDE? ................................................................................................................................................................................... 41
2. Common IDE features .................................................................................................................................................................... 41
V. Debugging ......................................................................................................................................................................................... 46
VI. Coding standard ................................................................................................................................................................................ 50
3
1. Name convention:.......................................................................................................................................................................... 50
2. Statement convention: .................................................................................................................................................................. 51
3. Layout............................................................................................................................................................................................. 52
4. Commenting and Documenting ..................................................................................................................................................... 53
VII. Conclusion ...................................................................................................................................................................................... 53

4
I. Introduction

I have applied for a post as a trainee with a software development company and have been invited for an interview. I
have been passed the presentation to demonstrate my problem solving and basic programming skills. Now I am given a
more challenge task to create a fully working, secure application that has been developed using an IDE and adheres to
coding standards for a detailed business problem.

II. Programming Paradigms


1. Procedural paradigm
Procedure programming is a programming language that allows computers to solve problems by following a set of
instructions. Procedural programming is also known as mandatory programming or top-down language since a
sequence of steps will be performed from the top to the bottom and in the correct order of the list.

Fundamentally procedural or imperative code is something that directly instructs a computer how to complete a task
that you want it to do in logical steps. Rather than declaring the world’s state (as we mentioned declarative things like
CSS do), you’d define that you shall make this things by cycling through this, appending it to that, and putting the
result here.

Much of WordPress is fundamentally procedural, in that (theme template files, for example) are a direct set of very
literal PHP and WordPress function calls that together accomplish the creation of a web page. This procedural style has
a great advantage that it is less confusing than many alternatives, and there is less routing around through lots of
different complicated concepts for most newer developers.

5
If you want a machine to solve a problem or perform a task, you must spell out each move in a list of instructions
about how and what to do. It means that the majority of early programming languages were procedural in nature.
(geeksforgeeks, 2018)

Figure 1 - Procedural paradigm

2. Object-oriented paradigm (OOP)


Object-oriented programing, or OOP, is language that solve problem by each step based on using object in all
algorithms. An object that is a part of a program has certain number of actions must be performed and it knows how
to contact with others of the program. Furthermore, this object is a basic unit or simple part in OOP.

In object-oriented programing, in order to control and flow your code, you can create objects along with their
properties and make sure that they do certain actions. By the way, a method in OOP is similar a procedure in
procedural programming but it is different in a part of objects.

6
OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them.
This approach to programming is well-suited for programs that are large, complex and actively updated or maintained.

Classes in Object-oriented programming is like a blueprint of objects and using them is one very important thing in
OOP. Classes will provide what objects should do, how they look and what they can do, just like a concept and objects
are embodiment. Examples of object-oriented languages include C#, Java, Perl and Python. (geeksforgeeks, 2018)

Figure 2 - Object-oriented programming (OOP)

7
3. Event-driven paradigm
Event-driven programming is like a computer programming model with the control of intentional events. Those events
are recorded by a code that knows as event listener. If some certain events have happened and occurred, it will give
information and handle those events with certain actions that have coded before. It focuses on providing processes
that respond to user actions.

Events are monitored by a code (or function) known as an event listener. If the event listener detects that an assigned
event has occurred, it will trigger a callback function, known as an event handler, which will perform said event, e.g.
clicking (the event) a “print” button (event listener) activates the actual print process (event handler).

Event-driven programs can be written in any programming language, although some languages(Visual Basic for
example) are specifically designed to facilitate event-driven programming, and provide an integrated development
environment (IDE) that partially automates the production of code, and provides a comprehensive selection of built-in
objects and controls, each of which can respond to a range of events. Virtually all object-oriented and visual languages
support event-driven programming. Visual Basic, Visual C++ and Java are examples of such languages.

Figure 3 - Event-driven paradigm

8
4. Comparison
Procedural paradigm Object-oriented paradigm (OOP) Event-driven paradigm
Focus on the order of the steps what Focus on objects and classes which Focus on giving processes that
should do. related to problems. respond to user actions or event.
Be completed by the commands Objects and classes have to do Be determined by event from user
which are executed from top to certain actions and related each actions, such as click, drag and drop,
down. other. ...
Provide interface to write code and Provide writing code in model Provides graphical for creating
create program. programs.

III. Program results


1. Scenario – Problem – Solution
a. Scenario - problem
The user want to manage his/her boarding house and manage tenants as well as each personal information, such
as full name, birth year, id card number, room number, ... Besides, user want to edit the information of tenants, add
new tenants or delete tenant who doesn’t want to live, change the wrong information, … and user want to calculate
the money for the rent of each room. It’s manager requirements. About tenant requirements, they want to see list of
tenants and check each information of each person.I agreed to help them with the problem. My application follows
coding standard so it is very easy to read. Also, this can help me improve myself.

b. Solution
I decided to use both OOP and Event-driven paradigm to make this application. I will save my information in
ArrayList to store memory and it is very convenient for contacting with information that store in ArrayList. I made
a option form for the user to choose. Button, label, and text box are used to make the user interface and store the
data. I also use the foreach loop statement for the List.

9
2. Designing
a. Use case diagram
There are two actors: tenant and manager. Based on the requirements, program has 5 functions: add, edit, delete
the information of customer, displays bill of rental house and final function is view list. Tenant only has function
view list but manager has all.

Figure 4 - Use case diagram

10
b. Flow chart
Before create a program, determining objects and classes is very important. In this program, information of
customer or tenant is a major thing. So that create a class for tenants, each tenant includes name, number room,
ID, birth year, … it is easily defined information of tenants.

Figure 5 - Diagram of class Tenant

11
When Information of Tenant is determined, saving them for using in each certain function is very important.
ArrayList is array, saving information in ArrayList is one of many ways to store memory and It is very convenient
for contacting with information that store in ArrayList. ArrayList has many functions: Add new information, Delete
or Remove one information on certain position, … Besides, users don’t need to be worried about space or length
of ArrayList, it can store lots of information.

Therefore, I use ArrayList to easily contact and manage.

Figure 6 - Store information in ArrayList

12
 Adding information function

Figure 7 - Adding information

13
 Deleting information function

Figure 8 - Deleting information

14
 Editing information function

15
 Displaying bill function

Figure 9 - Displaying bill for each Room

16
3. Explanation of Codes

17
I assign the calculate electric money event for the button 1. I declare the electric number last month and the electric number this
month is integer because this is the most suitable types of variables. I use the bool types to make sure that all the information the
user input in the electricity number box is all number, then I use the if statement to make sure that the user only input number in
the electricity number box, if the user does not input a number in the box or input the number of electricity now is smaller than last
month, the screen will display a notice to force the user to input a right number in the box, I use the MessageBox.Show statement
for the user to make sure that they have understood the notice. If the user input right numbers in both boxes, the program will then
calculate the electric number that they consume by the electric number last month minus the electric number this month. Then the
electric money will be calculate by the electric number consumed * 3000 and the the lbElec.Text statement will display the number
of electric consumed to the screen and the lbElecMn will display the amount of money that the customer has to pay.

18
I assign the calculate water money event for the button 2. I declare the water number last month and the water number this month
is integer because this is the most suitable types of variables. I use the bool types to make sure that all the information the user
input in the water number box is all number, then I use the if statement to make sure that the user only input number in the water
number box, if the user does not input a number in the box or input the number of water now is smaller than last month, the screen
will display a notice to force the user to input a right number in the box, I use the MessageBox.Show statement for the user to make
sure that they have understood the notice. If the user input right numbers in both boxes, the program will then calculate the water
number that they consume by the water number last month minus the water number this month. Then the water money will be
calculate by the electric number consumed * 3000 and the the lbWat.Text statement will display the number of water consumed to
the screen and the lbWatMn will display the amount of money that the customer has to pay.

I assign the calculate other money event for the button 3. The others money includes the cleaning fee, internet fee, parking fee, the
debt money from last month or others consumption. I declare all this components false as default in the first picture since I do not
know which customer will use what service. I use the if statement to make sure that if the user tick the box right in front of the
service, it will mark the box so that it will be enable that box r for the program to calculate the money. If the user does not tick the
box, that box will be mark and then it will be disabled and the program will not calculate it in the final result. All the if statement will
be process when the user click the “Check” button in the program.

19
20
I assign the calculate other services event for the button 4. I declare the type of variables for the cleaning fee as integer and it will
be calculate by the number of person * 50000, I also declare the variables for the internet fee as integer and it will be calculate by
the number of people * 60000, and the parking fee is also declare as integer and will be calculate by the number of vehicles *30000.I
also declare the other service money, the old debt money, the house rent money and the total amount money the customer has to
pay as integer. And I use the bool statement to make sure that the user has input the information in the other service money box
and the old debt money box. If the user the does not input a right number in those box when they are enable, the screen will display
a notice to make the user re input the information. I also assign the house money as 350000 all the time in the program. And then
the total other money will be calculated by the cleaning fee + the internet fee + the parking fee + other service fee + old debt + the
house rent money. And then I use the “ lbMn3.Text = ‘’+ totalMn.ToString()” to print the amount of money to the screen.

21
I assign the calculate the total amount of money event for button 5. I declare the Electric Money, the Water Money and the Others
Money as integer. And a string to notice the user when they forget to calculate the Electric Money or the Water Money. I use the
bool statement to make sure that the user input the right type of number in the Electric and Water Number and then it will display
the amount of money that the customer has to pay. If the user forget to calculate the Electric money, the screen will display “ Forget
calculate Electric Money “ and the message box will be display to make sure that the user get the message. The same thing will
happen when the user forger to calculate the Water money. A notice will be display and a message box will also be display for the
user to mark. If the user has enter all the information, then the total money that the customer will have to pay will be calculate by
the electric money + the water money + the other service money and then the “lbTT.Text = “” + TotalMN.ToString()” will display the
amount of money to the screen.

And I assign the exit event for the exit button. I use the “this.Close()” command to let the program know that I want to exit and then
it will exit for me.

22
23
I use the foreach to repeat all the element in the list of the hotel to print it on the screen. I use the foreach loop for the number
room, the name of the customer, birth year, ID number and the number of vehicle. And the “Text” command for the user to input
the customer information. And then I use the “ CellClick” command to show all the information of the customer on the screen when
the user want.

24
25
26
27
I assign the fix event for my fix button and I declare the type for all of my variables and then I use the “if…else” statement to check if
the user enter the valid information or not, if not, the screen will display a notice to make the user re enter the right information.
Then I use the foreach loop to check if the ID is correct or not , if the ID is correct, the program will display the information of the
customer to the screen, and then I use the “SelectedRow.Cell” command to save the change on the screen.

I assign the bill event to the bill button. It will make a bill for the room you choose, I use the if statement to make the user know if
they haven’t choose a room. If they choose a room, It will transfer the user to the bill form. I also assign the delete event for the del
button, if the user want to delete the customer, the screen will display a notice if the user want to delete it or not. If the user
confirm, the customer will be delete. I assign the add event to the add button, if the user want to add a customer, it will transfer to
the add form. And finally i make the exit button to exit the program.

28
In this add function to let the user to enter the customer information, and I also use the if statement to check if the information is
valid or not, if not the screen will display a notice for the user to re input the information. If the user press the button, all the
information will be saved.

29
In this form, I set a password for the user to enter the password, if the user enter wrong, the screen will display wrong so that the
user can enter again.

30
31
In this form, I use the foreach loop to access to each element to display it on the screen for the customer and user to see if they
want to. And I use the if statement to make sure that the screen will display all the information that I have input if the requirement
condition is fulfill. I also make the exit button for this function for the user to exit.

4. Program

When start program, there are 3 options for user to choose: View list, Edit list and Exit. Everyone can choose option 1
and 3, but option 2 for only manager and need password to enter (password: 123456). If enter wrong password,
program will notify.

Figure 10 - Start the program

 Choose option 1: List of Customer.

32
An interface will be display on the screen, including list of tenants and clear details of each person.

Figure 11 - Interface of option 1

When we choose one row on the table, the information of person on selected row will display on boxes which are located on the left
from table.

33
Figure 12 - Show clearly information of each person

And press Exit button to exit interface of Option 1.

 Choose option 2:
The user need to know password to enter this function (Password: 123456). The interface when login will look like the figure
10 and this is the interface of the program when enter the right password:

34
Figure 13 - Interface of option 2

The interface of Option 2 is very similar with its in Option 1, but in Option 2, there are more buttons and more functions than in
Option 1 such as : Edit, Add, Delete and Bill.

 Edit function: Choose 1 customer and change information in Boxes then press Edit to change in list.

35
Figure 14 - Actions with Edit button

In this example, i changed the customer name from ( f.Name: Binh, l.Name: Nguyen Duc) to (f.Name: Thao, l.Name: Pham) and
some types of information also changed, too.

36
 Add function: Press button Add and new interface has been displayed on screen

Figure 15 - Add information interface

The user enter the tenant information into these boxes and press OK to add.

The new customer has been added into the list.

37
Figure 16 - Action with add function

 Delete function: Choose the customer you want to delete and press Delete button. The program will notify a confirm box to
make sure that you really want to delete that customer. If you press no, that customer won’t be deleted. If you press yes,
that customer will be deleted.

38
Figure 18 - Action with Delete button

 Bill function: Choose one customer you want to get money for rent, then press Bill button for calculating money

Figure 17 - Action with Bill button

39
After entering all the necessary information for calculate Electricity and Water Money, press Calculate button at section 1
and 2 to calculate money. In section 3, check the mount you have to pay, then tick it. After tick all checkboxes you need to
check, press check button then press calculate button to calculate money. After all, when you know money you have to pay
at section 1,2 and 3, press calculate button at section 4 to calculate total money.

Figure 19 - Example of Bill Function with a Customer

Then press the Exit button to exit.

40
 Choose option 3: Just exit and close the interface.

Bonus: If you enter wrong type of information, the program will notify you until you enter right type of them.

IV. IDE usage in development


1. What is IDE?
IDE is the Integrated Development Environment that provides the user interface for code development, testing and
debugging features. It helps to organize the project artifacts that are relevant to the source code of the software
application. It provides several tools and features to make the development easy and standardize based upon the
programming language the developer writes the code. The IDEs also have the functionalities to compile and interpret the
program.

Microsoft Visual Studio (MVS) is one program of IDE. It provides many functions that helps a lot when writing code.

2. Common IDE features


 Code completion capabilities
This feature is very convenient for writing code. Can only write some first characters of code what you want to write,
MVS will complete the code for you. Increase productivity and waste less time.

 Automatically checks for errors

41
When you finish a line of code, MVS will notify you that line is right or wrong by underline that code in red color.
Example: this line code is wrong and MVS has been notified you.

 Support split screen


Screen is divided for using many task, we can keep track them at the same time.

42
 Lists errors and allows debugging while building applications

 Translators

43
 Track performance details in real time
Help to manage information effectively, not to cause any damage for PC

44
 Auto Indentation
Easy to keep track, to read and follow the code, no difficult to understand.

 Toolbox
When creating a Window Forms Programing, we just drag and drop from the toolbox, which is very convenient.

45
V. Debugging
In the software development life cycle, writing code doesn’t take more time than finding and fixing bug. Debugging is a series
of finding bug in the program and fixing them in order to have high quality program. When finding defect in code is determined, you
need to know the main reason of that defect, which is called the debugging. When having any information about the main reason of
that defect, fixing the defect to make the program behavior as expected is very easy. Visual Studio IDE brings us many tools to debug
code as well as application. Some important feature of Visual Studio IDE for debugging is breakpoint, labeling and saving
breakpoints, putting conditions and filter on breakpoints, … And you can start debugging form Debug menu or just press F5 on
keyboard. (visualstudio, n.d.)

Figure 20 - Start debugging

46
Here is my program when it’s running normal.

47
I tried to debug with the Button1 first:

- Step 1: I change the “int ElecMn = Elec *3000” to “int ElecMn = Elec -3000”

Figure 21 - Debugging

48
- Step 2: Then I add the breakpoint at where I think the bugs would be

Figure 22 - Debugging

- Step 3: F10 to run step by step and here is the result :


In this step , there is something which is wrong and the result became -2898

Figure 23 – bugging

49
- Step 4: Finally , the problem is “int ElecMn = Elec -3000” so I change it back to “int ElecMn = Elec *3000” and the
program run normally.
-

Figure 24 - Fix the bug

VI. Coding standard


1. Name convention:
- Names representing types must be in mixed case starting with upper case.

Figure 25 - Name types

50
- Variable names must be in mixed case starting with lower case.

Figure 26 – Variables name

- Named constants (including enumeration values) must be all uppercase using underscore to separate words.

- Names representing methods or functions must be verbs and written in mixed case starting with upper case.

Figure 27 – Methods/ functions name

- Variables with a large scope should have long names, variables with a small scope can have short names.
- The name of the object is implicit, and should be avoided in a method name.

2. Statement convention:
- Complex conditional expressions should be avoided.

Figure 28 - Conditional expression

51
- Type conversions must always be done explicitly. Never rely on implicit type conversion.

Figure 29 - Conversions typing

3. Layout
- White Space:

Figure 30 - White space layout

- Logical units within a block should be separated by one blank line.

Figure 31 - Separate logical units

52
- Use alignment wherever it enhances readability.

4. Commenting and Documenting

Figure 31 - Commenting Example

VII. Conclusion
After finishing this report, I have learnt many things about Procedural Programming, Object-oriented programing and Event-
driven programming. I have known about the feature of IDE in Visual Studio, debugging and code standard. About my
program, maybe it is not perfect program, but I have done my best in it.

53
Bibliography
(n.d.). Retrieved from visualstudio: https://code.visualstudio.com/docs/editor/debugging

(n.d.). Retrieved from kodify: https://kodify.net/csharp/visual-studio/debug-watch/

(n.d.). Retrieved from perforce: https://www.perforce.com/resources/qac/coding-standards

(2018, 10 12). Retrieved from geeksforgeeks: https://www.geeksforgeeks.org/introduction-of-programming-paradigms/

(2021, 4 30). Retrieved from softwaretestinghelp: https://www.softwaretestinghelp.com/debugging-techniques-in-selenium/

54

Powered by TCPDF (www.tcpdf.org)


Index of comments

1.1 Correct types of programming paradigms but lack how you apply them into your program

Correct scenario, problem and solution

Correct program that meet requirements of assignments.

Correct debugging process and coding standards.

Incorrect academic refs.

Powered by TCPDF (www.tcpdf.org)

You might also like