Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

ASSIGNMENT 1

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Prog102: Procedural Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Ho Tran Minh Hung Student ID GCD19899

Class GCD0904 Assessor name Phan Thanh Tra

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

Grading grid

P1 P2 P3 M1 M2 D1

1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

2
Table of contents

TASK 1 . INTRODUCTION TO COMPUTER PROGRAMMING


LANGUAGES,C LANGUAGES AND DISCUSS KEY FEATURES OF
PROCEDURAL PROGRAMMING.......................................................6

1.1. About programing languages...................................................6

1.2 . About procedural programming..............................................7


1.2.1 Simple program.........................................................................7
1.2.2 Variable.....................................................................................8
1.2.3 Three contructions(consequence, selection, iteration with 6
statements)......................................................................................10
1.2.4 Functions.................................................................................11
1.2.5 Value passing..........................................................................12
1.2.6 Parameter passing..................................................................13
1.2.7 Data Type................................................................................13
1.2.8 Modularity..............................................................................14

TASK 2. DESIGN PROCEDURAL PROGRAMMING SOLUTIONS.........14

2.1 Variables and data types and its scope....................................14


2.1.1 In variables and out variables.................................................14
2.1.2 Switch - case / Selection variables..........................................15

2.2 The required construction for the solution..............................15


2.2.1 Selection structure..................................................................15
2.2.2 Switch-case statement............................................................16
2.2.3 If-else Structures.....................................................................17
2.2.4 For statement.........................................................................18
2.2.5 While statement.....................................................................18

3
2.2.6 Do-While statement...............................................................19

2.3 functions and hierarchy diagram of the program.....................20


2.3.1 Enter the id.............................................................................20
2.3.2 Enter the grades......................................................................20
2.3.3 Enter the number student......................................................21
2.3.4 Select keys menu....................................................................21
2.3.5 Hierarchy Diagram of the Scenario Program..........................21

TASK 3. DESIGN A PROCEDURAL PROGRAMING SOLUTION FOR A


GIVEN PROBLEM...........................................................................22

3.1 Use-Case diagram...................................................................22

3.2 Flow Chart for Scenario Program.............................................23


3.2.1 Flow Chart : Menu Operation.................................................23
3.2.2 Flow Chart : Input Student’s ID And Grade............................24
3.2.3 Flow Chart : Input Students List..............................................24
3.2.4 Flow Chart : Display Student List With Name, ID and Grade..25
3.2.5 Flow Chart : Find the Student with highest Grade.................25
3.2.6 Flow Chart : Find the Student with lowest Grade..................26
3.3 General overview of my solution...............................................26

INDEX OF COMMENTS..................................................................27

4
Table of Figures
Figure 1: Programming language illustration.........................................................................................6
Figure 2 : How computer store and execute a program........................................................................6
Figure 3 : How computer can understand programming languages......................................................7
Figure 4 : Procedural oriented programing...........................................................................................7
Figure 5 : Simple program to display Hello world to the screen............................................................8
Figure 6 : Flow chart Hello, World! Program.........................................................................................8
Figure 7..................................................................................................................................................8
Figure 8..................................................................................................................................................9
Figure 9..................................................................................................................................................9
Figure 10..............................................................................................................................................10
Figure 11 : Three contructions in programming..................................................................................11
Figure 12 : Functions in Procedural Programming...............................................................................12
Figure 13 : Example for Parameter Passing.........................................................................................13
Figure 14 : Example about Data Type..................................................................................................13
Figure 15 : Modularity in Program.......................................................................................................14
Figure 16..............................................................................................................................................15
Figure 17..............................................................................................................................................15
Figure 18 : Example about Selection Structure....................................................................................16
Figure 19 : Switch Case Structures.......................................................................................................17
Figure 20..............................................................................................................................................17
Figure 21..............................................................................................................................................18
Figure 22 : The syntax of the for..........................................................................................................18
Figure 23 : Diagram for While Loop.....................................................................................................19
Figure 24 : Diagram for Do-While Loop...............................................................................................20
Figure 25..............................................................................................................................................20
Figure 26..............................................................................................................................................20
Figure 27..............................................................................................................................................21
Figure 28..............................................................................................................................................21
Figure 29 : Hierarchy Diagram of the Scenario Program......................................................................22
Figure 30 : Use Case Diagram for Scenario Program...........................................................................23
Figure 31 : Menu Operation Flow Chart..............................................................................................23
Figure 32 : Input Student List Flow Chart.............................................................................................24
Figure 33 : Display Students List Flow Chart........................................................................................25
Figure 34 : Find the Student with highest Grade Flow Chart...............................................................25
Figure 35 : Find the student with lowest Grade Flow Chart................................................................26

