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

Higher Nationals in Computing

Unit 0: Procedural Programming


ASSIGNMENT 1

Learner’s name: Nguyễn Xuân Nam


ID: GCS200708
Class:
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 9/8/2021 Date Received 1st submission

Re-submission Date 13/8/2021 Date Received 2nd submission

Student Name Nguyễn Xuân Nam Student ID GCS200708

Class GCS0905A 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 D1 Critically evaluate the design


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

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
P1. Provide introduction to procedural programming..................................1
1. Introduction to computer programming lauguage................................................1
1.1 Low lever language........................................................................................................1
1.2 High lever language.......................................................................................................2

2. Introduction to procedural programming.............................................................3


3. Criteria for choosing a programming language to use...........................................4

P2. Identify the program units and data and file structures required
implement a given design...........................................................................4
1. The variables and data types required..................................................................5
1.1 The variables.................................................................................................................. 5
1.2 Data types required.......................................................................................................6
1.2.1 Basic Types............................................................................................................6
1.2.2 Enumcrated types.................................................................................................6
1.2.3 The type void........................................................................................................7
1.2.4 Derived types........................................................................................................7

2. There are 5 data types in procedural programming..............................................7


2.1 Int.................................................................................................................................. 7
2.2 Float............................................................................................................................... 8
2.3 Character....................................................................................................................... 8
2.4 Double........................................................................................................................... 9

3. Selection structures..............................................................................................9
3.1 If..................................................................................................................................... 9
3.2 If else............................................................................................................................ 11
3.3 Swtich-case................................................................................................................... 12

4. Interation constructs............................................................................................14
4.1 For................................................................................................................................. 14
4.2 While............................................................................................................................. 15
4.3 Do-While....................................................................................................................... 16

5. External moduls/functions required....................................................................18


5.1 Stdio.h........................................................................................................................... 18
5.2 String.h......................................................................................................................... 18
5.3 Printf............................................................................................................................. 18

P3. Design a procedural programming solution for a given problem...........18


1. Use case...............................................................................................................18
2. Flowchart.............................................................................................................19
2.1 Select Menu Functions.................................................................................................19
2.2 Input student informations...........................................................................................20
2.3 Print all student informations.......................................................................................23
2.4 Printf highest grade......................................................................................................24
2.5 Printf lowest grade........................................................................................................26

3. Pseudo code.........................................................................................................28
3.1 Select menu functions..................................................................................................28
3.2 Input student informantions.........................................................................................28
3.3 Print all student informations.......................................................................................29
3.4 Print highest grade........................................................................................................29
3.5 Print lowest grade.........................................................................................................30

M1. Discuss on characteristics and features of procedural programming....30


1. Characteristics of procedural programming.........................................................30

2. Features of procedural programming...................................................................31


2.1 Predefined functions....................................................................................................31
2.2 Local Variable................................................................................................................ 31
2.3 Global Variable.............................................................................................................31
2.4 Modularity.................................................................................................................... 32
2.5 Parameter Passing........................................................................................................32
ASSIGNMENT 1 ANSWERS
P1. Provide introduction to procedural programming

1.Introduction to computer programming lauguage

A programming language is a formal language comprising a set of instructions that produce


various kinds of output. Programming languages are used in computer programming to implement
algorithms. Computer programming language, any of various languages for executed directly
when they are in the computer manufacturer-specific numerical form known as machine
language, after a simple substitution process when expressed in a corresponding assemble
language or after translation from some “higher-level” language. Although there are many
computer languages, relatively few are widely used. Machine and assembly languages are “low-
level” requiring a programmer to manage explicitly all of a computer’s idiosyncratic features of
data storage and operation. In contrast, high-level languages shield a programmer from worrying
about such consideration and provide a notation that is more easily written and read by
programmers.

Emple: C++, C#,….

1.1.Low lever language

A low-level programming language is a progeamming language that provides little or no


abstraction from a computer’s instruction set architecture-commands or functions in the language
map closely to processor instructions. Generally, this refers to either machine code or assembly

