You are on page 1of 30

Higher Nationals in Computing

Unit 0: Procedural Programming


ASSIGNMENT 1

Learner’s name: PHẠM NGUYỄN QUỲNH NHƯ


ID: GCS210018
Class: GCS1005A
Subject code: PROG102
Assessor name: PHAN MINH TAM

Assignment due: Assignment submitted:


ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 0: IT Fundamental & Procedural Programming

Submission date Date Received 1st submission

Re-submission Date Date Received 2nd submission

PHẠM NGUYỄN QUỲNH


Student Name Student ID GCS210018
NHƯ

Class GCS1005A Assessor name Phan Minh Tam

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:

Signature & Date:


ASSIGNMENT 1 BRIEF

Unit Number and Title Unit 0: IT Fundamental & Procedural Programming


Academic Year 2021
Unit Tutor
Assignment Title Assignment 1: Analysis and Design a solution for procedural programming
problem
Issue Date
Submission Date
IV Name & Date

Learning Outcomes and Assessment Criteria

Pass Merit Distinction

LO1 Understand the principles of procedural programming


LO2 Be able to design procedural programming solutions

P1 Provide an introduction to M1 Discuss on characteristics and D1 Critically evaluate the design of


procedural programming features of procedural your solution against the
programming characteristics and features of
procedural programming.
P2 Identify the program units and M2 Review the design of a
data and file structures required procedural programming
to implement a given design solution.

P3. Design a procedural


programming solution for a given
problem

Assignment Brief
Scenario:
A math teacher wants to manage grades of a class. He asks you to help him to write a small application to do
that. He needs to enter student IDs, student’s grades and store these information into 2 separate arrays
(integer array for IDs and float array for grades). Then he needs to print all student IDs together with their
grades. Finally, he needs to know which student has highest grade and lowest grade. Your program should be
menu based with the options above. When an option is done, the program should go back to the main menu so
he can choose another option. There should be an option to quit program.
Task 1
To prove your programming ability to be appointed to this small project, please prepare an illustrated guide on
programming in general and a particular emphasis on procedural programming. Here you will need to include
introduction to computer programming languages and discuss key features of procedural programming.
Task 2
Your next task is to do the analysis for the scenario mentioned above by doing the following subtasks
 Identify the variables and data types required in the program.
 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.
 Identify and describe any iteration constructs.
 Split the program into functions (sub-functions) and draw a hierarchy diagram to illustrate the
structure of your program.

Task 3
You need to use a drawing tool to draw design diagram for your program, includes:
 A use case diagram for actions required
 Flow chart diagrams for: menu operation, printing IDs and grades, finding max grade and finding min
grade.
 Review / evaluate your design, state clearly pros vs cons and which needs to improve, using
characteristics of procedural programming as bases to discuss.

Write a report for 3 tasks above and submit the report to CMS in PDF format.

Submission Format
The submission is in the form of an individual written report. This should be written in a concise, formal
business style using single spacing and font size 12. You are required to make use of headings, paragraphs and
subsections as appropriate, and all work must be supported with research and referenced using the Harvard
referencing system. Please also provide a bibliography using the Harvard referencing system.
Table of Contents

Unit 0: Procedural Programming ASSIGNMENT 1 1


P1. Provide an introduction to procedural programming. .............................................................................. 1
1. Definition ............................................................................................................ Error! Bookmark not defined.
1.1. Definition ....................................................................................................................................................1
1.2. Classify ........................................................................................................................................................ 1
2. Introduction to procedural programming .........................................................................................................2
2.1. Definition ....................................................................................................................................................2
2.2 .Introduction to C programming language ..................................................................................................3
P2. Identify the program units and data and file structures required to implement a given design .................. 4
1. Variables ............................................................................................................................................................ 4
1.1. Definition ....................................................................................................................................................4
1.2. Example ...................................................................................................................................................... 5
2. Data types ..........................................................................................................................................................5
2.1. Definition ....................................................................................................................................................5
2.2. Types if data types in C ...............................................................................................................................5
3. Selection structures (Conditional Statements) ................................................................................................. 6
A. If statement ...................................................................................................................................................6
B. If…else statement ..........................................................................................................................................7
C. If…else if statement .......................................................................................................................................8
A. Switch – case statement ............................................................................................................................... 9
4. Iteration structures ..........................................................................................................................................10
A. For statement ..............................................................................................................................................10
B. While statement ..........................................................................................................................................11
C. Do…while statement ................................................................................................................................... 12
.................................................................................................................................................................. 12
P3. Design a procedural programming solution for a given problem .............................................................12
1. Requirements for the given scenario: .........................................................................................................12
2. Use case diagrams ....................................................................................................................................... 13
3. Flowcharts ....................................................................................................................................................... 14
A. Input IDs and Grade .................................................................................................................................... 14
B. Show IDs and Grade .................................................................................................................................... 16
C. Print highest grade ...................................................................................................................................... 17
D. Print lowest grade .......................................................................................................................................19
4. Pseudo code .................................................................................................................................................... 20
4.1. Input Id and Grade ....................................................................................................................................20
4.2. Show IDs and Grade ................................................................................................................................. 21
4.3. Print highest grade ................................................................................................................................... 21
4.4. Print lowest grade .................................................................................................................................... 22
ASSIGNMENT 1 ANSWERS
P1. Provide an introduction to procedural programming.