5
Task 1 . introduction to computer programming
languages,C languages and discuss key features of
procedural programming.
1.1. About programing languages.
Along with the development of technology, computers were born for us to use.
And so that the computer can understand what we want and do what we want.
Programming languages have been created for us to use so that computers can
understand us.

Figure 1: Programming language illustration

Arcording to Wikipedia, “A computer program is stored as a file on the computer's


hard drive. When the user runs the program, the file is read by the computer, and
the processor reads the data in the file as a list of instructions. Then the computer
does what the program tells it to do” (Anon., n.d.)

Figure 2 : How computer store and execute a program


“A computer program is written by a programmer. It is very difficult to write in the
ones and zeroes of machine code, which is what the computer can read, so
computer programmers write in a programming languages, such as BASIC, C, or Java.
Once it is written, the programmer uses a compiler to turn it into a language that the
computer can understand” (Anon., n.d.)

6
Figure 3 : How computer can understand programming languages

1.2 . About procedural programming


Procedural programming is a method of breaking down large problems for ease
of programming and testing.

Figure 4 : Procedural oriented programing

In simple terms, procedural programming is writing instructions that tell the


computer step-by-step how to complete a task.
Key features of procedural programming:

1.2.1 Simple program


This is simple program to illustrate about procedural programming with C
languages.

7
Figure 5 : Simple program to display Hello world to the screen

The output of the program is display : “Hello, World” to the screen.

We can input different string inside quotation (“…”) to display the text to the screen.

This is the flowchart of this program.

Figure 6 : Flow chart Hello, World! Program

1.2.2 Variable
in C language, variable is a named memory area so that when we want to use some
data value in our program for different purposes.

Figure 7

8
Variables declaration:

Figure 8

*Local variable

The scope of local variables will be within the function only.

These variables are declared within the function and can’t be accessed outside the
function.

Figure 9

*Global variable

The scope of global variables will be throughout the program.

9
These variables can be accessed from anywhere in the program.

Figure 10

10
1.2.3 Three contructions(consequence, selection, iteration with 6 statements)
Based on specific reference source, there are the ways to control the lines of code
- Sequencing: This means that the computer will run your code in order, one line at a
time from the top to the bottom of your program. It will start at line 1, then execute line
2 then line 3 and so on till it reaches the last line of your program. (Anon., 2015)
- Selection: Sometimes you only want some lines of code to be run only if a condition is
met, otherwise you want the computer to ignore these lines and jump over them. This
is achieved using IF statements. e.g. If a condition is met then lines 4, 5, 6 are
executed otherwise the computer jumps to line 7 without even looking at line 4,5 and
6. (Anon., 2015)
- Iteration: Sometimes you want the computer to execute the same lines of code several
times. This is done using a loop. There are three types of loops: For loops, while loops
and repeat until loops. That’s handy as it enables you not to have to copy the same
lines of code many times. (Anon., 2015).

Figure 11 : Three contructions in programming

1.2.4 Functions
Function is a block of instructions that perform a certain function. In C
languages, it required at least one function, which is main() and additional
functions.

For different purposes, you can divide the code into separate functions.

we have 2 types of functions in C languages : Library functions and User-


defined functions.

11
Figure 12 : Functions in Procedural Programming

1.2.5 Value passing


“When a function gets executed in the program, the execution control is transferred
from callingfunction to called function and executes function definition, and finally
comes back to the calling function. When the execution control is transferred from
calling-function to called-function it may carry one or number of data values. These
data values are called as parameters” (Anon., n.d.)
In C, there are two types of parameters and they are as follows...
- Actual parameters: The parameters that appear in function calls.
- Formal parameters: The parameters that appear in function declarations.

We have two methods to pass parameters from calling function to called function,
based on different reference sources.

Call by Value Call by Reference


“The call by value method of passing arguments to “The call by reference method of passing arguments to
a function copies the actual value of an argument a function copies the address of an argument into the
into the formal parameter of the function. formal parameter.
In this case, changes made to the parameter Inside the function, the address is used to access the
inside the function have no effect on the actual argument used in the call. It means the changes
argument” made to the parameter affect the passed argument

12
1.2.6 Parameter passing
“Parameter Passing is a mechanism used to pass parameters to functions, subroutines or
procedures. Parameter Passing can be done through ‘pass by value’, ‘pass by reference’,
‘pass by result’, ‘pass by value-result’ and ‘pass by the name’”. (Bhatia, 2020)

Figure 13 : Example for Parameter Passing

1.2.7 Data Type


C divides the data into different groups which is the data type.

Figure 14 : Example about Data Type

13
1.2.8 Modularity
“Modularity is when two dissimilar systems have two different tasks at hand but are
grouped together to conclude a larger task first. Every group of systems then would have its
own tasks finished one after the other until all tasks are complete.” (Bhatia, 2020)

Figure 15 : Modularity in Program

