Assignment 1: Qualification BTEC Level 5 HND Diploma in Computing

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

ASSIGNMENT 1

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 0: Procedural Programming

Submission date October 10, 2020 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyễn Xuân Quyến Student ID GCH190732

Class GCH0901 Assessor name Lai Manh Dung

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 Quyen

Grading grid

P1 P2 P3 M1 M2 D1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Table of Contents
Table of Diagrams .......................................................................................................................................... 4

Table of Figure ............................................................................................................................................... 4

Table of Codes................................................................................................................................................ 4

I. Introduction to procedural programming: ............................................................................................... 5

1. Introduction to Computer Programming Languages: .......................................................................... 5

2. Introduction to Procedural Programming: ........................................................................................... 7

II. Identify the program units and data and file structures: ...................................................................... 9

1. Identify the variable and data type required in the program: .............................................................. 9

2. Identify and describe 2 different selection structures, including the condition(s) to check; state why
they are needed and where they can be used in the context of the scenario. ............................................. 9

3. Identify and describe iteration constructs: ......................................................................................... 12

4. Split the program into functions (sub-functions) and draw a hierarchy diagram to illustrate the
structure of your program: ........................................................................................................................ 15

a. Split the program into functions: ................................................................................................... 15

b. Draw a hierarchy diagram to illustrate the structure of your program: ......................................... 15

III. Design the program using: use-case diagram and Flowchart: ........................................................... 16

1. A use case diagram for actions required: .......................................................................................... 16

2. Flowchart diagrams: .......................................................................................................................... 17

IV. Review / evaluate your design, state clearly pros vs cons and which needs to improve, using
characteristics of procedural programming as bases to discuss: .................................................................. 21

1. Menu operation: ................................................................................................................................ 21

2. Print ID and point: ............................................................................................................................. 21

3. Finding max grade and finding min grade: ....................................................................................... 21

References .................................................................................................................................................... 22
Table of Diagrams
Diagram 1: Diagram illustrate the structure of program .............................................................................. 15
Diagram 2: Use-case diagram of required actions ....................................................................................... 16
Diagram 3: Flowchart diagram menu operation........................................................................................... 17
Diagram 4: Flow chart diagrams printing ID and grade .............................................................................. 18
Diagram 5: Flow chart diagrams finding max grade .................................................................................... 19
Diagram 6: Flow chart diagrams finding min grade .................................................................................... 20

Table of Figure
Figure 1: Divide of programming languages (Beal, 2017) ............................................................................ 6
Figure 2: Programming paradigms (Anon., 2018) ........................................................................................ 6
Figure 3: The flow chart of “If…else” statement ......................................................................................... 10
Figure 4: The flow chart of “Switch-case” statement .................................................................................. 11
Figure 5: Flow chart of “For” loop ............................................................................................................... 13
Figure 6: Flow Diagram of “do…while” ..................................................................................................... 14

Table of Codes
Code 1: "Hello world !" in Java .................................................................................................................... 5
Code 2: "Hello world !" in C ......................................................................................................................... 5
Code 3: Example about procedural programming ........................................................................................ 8
Code 4: "If' Statement Function ................................................................................................................. 10
Code 5: “Switch-case” Statement Function ................................................................................................ 12
Code 6: For-Loop to find highest mark ....................................................................................................... 13
Code 7: For-loop to printf to the screen ...................................................................................................... 14
I. Introduction to procedural programming:

1. Introduction to Computer Programming Languages:


Computer programming language is a standardized language according to a particular set of rules, so that a
programmer can describe working programs for electronic equipment that are both human and that device
understands. (Nguyễn, 2019)

The term programming language usually refers to high-level languages, such as: Python, Java, C, C++, C#,
PHP, …Each of these programming languages has similarities and differences, standardized against a set of
separate rules.

Example: Some hello world programs of some computer programming languages:

Code 1: "Hello world !" in Java

Code 2: "Hello world !" in C


- Divide programming languages:
Figure 1: Divide of programming languages (Beal, 2017)

• Machine Language: is the base language of the processor. Programs written in all other languages
are eventually converted to the machine language before that program is executed. Instructions in
the machine language are represented as binary codes. This is the only language a microprocessor
can directly detect and execute. (Nguyễn, 2019)
• Assembly language: is a low level programming language for computers. The assembly is converted
to machine code that is executed by a named utility program a compiler like NASM, MASM, etc.
• High-level programming language: is a programming language with a form close to a natural
language, with high independence, less dependent on the type of device (processor type) as well as
the compilers. Some popular high-level programming languages today such as C, C ++, Java, Pascal,
PHP, Visual Basic. (Nguyễn, 2019)