1. Programming languages

1.1. Definition
- Programming language is a collection of rules of chain conversion or elements in
programs into codes that computers can understand and convert into different
machines outputs. Besides, the programming languages are also understood such as
a computer language and is used by programmers to make algorithms in the
program. Computer languages are often used to identify and manipulate the data
structure or control the execution.

- Ex: C, C++, Python, Java, etc

1.2. Classify
- Programming language is divided into 2 types:

o High level programming language: High -level language is the language that
programmers can write an independent program with a specific computer.
High -level languages are considered high -end and help programmers can
Page |1
understand easily and when running on computers we need a translator so
that the computer can understand and run easily. (ex: C#, FORTRAN, Pascal,
etc)

o Low level programming language: low -level language we can simply


understand that the parts close to the hardware that programmers can run
the code on it. Besides, programmers can define differently depending on
the purpose of the program. (ex: binary code, machine language)

2. Introduction to procedural programming

2.1. Definition
- Procedure programming can be the first programming model that a new
developer will learn. In other words, the procedure code is a direct code that
helps computers understand and complete the task according to logical steps.
Programming procedures will divide the program into procedures, also
considered as habits or functions, habits or functions just to contain a series of
steps done. Put simply, programming procedures will set out a series of
guidelines for computers to do to complete the assigned task.

- Programming procedures has the main features such as:


Page |2
o Predefined functions: the predefined functions are built up higher-level
programming languages, but they are obtained from the library or the
registry, rather than the program.

o Local Variable: local variables will be declared with structure and limits
within the local scope, programmers can only be used in the method of
decision and if outside the local scope, it will stop working.

o Global Variable: unlike local variables, global variables will be declared


outside other functions determined in the code, so global variables will
perform all the wishes in the program.

o Modularity: when two different systems have different tasks, but in the
procedure programming we can group them to perform a bigger task.

o Parameter Passing: Parameter Passing is organization used to pass


variables to functions, subroutines or procedures.

2.2 .Introduction to C programming language

It is a general-purpose computer programming language. It was designed in the 1970s


by Dennis Ritchie, and residue very widely used and significant. It is an essential
procedural language that supports structured programming, lexical variable scoping,
and recursion, with a static type system. It was created to be compiled to contribute
low-level access to memory and language constructs that map efficiently to machine
instructions, all with minimal runtime support. Despite its low-level proficiencies, the
language was designed to motivate cross-platform programming. A standards-
compliant C program written with portability in mind could be assembled for a wide
variety of computer platforms and operating systems with few changes to its source
code.

Page |3
P2. Identify the program units and data and file structures required to implement a given design

1. Variables

1.1. Definition
The variable of each program will be declared by the programmer with characters,
numbers and underscore. Each variable name must be started with a letter or
underscore the programmer must distinguish the upper and lowercase letters often
because the C language is quite sensitive. When the programmer named the variable in
the character, avoid 32 characters in C (ex: static, if, break, etc). The programmer
should not name the variable of more than 31 characters otherwise the program will
have problems in a number of translation processes. Each variable declared will be the
archive area in the program that the programmer writes they have a certain type, a set
size and arranged a determined layout. A variable has a specified range of values stored
in memory.

Page |4
1.2. Example
- The name contains underscore: First_name, full_name, date_of_birth, etc
- The name contains number: num1, d1, B1, student1, etc
- Other: n, x, y, first_name1, max_grade1, etc

2. Data types