Task 2. DESIGN PROCEDURAL


PROGRAMMING SOLUTIONS
2.1 Variables and data types and its scope
2.1.1 In variables and out variables
In variables

Int : for storing Student’s ID.

Char : for storing Student’s Name.

Float : for storing Student’s Grade.

Out variables

He list of students that the user enters.

Information of student has the highest with grades.

Information of student has the lowest with grades.

14
Figure 16

This function will be responsible for displaying the menu and the programmed
options based on user requirements.

2.1.2 Switch - case / Selection variables

Figure 17

Case 1: Create list student.

Case 2: Display list student.

Case 3: Find and print the ID and the grades of student has highest grades.

Case 4: Find and print the ID and the grades of student has lowest grades.

Default: Print error.

2.2 The required construction for the solution


2.2.1 Selection structure
“A selection structure also known as a conditional structure, this is a programming feature that can
performs different processes based on whether to check a condition is true or false.” (Anon., n.d.)

15
Figure 18 : Example about Selection Structure

2.2.2 Switch-case statement


Switch-case Structures use to design a menu options for user to help them determined what
function in program they want to use.

Switch-case statement is executed only once.

The switch case is used when we have multiple options and we want to compared the input value
with all the cases inside the switch..case block to execute different options.

16
Figure 19 : Switch Case Structures

2.2.3 If-else Structures


If … Else Structures use to test in certain condition and make decision about which code block need
to be executed.

If…else Structures to find the student have lowest grade the same with student have highest grade
with the condition is : the student in the current loop have grade lower than the grade of student in
the previous loop, then returns the student with the lower grade in current loop.

The If-else statement is executed twice.

Figure 20

17
Figure 21

2.2.4 For statement


For is a more efficient loop construct in ‘C’ programming.

Figure 21 : The syntax of the for

Figure 22 : The syntax of the for

For helps us to display all student user add and find the students with the highest and lowest scores.

The initialization statement is executed three times.

2.2.5 While statement


A while loop in C programming repeatedly executes a target statement as long as a given condition is
true.

18
Figure 23 : Diagram for While Loop

Here, statements may be a single statement or a block of statements. The condition may be any
expression, and true is any nonzero value. The loop iterates while the condition is true.

When the condition becomes false, the program control passes to the line immediately following the
loop.

2.2.6 Do-While statement


Different from for statement and while statement checks the condition at the beginning of the loop,
do-while statement checks the condition at the end of the loop.

A do...while statement is similar to a while statement, except the fact that it is guaranteed to
execute at least one time.

19
Figure 24 : Diagram for Do-While Loop

The Do-while statement is executed twice.

2.3 functions and hierarchy diagram of the program


2.3.1 Enter the id

Figure 25

idHtmh is an integer. If input idHtmh <0, return idHtmh and input again.

2.3.2 Enter the grades

Figure 26

20
gradesHtmh is a float. Input grades.

2.3.3 Enter the number student

Figure 27

Enter the number of students. n = the number of students.

2.3.4 Select keys menu

Figure 28

User has 4 choice.

2.3.5 Hierarchy Diagram of the Scenario Program

21
Figure 29 : Hierarchy Diagram of the Scenario Program

TASK 3. DESIGN A PROCEDURAL


PROGRAMING SOLUTION FOR A GIVEN
PROBLEM
3.1 Use-Case diagram
Arcording to Wikipedia, “Use Case Diagram is a representation of a user's interaction with the
system that show the relationship between the use and the different use cases in which the user is
involved” (Anon., n.d.).

This is the Use Case Diagram for my Scenario Program.

22
Figure 30 : Use Case Diagram for Scenario Program

3.2 Flow Chart for Scenario Program


Arcording to Wikipedia, “A flowchart is a type of diagram that represents a workflow or process. A
flowchart can also be defined as a diagrammatic representation of an algorithm, a step-bystep
approach to solving a task” (Anon., n.d.)

3.2.1 Flow Chart : Menu Operation

Figure 31 : Menu Operation Flow Chart

23
3.2.2 Flow Chart : Input Student’s ID And Grade

Figure 31 : Input Student's ID and Grade Flow Chart

3.2.3 Flow Chart : Input Students List

Figure 32 : Input Student List Flow Chart

24
3.2.4 Flow Chart : Display Student List With Name, ID and Grade

Figure 33 : Display Students List Flow Chart

3.2.5 Flow Chart : Find the Student with highest Grade

Figure 34 : Find the Student with highest Grade Flow Chart

25
3.2.6 Flow Chart : Find the Student with lowest Grade

Figure 35 : Find the student with lowest Grade Flow Chart

3.3 General overview of my solution


create a software that can update student information and display all student information added
user. Find and display the student with the highest and lowest scores

26
Index of comments

27

You might also like