Figure 2: Programming paradigms (Anon., 2018)


2. Introduction to Procedural Programming:
Procedural programming is a programming paradigm, rooted in structured programming, based on the
concept of procedure invocation. A procedure (a type of procedure or subroutine) simply contains a series
of computational steps to be performed. Any given procedure can be invoked at any time during program
execution, including other procedures or itself. The procedural method divides a large program into
functional blocks or functions (procedures) that are small enough to be easily programmed and tested.
(Wikipedia, 2020)

Key features of procedural programming:

• Predefined functions: A predefined function is usually a command defined by name. Usually,


predefined functions are built in higher level programming languages, but they are derived from
libraries or registers, not programs.
• Local variable: A local variable is a variable that is declared in the main structure of a method and
is limited to the local scope in which it is provided. The local variable can only be used within the
method for which it is defined, and if it is used outside of the method specified, the code will stop
working.
• Global variable: A global variable is a variable declared outside of any other function defined in
the code. Therefore, global variables can be used in all functions, unlike a local variable.
• Modularity: when two different systems have two different quests but are grouped together to end
a larger quest than before.
• Parameter passing: Parameter passing is a mechanism used to pass parameters to functions,
subroutines, or procedures. (Bhatia, 2020)

Example:
Code 3: Example about procedural programming
- In the C language programming example, predefined functions are represented by main function,
display function with specified data types. They are declared in the library #include <stdio.h>, with
commands with specific names such as: scanf, printf, ...
- In the example, the global variable is: int benngoai = 1000; This variable is declared outside of any
other function defined in the code. Therefore, a global variable can be used in all functions, unlike a
local variable, it is used in both main () and display ().
- In the example, local variables are: int a, int b; It is declared in the display () and main () functions
that are limited to the local scope in which it is provided. The local variable can only be used within
the method it was defined in, and if it is used outside the method specified, the code will stop
working. They cannot be shared for different functions.
- In the example, we use display () and main () as two independent functions, the problem is divided
into such sub-functions but grouped together to end a larger task, it represents the modularity of
procedural programming.
- In the example: int sum(int & x, int & y), the purpose is to find the address of x and y in the program
to pass the value to it.
II. Identify the program units and data and file structures:

1. Identify the variable and data type required in the program:


• Declare the number of students need to enter scores, we use variable “size”, type of integer:
Int size;
• Declare the variable char name [50] [50] to assign to the student's name when entering the program
Char name [50] [50];
• Because the student's ID is an integer, so we declare the array, the integer type with the array name
"IDs '", the element number is 100:
Int IDs [50];
• Because the student's score can be of type decimal so we declare the array, with the float type with
the array name "grade '", the element number is 100:
Float grade [50];
• “Float max”, “float min” to represent student's highest score and highest score:
Float max = 0, min=10;
• Declare the variables “imax and imin”, type integer to find the student with the highest score and
the lowest score:
Int imax = 0, imin=0;
• Int choice shows the choice that user choose in menu:
Int choice;
• Int i, used for loop function and be numeral number in array function:
Int i;

2. Identify and describe 2 different selection structures, including the condition(s) to


check; state why they are needed and where they can be used in the context of the
scenario.
• “If” or “if-else” statement function:
Figure 3: The flow chart of “If…else” statement
Used to check if a certain conditional expression in parentheses is true, if true then executes the
statements inside the if block and vice versa, it will ignore those statements or it will execute the
code is in "else".
In my program, the "if" statement is used to find the highest or lowest score of the student and used
to check the teacher's input condition, if there is no input then data is not display on the screen.
Example:

Code 4: "If' Statement Function


max is the highest mark, if the element is smaller than max (the condition is true), max will be the
element.
• Switch statement function:

Figure 4: The flow chart of “Switch-case” statement


“Switch” statement is a multiway branch statement. "Switch" compares an integer expression with
a list of values of integers, literal constants or constant expressions. Each value in the list is a “case”
in the switch block. In the "switch" block there can also be a “default” case that may or may not be.
On the other hand, in each case there are blocks of statements waiting to be executed.
In my program I use the "Switch-case" structure to create option buttons in the menu panel of the
program.
Code 5: “Switch-case” Statement Function
In my program, there are many options such as: Input Student; Find highest mark, Lowest Mark; Exit…