2.1. Definition
A data type, in programming, is a classification that specifies the type of value of a
variable and has what type of mathematical, relational or logical operations can be
applied without causing errors. The data type defines the operations that can be safely
performed to create, transform, and use the variable in another calculation. For
example, a string is a data type used to classify text and an integer is a data type used
to classify integers.

2.2. Types if data types in C


Sr.No Type & Description
1 char
Size: 1 byte
Description: signed character/byte. Characters are enclosed in single quotes
Format specifier: %c
2 int
Page |5
Size: 4 bytes
Description: signed integer
Format specifier: %d, %i
3 float
Size: 4 bytes
Description: floating point number
Format specifier: %d
4 double
Size: 8 bytes
Description: double precision number
Format specifier: %lf
5 void
Description: Represents the absence of type.

3. Selection structures (Conditional Statements)

A. If statement
i.Syntax

ii.Example

Page |6
B. If…else statement
i. Syntax

ii. Example

Page |7
C. If…else if statement
i. Syntax

Page |8
ii.Example

D. Switch – case statement


i. Syntax

Page |9
ii. Example

4. Iteration structures

A. For statement
i. Syntax

P a g e | 10
ii. Example

B. While statement
i. Syntax

ii. Example

P a g e | 11
C. Do…while statement
i. Syntax

ii. Example

P3. Design a procedural programming solution for a given problem

1. Requirements for the given scenario:


- Select functions from menu
- Input student information (IDs, Grades)
- Print all student information(IDs, Grades)
- Print highest grade
- Print lowest grade
- Exit program

P a g e | 12
2. Use case diagrams

 Explanation:
The Use Case illustration describes the student's score management system, the
user is a teacher. Users will perform four functions in the program including:
entering student’s scores and student’s IDs, viewing grade and IDs of students,
printing the smallest and largest grades of students.

P a g e | 13
3. Flowcharts

A. Input IDs and Grade

 Explanation:
The Use Case illustration describes steps to implement the program enter the grades and IDs of
students.

 Step 1: Begin the program.


P a g e | 14
 Step 2: The user will declare variables such as: id, grade, selection.

 Step 3: After, the user have to choose the menu in the program.

 Step 4: Entering the selection in the program.

 Step 5: If the selection equal 1 is true.

 Step 5.1: The user will input the grades and IDs of students.

 Step 5.2: The grades and IDs of students will store in ID array and Grade array.

 Step 5.3: After, the program returns to the menu.

 Step 6: Otherwise we will consider the condition:

 Step 6.1:
 If the selection equal 5 -> the program will be stop.
 If not -> the program will return to the menu and continue the program.

P a g e | 15
B. Show IDs and Grade

 Explanation:
The Use Case illustration describes steps to implement the program show the grades and IDs of
students.

 Step 1: Begin the program.

 Step 2: The user will declare variables such as: id, grade, selection.
P a g e | 16
 Step 3: After, the user have to choose the menu in the program.

 Step 4: Entering the selection in the program.

 Step 5: If the selection equal 2 is true.


 Step 5.1: The program will show IDs and Grade of student to the user.
 Step 5.2: After that, the program returns to the menu and continue.

 Step 6: Otherwise we will consider the condition:


 Step 6.1:

 If the selection equal 5 -> the program will be stop.

 If not -> the program will return to the menu and continue the program.

C. Print highest grade

 Explanation:
The Use Case illustration describes steps to implement the program show highest grade of students.

P a g e | 17
 Step 1: Begin the program.

 Step 2: The user will declare variables such as: id, grade, selection.

 Step 3: After, the user have to choose the menu in the program.

 Step 4: Entering the selection in the program.

 Step 5: If the selection equal 3 is true.


 Step 5.1: The user will declare variables such as float highest and assign highest to
Grade[0].
 Step 5.2: The program will check if i are smaller than the number of students with a
list.
o Step 5.2.1: If the condition is true
- The program will perform the highest test mission is smaller than the
Grade [i] or not.
- If that is, the program will assign Highest to the Grade [i] and
increase i to a unit.
o Step 5.2.2: If the condition is false, the program will print on the screen the
highest grade of student.

 Step 6: Otherwise we will consider the condition:


 Step 6.1:
o If the selection equal 5 -> the program will be stop.
o If not -> the program will return to the menu and continue the program.

P a g e | 18
D. Print lowest grade

 Explanation:
The Use Case illustration describes steps to implement the program show lowest grade of students.

 Step 1: Begin the program.

 Step 2: The user will declare variables such as: id, grade, selection.

 Step 3: After, the user have to choose the menu in the program.

 Step 4: Entering the selection in the program.

 Step 5: If the selection equal 4 is true.


 Step 5.1: The user will declare variables such as float highest and assign lowest to
Grade[0].

P a g e | 19
 Step 5.2: The program will check if i are smaller than the number of students with a
list.
o Step 5.2.1: If the condition is true
- The program will perform the highest test mission is smaller than the
Grade [i] or not.
- If that is, the program will assign lowest to the Grade [i] and increase
i to a unit.
o Step 5.2.2: If the condition is false, the program will print on the screen the
lowest grade of student.

 Step 6: Otherwise we will consider the condition:


 Step 6.1:
o If the selection equal 5 -> the program will be stop.
o If not -> the program will return to the menu and continue the program.

4. Pseudo code

4.1. Input Id and Grade


Start
Declare variables: id, grade, selection
Do{
 S1: Show the menu
 S2: Input selection
 S3: if (selection == 1)

 Input id and grade

 Store id and grade into ID array and Grade array

 Back to S1
 S4: if (selection != 5)

 Back to S1
}while (selection == 5)
Stop

P a g e | 20
4.2. Show IDs and Grade
Start
Declare variables: id, grade, selection
Do{
 S1: Show the menu
 S2: Input selection
 S3: if (selection == 2)

 Show IDs and Grade

 Back to S1
 S4: if (selection != 5)

 Back to S1
}while (selection == 5)
Stop

4.3. Print highest grade


Start
Declare variables: id, grade, selection
Do{
 S1: Show the menu
 S2: Input selection
 S3: if (selection == 3)

 Declare variables: float highest

 Assign highest = Grade[0]

 i < NoOfStudent

 If the condition is true


o highest < Grade[i]
o Assign highest = Grade[i], i++

 If not -> print the highest

 Back to S1

P a g e | 21
 S4: if (selection != 5)

 Back to S1
}while (selection == 5)
Stop

4.4. Print lowest grade


Start
Declare variables: id, grade, selection
Do{
 S1: Show the menu
 S2: Input selection
 S3: if (selection == 4)

 Declare variables: float lowest

 Assign lowest = Grade[0]

 i < NoOfStudent

 If the condition is true


o lowest < Grade[i]
o lowest = Grade[i], i++

 If not -> print the lowest

 Back to S1
 S4: if (selection != 5)

 Back to S1
}while (selection == 5)
Stop

P a g e | 22
REFERENCES

1. (wikipedia 2022), available at:


https://en.wikipedia.org/wiki/Programming_language#:~:text=A%20programming%20language%2
0is%20any,computer%20programming%20to%20implement%20algorithms. [Accessed 31 May,
2022]

2. (Beal 2022), available at: https://www.webopedia.com/definitions/high-level-language/


[Accessed 31 May, 2022]

3. (Eggleston 2020), available at: https://www.coursereport.com/blog/a-guide-to-low-level-


programming-for-beginners [Accessed 31 May, 2022]

4. (Bhatia 2022), available at: https://hackr.io/blog/procedural-programming [Accessed 1 June,


2022]

5. (wikipedia 2022), available at: https://en.wikipedia.org/wiki/C_(programming_language)


[Accessed 1 June, 2022]

6. (C - Variables n.d.), available at:


https://www.tutorialspoint.com/cprogramming/c_variables.htm [Accessed 1 June, 2022]

7. (Contributor n.d.), available at:


https://www.techtarget.com/searchapparchitecture/definition/data-type [Accessed 1 June, 2022]

8. (C Data Types n.d.) , available at: https://www.programiz.com/c-programming/c-data-


types#:~:text=In%20C%20programming%2C%20data%20types,of%20int%20(integer)%20type.
[Accessed 2 June, 2022]

9. (C if...else Statement n.d.), available at: https://www.programiz.com/c-programming/c-if-else-


statement [Accessed 2 June, 2022]

10. (C switch Statement n.d.), available at: https://www.programiz.com/c-programming/c-switch-


case-statement [Accessed 2 June, 2022]

11. (for loop in C n.d.), available at:


https://www.tutorialspoint.com/cprogramming/c_for_loop.htm [Accessed 2 June, 2022]

P a g e | 23

You might also like