Page |1
language. Because of the low (hence the word) abstraction between the language and machine
language, low-level languages are sometimes described as being “close to the hardware”.
Programs written in low-level languages tend to be relatively non-portable, due to being
optimized for a certain type of system architecture. Low-level languages can convert to machine
code without a compiler of interpreter-second-generation programming languages use a simple
processor called an assembler – and the resulting code runs directly on the processor. A program
written in a low-level language can be made to run very quickly with a small memory footprint. An
quivalent program in a high-level language can be less efficient and use more memory. Low-level
languages are simple but considered doffocult to use, due to numerous technical details that the
programmer must remerber. By comparison, a high-level programming language isolates
execution semantics of a computer architecture from the specification of the program which
simplifies development.

1.2.High lever language

In computer science, a high-level programming language is programming language with strong


abstraction from the details of the computer. In contrast to low-level programming languages, it
may use natural language elements, be easier to use or may automate significant areas of
computing systems, making the process of developing a program simpler and more
understandable than when using a lower-level language. The amount of abstraction provided
defines how “high-level” a programming language. In the 1960s, high-level programming
languages using a compiler were commonly called autocodes. Examples of autocodes are COBOL

Page |2
and Fortran. The first high-level programming language designed for computer was Plankalkul,
created by Konrad Zuse. However, it was not implemented in his time and his original
contributions were largely isolated from other developments due to World War II, aside from the
language’s influence on the “Superplan” language by Heinz Rutishauser and also to some degree
Algol. The first significantly widespread high-level language was Fortran, a machine-independent
development of IBM’s earlier Autocode systems. Algol, defined in 1958 and 1960 by committees
of European and American computer scientists, intro duced recursion as well as nested functions
under lexical scope. It was also the first language with a clear distinction between value and name-
parameters and their corresponding sematics. Algol also introduced seral structured programming
concopts, such as the while-do and if-then-else constructs and its syntax was the first to be
described in formal notation – “Backus-Naur form” (BNF). During roughly the same period, Cobol
introduced records and Lisp introduced a fully general lambda abstraction in a programming
language for the first time.

2.Introduction to procedural programming

Procedural programming is a programming paradigm, derived from structured programming,


[citation needed] based on the concept of the procedure call. Procedures simply contain a series
of computional steps to be carried out. Any given procedure might be called at any point duringa
program’s execution, including by other procedures or itself. The first major procedural
programming languages appeared circa 1957-1964, including Fortran, ALGOL, COBOL, PL/I and
BASIC. Pascal and C were published circa 1970-1972. Procedural Programming may be the first

Page |3
programming paradigm that a new developer will learn. Fundamentally, the procedural code is
the one that directly instructs a device on how to finish a task in logical steps. This paradigm user a
linear top- down approach and treats data and procedures as two different entities. Based on the
conpt of a procedure call, Procedural Programming divides the program into procedures, which
are also known as routines or functions, simply containing a series of steps to be carried out.
Simply put, Procedural Programming involves writing down a list of instructions to tell the
computer whtat it should do step-by-step to finish the task at hand.

3.Criteria for choosing a programming language to use

The right selection of programming language yields solutions that are concise, easy to debug,
easy to extend, eay to document and easy to fix. The support and community. It is very important
to consider the platform on which the program will run. Say you have two languages, Java and C. If
a program is written in C and needs to be run on Windows and Linux platforms, it would require
platform compilers and two different executables. On the other hand, with Java development, the
program can run on any machine provided a Java Machine(JVM) is installed. The same goes for
web pages. They should all look and work the same across all browsers. However, using CSS3 tags
and HTML 5 without checking browser compatibility will cause the site to look and behave
diffenrently across different browsers.

P2.Identify the program units and data and file structures required to
implement a given design
Page |4
1.The variables and data types required

1.1.The variables

A variable is nothing but a name given to a storage area that our programs can manipulate. Each
variable in C has a specific type, which determines the size and layout of the variable’s memory;
the range of values that can be stored within that memory and the set of operations that can be
applied to the variable. The name of a variable can be composed of letters, digits and the
underscore character. It must begin with either a letter or an underscore. Upper and lowercase
letters are distinct because C is case-sensitive. C programming language also allows to define
various other types of variables, which we will cover in subsequent chapters like Enumeration,
Poionter, Array, Structure, Union, etc. For this chapter, let us study only basicvariable types. Based
on the basic types explained in the previous chapter, there will be the following basic variable
types

 Variable name must begin with letter or underscore.

 Variables are case sensitive.

 They can be constructed with digits, letters.

 No special symbols are allowed other than underscore.

 Sum, height, _value are some examples for variable name.