3. Identify and describe iteration constructs:


• For Loop:
Figure 5: Flow chart of “For” loop
For Loop has the function of allowing the execution of a command and a group of instructions
multiple times under certain conditions. If the condition becomes true, the loop will be executed, if
the condition is false the loop exits.
So I use the for loop in my program, this function compares “max”, “min” with elements we put in
memory and make a routine to find the highest and lowest. It can also be used to print IDs and grades
of all students on the screen.

Code 6: For-Loop to find highest mark


Code 7: For-loop to printf to the screen

• Do-while:

Figure 6: Flow Diagram of “do…while”


Do while function is a loop function. But it’s different with “While” function a little: “Do while”
function will execute the code at least once and then check the condition next. Perform at least once
even if the condition is wrong from the beginning.
In my program, I use the Do while function to create a Menu, when running a selection, the program
will let you continue to select other options of the program.
4. Split the program into functions (sub-functions) and draw a hierarchy diagram to
illustrate the structure of your program:
a. Split the program into functions:
- Function: Void INPUT
- Function: Void DISPLAY
- Function: Void FIND HIGHEST GRADE, LOWESR GRADE
- Advantages by using sub-functions:
❖ first the program will be shorter than usual
❖ Reduce the risk of error.
❖ Divide a big problem by making small problems for easy handling.
❖ I can avoid code repeating in my program.
❖ Computers can read the program more easily.
❖ Last but not least, convenience when modifying programs, upgrading or maintaining.

b. Draw a hierarchy diagram to illustrate the structure of your program:

Diagram 1: Diagram illustrate the structure of program


III. Design the program using: use-case diagram and Flowchart:

1. A use case diagram for actions required:

Diagram 2: Use-case diagram of required actions


2. Flowchart diagrams:

• Flow chart diagrams menu operation:

Diagram 3: Flowchart diagram menu operation


• Flow chart diagrams printing IDs and grades:

Diagram 4: Flow chart diagrams printing ID and grade


• Flow chart diagrams finding max grade:

Diagram 5: Flow chart diagrams finding max grade


• Flow chart diagrams finding min grade

Diagram 6: Flow chart diagrams finding min grade


IV. Review / evaluate your design, state clearly pros vs cons and which
needs to improve, using characteristics of procedural programming
as bases to discuss:

C is a basic programming language, the foundation for all programmers to learn to code, it is the basis for
learning more advanced languages.

Although the program runs normally and shows what is needed, it has not been optimized. Some comments
about the program:

1. Menu operation:
We should use a "switch-case" structure instead of "if-else", which in my opinion is easier to understand.

2. Print ID and point:


I use for loop instead of while loop to print student IDs in turn with their scores because loop "For" will
assign the student's score and ID in order of turn, and when printed it will Exactly. However the time to
enter the IDs and points is quite time consuming.

3. Finding max grade and finding min grade:


Advantages: Easy to understand. Simple to users. We can access any element in the array by specifying an
index for that element.

Disadvantages: Two separate arrays are difficult to manage. It takes time to check the elements of the two
arrays in turn to find the smallest and largest values.
References
Anon., 2018. geeksforgeeks. [Online]
Available at: https://www.geeksforgeeks.org/introduction-of-programming-paradigms/
[Accessed 7 October 2020].

Beal, V., 2017. webopedia. [Online]


Available at: https://www.webopedia.com/TERM/P/programming_language.html
[Accessed 7 October 2020].

Bhatia, S., 2020. hackr.io. [Online]


Available at: https://hackr.io/blog/procedural-programming
[Accessed 7 October 2020].

Nguyễn, T., 2019. Hocban.vn. [Online]


Available at: https://hocban.vn/ngon-ngu-lap-trinh-la-gi
[Accessed 06 October 2020].

Nguyễn, T., 2019. Hocban.vn. [Online]


Available at: https://hocban.vn/phan-loai-ngon-ngu-lap-trinh
[Accessed 7 October 2020].

Wikipedia, 2020. Wikipedia. [Online]


Available at: https://en.wikipedia.org/wiki/Procedural_programming
[Accessed 7 October 2020].

You might also like