You are on page 1of 16

ASSIGNMENT 1 FRONT SHEET

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 Vu Quang Anh Student ID GCH210928

Class GCH1102 Assessor name Dinh Duc Manh

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
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Contents
List of figure ................................................................................................................................................... 4
INTRODUCTION .......................................................................................................................................... 4
P1: Procedural Programming ......................................................................................................................... 4
1. Definition: ............................................................................................................................................... 4
M1: CHARACTERISTICS OF THE PROGRAMMING PROCESS . ......................................................... 5
1. Predefined functions: ............................................................................................................................ 5
2. Local Variable: ...................................................................................................................................... 6
3. Global Variable: .................................................................................................................................... 6
4. Modularity: ............................................................................................................................................ 6
5. Parameter Passing: ............................................................................................................................... 6
P2: Analysis .................................................................................................................................................... 6
I. variables and data types required in the program. .................................................................................. 6
II. Selection Structure: ................................................................................................................................. 7
1. Switch Structure: ..................................................................................................................................... 7
2. If .............................................................................................................................................................. 7
III. iteration constructs .............................................................................................................................. 8
1. For ........................................................................................................................................................... 8
2. Do-While ................................................................................................................................................. 9
IV. Function of program ............................................................................................................................ 9
1. sub-functions ........................................................................................................................................... 9
2. hierarchy diagram ................................................................................................................................... 9
P3. Diagram .................................................................................................................................................. 10
1. Action required ..................................................................................................................................... 10
2. Main menu and displaying .................................................................................................................... 12
3. Print ID and grade ................................................................................................................................. 13
4. Find highest grade and lowest grade ..................................................................................................... 14
References .................................................................................................................................................... 16
List of figure
Figure 1: Procedural Programming ................................................................................................................ 5
Figure 2. Switch structure .............................................................................................................................. 7
Figure 3: for loop ........................................................................................................................................... 8
Figure 4: hierarchy diagram ......................................................................................................................... 10
Figure 5: Action required ............................................................................................................................. 11
Figure 6: main menu..................................................................................................................................... 12
Figure 7: print ID and menu ......................................................................................................................... 13
Figure 8: find student has highest grade ....................................................................................................... 14
Figure 9: find student has lowest grade ........................................................................................................ 15

INTRODUCTION
Programming is writing computer code to create a program, to solve a problem. Programs are created to
implement algorithms. Algorithms can be represented as pseudocode or a flowchart, and programming is
the translation of these into a computer program.

P1: Procedural Programming


1. Definition:
Procedural Programming is likely to be a new developer's first programming paradigm. Procedural code,
in its most basic form, is the code that tells a device how to complete a task in logical steps. This paradigm
takes a top-down, linear approach to data and methods, and sees them as two distinct things. Procedural
Programming separates a program into procedures, which are sometimes known as routines or functions
and simply comprise a set of actions to be carried out, based on the concept of a procedure call.

Simply put, procedural programming is laying down a list of instructions that teach the computer how to
complete a task step by step. (Bhatia, 2022)
Figure 1: Procedural Programming

Advantages

• Procedural Programming is excellent for general-purpose programming


• The coded simplicity along with ease of implementation of compilers and interpreters
• A large variety of books and online course material available on tested algorithms, making it easier
to learn along the way
• The source code is portable, therefore, it can be used to target a different CPU as well
• The code can be reused in different parts of the program, without the need to copy it
• Through Procedural Programming technique, the memory requirement also slashes
• The program flow can be tracked easily

Disadvantages

• The program code is harder to write when Procedural Programming is employed


• The Procedural code is often not reusable, which may pose the need to recreate the code if is
needed to use in another application
• Difficult to relate with real-world objects
• The importance is given to the operation rather than the data, which might pose issues in some
data-sensitive cases
• The data is exposed to the whole program, making it not so much security friendly

M1: CHARACTERISTICS OF THE PROGRAMMING


PROCESS .
1. Predefined functions:
A predefined function is typically an instruction identified by a name. Usually, the predefined
functions are built into higher-level programming languages, but they are derived from the library
or the registry, rather than the program. One example of a pre-defined function is ‘charAt()’, which
searches for a character position in a string.

2. 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 it is given. The local variable can only be used in the method it is defined in, and if it
were to be used outside the defined method, the code will cease to work.

3. Global Variable:
A global variable is a variable which is declared outside every other function defined in the code.
Due to this, global variables can be used in all functions, unlike a local variable.

4. 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.

5. 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’.

P2: Analysis
I. variables and data types required in the program.

variables data types Reason

Student ID ID Int

Student’s grade Grade Float Student’s grade is a real number