Page |5
1.2.Data types required

Data types in C refer to an extensive system used for declaring variables or functions of different
types. The type of a variable determines how much space it occupies in storage and how the bit
pattern stored is interpreted. The array types and structure types are referred collectively as the
aggregare types. The type of a fuction specifies the type of the fuction’s return value. We will see
the basic types in the following section, where as other types will be covered in the upcoming
chapters. The types in C can be classified as follows

1.2.1.Basic Types

They are arithmetic types and are further classified into: (a) integer types and (b) bloating-point
types.

1.2.2.Enumerated types

Page |6
They are again arithmetic types and they are used to define variables that can only assign
certain discrete integer values throughout the program.

1.2.3.The type void

The type specifier void indicated that no value is available.

1.2.4.Derived types

They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and €
Function types

2.There are 5 data types in procedural programming

2.1.Int

Integers are a commonly used data type in computer programming. For example, whenever a
Page |7
number is being incremented, such as within a “for loop” or “while loop”, and integer is used.
Integer are also used to determine an item’s location within an array.

 Stored numeric data cannot store other type e.g., “Alan” or


“abc”

 Declaration: int, num;

 Size (Depends on the Operating System) Normally 32 bits (4


bytes)

 Integers in the range: -32768 to 32767 Examples: 12322, 0,


-232

2.2.Float

A floating-point data type uses a formulaic representation of real numbers as an approximation


so as to support a trade-off between range and precision. For this reason, floating-point
computation is often found in systems which include very small and very large real numbers,
which require fast processing times.

 Stores values containing decimal places cannot store other


type e.g., “Alan” or “abc” Precision of up to 6 digits

 Declaration: float num;

 Size (Depends on the Operating System) Normally 32 bits (4


bytes)

 Examples: 12.1, 14.5, 15

2.3.Character

The character is also used as a reserved keyword in a programming language where it may be
represented in code languages as chr or char. It plays a critical role in computer programming that
is a data type that holds one character (letter, number, etc.) of data.

 Stores single character information cannot store other type


Page |8
e.g., “Alan” or “abc”

 Declaration: char c;

 Size (Depends on the Operating System) Normally 8 bits (1


byte)

 Examples: ‘a’, ‘b’, ‘$’, ‘%’, ‘1’, ‘2’

2.4.Double

The double is a fundamental data type buildt into the compiler and used to define numeric
variables holding numbers with decimal points. C, C#, C++ and many other programming
languages recognize the double as a type. A double type can represent fractional as well as whole
values.

 Stores values containing decimal places cannot store other


type e.g.,”Alan” or “abc” Precision of up to 10 digits

 Declaration: double num;

 Size (Depends on the Operating System) Normall 64 bits (8


bytes)

 Examples: 15.0, 2.456, 1245

3.Selection structures

3.1.If

The ability to control the flow of your program, letting it make decisions on what code to
execute is valuable to the programmer. The if statement allows you to control if a program enters
a section of code or not based on whether a given condition is true or false. One of the important
fuctions of the if statement is that it allows the program to select an action based upon the user’s
input. For example, by using an if statement to check a user entered password, your program can
decide whether a user is allowed access to the pro

Page |9
3.2.If else
P a g e | 10
If-else is a conditional statement in C++. The C++ of statement runs a block of code if a condition
is met. An if-else statement fuctions the same way but runs a second block of code if the condition
is not met. If and if-else statements can be nested.

3.3.Swtich-case

P a g e | 11
Switch case statements are a substitute for long if statements that compare a variable to several
integral values. The switch statement is a multiway is a multiway branch statement. It provides an
easy way to dispatch execution parts of code based on the value of the expression. Switch is a
control statement that allows a value to change control of execution.

P a g e | 12
4.Interation constructs

4.1.For

A “For” Loop is used to repeat a specific block of code (statements) a known number of times.
The for-loop statement is a very specialized while loop, which increases the readability of
program. Here is the syntax of the of for loop.