from 0 to 10
Student has highest Highest grade Float Student’s grade is a real number
grade from 0 to 10
Student has lowest Lowest grade Float Student’s grade is a real number
grade from 0 to 10
Name student Name[20] Char use to enter the maximum name of
20 character
Menu n Int The option are numbered from 1
to 5
II. Selection Structure:
1. Switch Structure:
A variable's value is examined and compared to other scenarios in a C switch statement.
After the case match has been determined, a block of statements relating to that specific
case is executed. Each case in a switch block has its own identifier, which is a unique name
or number. Until a match is found, the user-supplied value is compared to each case within
the switch block. If no case match is discovered, the default statement is executed, and
control departs the switch block.(Thompson, 2022)

Figure 2. Switch structure


Switch structure can be used in place if-else-if statements
Used in situations where the expression being evaluated results in multiple values.
- Case 1 input ID and student
- case 2 print list id student and name
- case 3 Print the list student has highest grade.
- case 4 Print the list student has lowest grade.
- case 5 exit

2. If
The If statement is in charge of changing a program's execution flow. A condition is always
used with an if statement. Before executing any statement within the body of If, the
condition is evaluated first. (Thompson, 2022)
III. iteration constructs
1. For
A for loop is a repetition control structure that allows you to efficiently write a loop that
needs to execute a specific number of times.

Figure 3: for loop

• Step 1: Initialize the iterator value, only do it once

• Step 2: Check the loop condition, if the condition is false

=> Go to step 5

• Step 3: Execute the loop content inside the loop body

• Step 4: Update the iterator value => Go back to Step 2

• Step 5: End the loop


2. Do-While
In C, a do...while loop is similar to a while loop, with the exception that the condition is
always run after the loop's body. An exit-controlled loop is another name for it.

Do-While loop can help us do menu in program

Unlike the for statement, the Do-while statement checks the condition at the end of the
loop.

IV. Function of program


1. sub-functions
Input information of students
Function Input Output
1. Enter the student's IDs. ID of student The ID of student.

2. Enter the grades. Grade of student The student's grade.

3. Find the students This function doesn't List of students who


have highest grade need the input have highest grade

4. Find the students This function doesn't List of students who


have lowest grade need the input have lowest grade

2. hierarchy diagram
Figure 4: hierarchy diagram

P3. Diagram
1. Action required
Figure 5: Action required

To save grades and student IDs in the program's memory, the teacher must first input them. The teacher
can then select any task, such as viewing all students' grades and IDs. Find the highest or lowest . After
selecting one of the alternatives, the application will return to the main menu, where you can select
another option or exit the program.
2. Main menu and displaying

Figure 6: main menu


> Explain flow chart :
Step 1. Start
Step 2. Set menu
Step 3. Set choice
Step 4. Case 1: input student information
Step5. Case 2: print information student and go back step 2
Step 6. Case 3,4: find highest grade and lowest grade. If true it print student has highest grade or
lowest grade and go back to menu
Step 7. Case 5: Exit program
Step 8. If 5 case not true, then it will down to Default, it print Invalid please choose again
Step 9. End program
3. Print ID and grade

Figure 7: print ID and menu

Explain flowchart
Step 1: start
Step 2: Declare float int i, float grade
Step 3: check condition
Step 4: print ID and grade
Step 5: increase by 1
Step 6: go back step 3
Step 7. Go to step 4 if done step 6 and get true step 3
Step 8: end
4. Find highest grade and lowest grade
a. Find highest grade

Figure 8: find student has highest grade

Explain flowchart:
Step 1: start
Step 2: declare variable float max, int i
Step 3: check condition if true then go to next step, if false print max grade
Step 4: check condition max < list[i].grade. if true, set max = list[i].grade
Step 5: increased by 1 unit and repeat step 3
Step 6: end
b. Find lowest grade

Figure 9: find student has lowest grade

Explain flowchart

Step 1: start
Step 2: declare variable float min, int i
Step 3: check condition if true then go to next step, if false print min grade
Step 4: check condition min > list[i].grade. if true, set min = list[i].grade
Step 5: increased by 1 unit and repeat step 3
Step 6: end
References
Bhatia, S., 2022. [Online]
Available at: https://hackr.io/blog/procedural-programming
[Accessed 14 june 2022].

Naveen, 2022. intellipaat. [Online]


Available at: https://intellipaat.com/blog/tutorial/c-tutorial/c-data-types/
[Accessed 15 june 2022].

Thompson, B., 2022. [Online]


Available at: https://www.guru99.com/c-if-else-statement.html#2
[Accessed 21 june 2022].

veer, 2021. btechgeeks. [Online]


Available at: https://btechgeeks.com/c-programming-language-variables/
[Accessed 15 june 2022].

You might also like