P a g e | 13
4.2.While

While loop is also known as pre-tested loop. In general, a while loop allows a part of the code to
be executed multiple times depending upon a given boolean condition. It can be viewed as a
repeating if statement. The while loop is mostly used in the case where the number of iterations is

P a g e | 14
not known in advance.

4.3.Do-While

In the previous tutorial we learned while loop in C. A do while loop is similar to while loop with
one exception that it executes the statements inside the body of do-while before checking the
condition. On the other hand in the while loop, first the condition is checked and then the

P a g e | 15
statements in while loop are executed. So you can say that if a condition is false at the first place
then the do while would ren once, however the while loop would not run at all.

P a g e | 16
5.External modules/functions required

5.1.Stdio.h

The header file stdio.h stands for Standard Input Output. It has the information related to
input/output functions.

5.2.String.h

The string.h header defines one variable type, one macro and various functions for manipulating
arrays of characters.

5.3.Printf

In C programming language, printf() function is used to print the (“character, string, float
integer, octal and hexadecimal values”) onto the output screen.

P3.Design a proccedural programming solution for a given problem

1.Use case

Identify requiments:

P a g e | 17
 Input student informations

 Print all student informations

 Print highest and lowest grade

 Select functions from menu

2.Flowchart

2.1.Select Menu Functions

P a g e | 18
 i: the repeated time

 option: menu

 input option: selection option

2.2.Input student information

P a g e | 19
 option: menu

 input option: selection option

 ID: student ID

P a g e | 20
 Grade: student grade

2.3.Print all student informations

P a g e | 21
P a g e | 22
 i: the repeated time

 option: menu

 input option: selection option

 IDs: IDs of all students

 Grade: grades of all students

2.4.Print highest grade

P a g e | 23
 i: the repeated time

 option: menu
P a g e | 24
 input option: selection option

 n: number of students in class

 maxGrade: student has the highest grade

 arrGrade: float array for grades

2.5.Print lowest grade

P a g e | 25
 i: the repeated time

 option: menu

P a g e | 26
 input option: selection option

 n: number of students in class

 minGrade: student has the lowest grade

 arrGrade: float array for grades

3.Pseudo code

3.1.Select menu functions

3.2.Input student informations

P a g e | 27
3.3.Print all student informations

3.4.Print highest grade

P a g e | 28
3.5.Print lowest grade

M1. Discuss on characteristics and features of procedural programming

1.Characteristics of procedural programming

Unlike with the object-oriented programming which is data and model concentrated, procedural

P a g e | 29
programming (PP) focus on sequences of actions to be done. From the point of programming, data
is the reason for the existence of a program.

In procedural languages such as C, programs are composed of procedures or functions and each
procedure is a sequence of statements that has a specific defined purpose.

The characteristics of PP are:

1. Focus on process or doing things rather than data.

2. The whole program is implemented based on actions such as reading, calculating and
printing. Therefore, a bunch of functions are written to solve a program from top to down.

3. Global data is often shared by all functions.

4. Data moves openly from function to function.

2.Featuares of procedural programming

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

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

P a g e | 30
2.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.

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

P a g e | 31
REFERENCES

 Kernighan, B. and Ritchie, D. (1988). The C Programming Language. United States, Hoboken:
Prentice Hall.

 Levy, Stephen(9 June 2021) https://en.wikipedia.org/wiki/Low-level_programming_language


[Accessed 8 August. 2021]

 From Wikipedia(18 July 2021) https://en.wikipedia.org/wiki/High-level_programming_language


[Accessed 8 August. 2021]

 Sagar Bhatia(8 Jan. 2021) https://hackr.io/blog/procedural-programming [Accessed 8 August.


2021]

 From tutorialspoint. C – Variables https://www.tutorialspoint.com/cprogramming/c_variables.htm


[Accessed 8 August. 2021]

 From tutorialspoint. C – Data types


https://www.tutorialspoint.com/computer_programming/computer_programming_data_types.ht
m [Accessed 8 August. 2021]

 Yingzi Li(2019) https://www.quora.com/What-is-the-major-characteristic-of-procedural-


programming [Accessed 8 August. 2021]

P a g e | 32

You might also like