You are on page 1of 24

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Prog102: Procedural Programming

Submission date 13/05/2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Tran Vu Anh Minh Student ID GCS210898

Class GCS1004B Assessor name

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 AM

Grading grid

P1 P2 P3 M1 M2 D1

1|Page
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

2|Page
Table of Contents
TASK1(P1,M1).............................................................................................................................. 5
(P1.Provide Information About Procedural Programming)............................................................ 5
1.Introduction programming languages......................................................................................... 5
1.1.Low-Level Programming Language..................................................................................... 5
1.2.High-level Programming language.......................................................................................... 6
2.Introduction to procedural programing....................................................................................... 7
3.Standard for choosing a programming language....................................................................... 7
(M1 Discuss on characteristics and features of procedural programming)................................... 7
4.Pros and Cons of Procedural Programming:............................................................................. 7
4.1.Advantages......................................................................................................................... 7
4.2.Disadvantages.................................................................................................................... 8
5.Conclusion..................................................................................................................................8
TASK 2(P2)................................................................................................................................. 9
(P2.identify the program and data and structures required to implement a given
design).....................…………………………………………………………………………………… 9
1.The variables and types of data................................................................................................ 9
1.1.TheVariables................................................................................................................... 9
1.2. The types of data .......................................................................................................... 10
1.2.1. Basic Types........................................................................................................ 10
1.2.2. Enumerated Types............................................................................................. 10
1.2.3. The Void type..................................................................................................... 10
1.2.4. Derived types..................................................................................................... 10
2. Types of data in procedural programming ...................................................................... 10
2.1. Types of data needed to write a program for the given the Scenario ................. 10
2.2. Int......................................................................................................................... 11
2.3. Float .................................................................................................................... 12
2.4. Char..................................................................................................................... 12
2.5. Void ..................................................................................................................... 13
3. Selection Structures.................................................................................................... 13
3.1. If Statement ......................................................................................................... 13
3.2 Switch-Case.......................................................................................................... 14
4. Iteration constructs ................................................................................................................ 14
4.1. For Loop ......................................................................................................................... 14
4.2. While Loop ...................................................................................................................... 14
4.3. Do While Loop................................................................................................................. 15
5. External modules/Functions.................................................................................................... 15
5.1. stdio.h............................................................................................................................... 15

3|Page
5.2. printf( ) ........................................................................................................................... 15
5.3. scanf( ) ........................................................................................................................... 15
6. A specific example program in C........................................................................................... 15
TASK 3 (P3, M2) ...................................................................................................................... 16
(P3. Write a Procedural Program for the given scenario).......................................................... 16
1. Identify The scenario ............................................................................................................. 16
2. Diagram to demonstrate the scenario ................................................................................... 16
3. Flowchart……………………………………………………………………………………………..17
3.1. Input ID and Grade...................................................................................................... 17
3.2. Print all Student ID and Grade…………………………………………………………….. 18
3.3. Print Student Highest Grade............... ........................................................................ 19
3.4. Print Student Lowest Grade ........................................................................................ 20
4. Structure Code....................................................................................................................... 20
4.1. Select Menu ................................................................................................................ 20
4.2. Input ID, Grade ........................................................................................................... 21
4.3. Print all student ID, Grade .......................................................................................... 21
4.4. Print Student highest Grade ....................................................................................... 22
4.5. Print Student lowest Grade ....................................................................................... 22
(M2 Review the design of a procedural programming solution.) .............................................. 23
5. Review and evaluate the design .......................................................................................... 24

4|Page
TASK 1 (P1, M1)
(P1. Provide Information About Procedural Programming)
1. Introduction programming languages
Programming language is a formal language comprising a set of strings
that produce various kinds of machine code output. Programming languages
are one kind of computer language, and are used in computer programming to
implement algorithms. Computer programming language, any of various
languages for expressing a set of detailed instructions for a digital computer.
Such instructions can be 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 assembly
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 considerations and provide a notation that is more easily
written and read by programmers.
1.1. Low-Level Programming Language
A low-level programming language is a programming language that
provides little or no abstraction from a computer's instruction set architecture
commands or functions in the language map that are structurally similar to
processor's instructions. Generally, this refers to either machine code or
assembly 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 or
interpreter – second-generation programming languages use a simpler

5|Page
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 equivalent program in a high-
level language can be less efficient and use more memory. Low-level languages
are simple, but considered difficult to use, due to numerous technical details
that the programmer must remember. 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-level Programming language
In computer science, a high-level programming language is a 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 (or even hide entirely) significant areas of
computing systems (e.g., memory management), 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 is.
In the 1960s, high-level programming languages using a compiler were
commonly called auto codes. Examples of auto codes are COBOL and
Fortran. The first high-level programming language designed for computers was
Plankalkül, 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
"Super plan" 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 Auto code systems. Algol, defined in
1958 and 1960 by committees of European and American computer scientists,
introduced 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 semantics Algol also introduced several
structured programming concepts, 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

6|Page
records (Also called structs) and Lisp introduced a fully general lambda
abstraction in a programming language for the first time.
2. Introduction to procedural programing
Procedural Programming may be the first 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
uses a linear top-down approach and treats data and procedures as two
different entities. Based on the concept 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 what it should do step-by-step to finish the task at hand
3. Standard for choosing a programming language
There are many factors that influence the choice of programming
languages, the main factors are cost, organization policy, availability, reliability,
suitability and expandability. All these factors should be considered when
choosing a programming language. One of the most important factors is cost as
it can influence the developing and maintenance to that software. To develop a
software project, the size of the project needs to be taken into account.
Depending on the size of the project it can change how many programmers you
employ. For example a big project will require lots of programmers which can
be very costly to contract. To even maintain the project and keep it up to date,
free from errors, will cost to keep the programmers to do this over the years.
However, some languages can be easier to cut development costs due to it
being easier, quicker to develop and maintain. Overall it’s important to balance
the cost and performance to reach the best possible outcome for the cost of the
project.

(M1 Discuss on characteristics and features of procedural programming)


4. Pros and Cons of Procedural Programming:
4.1. Advantages
− Procedural Programming is excellent for general-purpose programming.
− The coded simplicity along with ease of implementation of compilers and

7|Page
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.
4.2. 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.
There are different types of programming paradigm, which are nothing but a
style of programming. It is important to understand that the paradigm does not
cater to a specific language but to the way the program is written.
5. Conclusion
Procedural programming is closer to the task being performed than the way it
is performed. This is the standard approach used by many computer languages
like C, Pascal, and BASIC. There is no perfect programming paradigm, but it is
important to understand that the right paradigm always changes based on the
type of language you use and program you write. To get the best results and a
strong portfolio, you need to be proficient in both of the three major
programming paradigms.

8|Page
TASK 2 (P2)
(P2. Identify the program and data and structures required to implement a
given design)
1. The variables and types of data
1.1. The Variables
In computer programming, a variable or scalar is a storage location (identified
by a memory address) paired with an associated symbolic name, which
contains some known or unknown quantity of information referred to as a value;
or in easy terms, a variable is a container for a particular type of data (like
integer, float, String and etc...). The variable name is the usual way to reference
the stored value, in addition to referring to the variable itself, depending on the
context. This separation of name and content allows the name to be used
independently of the exact information it represents. The identifier in
computer source code can be bound to a value during run time, and the value
of the variable may thus change during the course of program execution.
Variables in programming may not directly correspond to the concept of
variables in mathematics. The latter is abstract, having no reference to a
physical object such as storage location. The value of a computing variable is
not necessarily part of an equation or formula as in mathematics. Variables in
computer programming are frequently given long names to make them
relatively descriptive of their use, whereas variables in mathematics often have
terse, one- or two-character names for brevity in transcription and manipulation.
A variable's storage location may be referenced by several different
identifiers, a situation known as
aliasing. Assigning a value to the variable using one of the identifiers will
change the value that can be
accessed through the other identifiers.
Following are the rules that must be followed while creating a variable:
• A variable name should consist of only characters, digits and an underscore.
• A variable name should not begin with a number.
• A variable name should not consist of whitespace.
• A variable name should not consist of a keyword.
9|Page
• 'C' is a case sensitive language that means a variable named 'age' and 'AGE' are
different.
1.2. The types of data
The data type defines which operations can safely be performed to create,
transform and use the variable in another computation. When a program
language requires a variable to only be used in ways that respect its data type,
that language is said to be strongly typed. This prevents errors, because while it
is logical to ask the computer to multiply a float by an integer (1.5 x 5), it is
illogical to ask the computer to multiply afloat by a string (1.5 x Alice). When a
programming language allows a variable of one data type to be used as if it
were a value of another data type, the language is said to be weakly typed.
1.2.1. Basic Types
They are arithmetic types and are further classified into: (a) integer types and (b)
floating-point types.
1.2.2. Enumerated Types
Enumeration (or enum) is a user defined data type in C. It is mainly used to
assign names to integral
constants, the names make a program easy to read and maintain
1.2.3. The Void type
The void type, in several programming languages derived from C and
Algol68, is the type for the result of a function that returns normally, but does
not provide a result value to its caller. Usually such functions are called for their
side effects, such as performing some task or writing to their
output parameters.
1.2.4. Derived types
They include Pointer types, (b) Array types, (c) Structure types, (d) Union types and
(e) Function types.
2. Types of data in procedural programming
2.1. Types of data needed to write a program for the given the Scenario
-Types of data needed to write the program for selecting a function out of the
five functions in the menu, input and output student information and find the
highest and lowest grade of all student

10 | P a g e
− “int” Array to stored student IDs and students.
− “float” Array to stored highest and lowest grades.
− “Printf” Function print Student IDs and Grades.
− “Scanf” Function to take input number and sentences from user.
− “Switch” Statement to switch between cases.
− “For” Loop to repeat a function until a condition is met.
− “If” Statement to perform the operations based on some specific condition.
-For the given scenario the program comprise of 4 Sub-Functions
− A function to Input student ID and student grade
− A function to Print all student ID and student grade
− A function to find the highest grade
− A function to find the lowest grade
2.2. Int
Integers are whole numbers with a range of values, range of values are
machine dependent. Generally, an integer occupies 2 bytes memory space and
its value range limited to -32768 to +32767 (that is, -2^15 to +2^15-1). A signed
integer uses one bit for storing sign and rest 15 bits for number. To control the
range of numbers and storage space, C has three classes of integer storage
namely short int, int and long int. All three data types have signed and unsigned
forms. A short int requires half the amount of storage than normal integer.
Unlike signed integer, unsigned integers are always positive and use all the bits
for the magnitude of the number. Therefore, the range of an unsigned integer
will be from 0 to 65535. The long integers are used to declare a longer range of
values and it occupies 4 bytes of storage space.

Syntax:
int <variable name>; like
int num1;
short int num2;
long int num3;

Example: 1, 2, 50, 1000

11 | P a g e
2.3. Float
The FLOAT data type stores double-precision floating-point numbers with up to
17 significant digits. FLOAT corresponds to IEEE 4-byte floating-point, and to
the double data type in C. The range of values for the FLOAT data type is the
same as the range of the C double data type on your computer.
For example:
float age = 10.5;
In this example, the variable named age would be defined as a float and
assigned the value of 10.5. Below is an example C program where we declare
this variable and assign the value:
Syntax:
#include <stdio.h>
int main()
{
float age = 10.5;
printf("Someone is over %f years old.\n", age);
return 0;
}
This C program would print "Someone is over 10.500000 years old."

2.4. Char
The CHAR data type stores character data in a fixed-length field. Data can be a
string of single-byte or
multibyte letters, numbers, and other characters that are supported by the code
set of your database
locale.
Example:
Syntax:
#include <iostream>
using namespace std;
int main()
{
char grade = 'A+';

12 | P a g e
cout << "I scored a: "<<grade;
return 0;
}

2.5. Void
The void data type, similar to the Nothing data type described earlier, is the
data type for the result of a function that returns normally, but does not provide
a result value to its caller. The void data type has no values and no operations.
It’s a data type that represents the lack of a data type.
Example:
void sum (int a, int b); – This function won’t return any value to the calling
function.
int sum (int a, int b); – This function will return value to the calling function.

3. Selection Structures
3.1. If Statement
The if statement is used to check some given condition and perform some
operations depending upon the correctness of that condition. It is mostly used in
the scenario where we need to perform the different
operations for the different conditions.

The structure of an if statement is as follows:

A simple example of C language if statement:

#include<stdio.h>
int main(){
int number=0;
printf("Enter a number:");
scanf("%d",&number);
if(number%2==0){

13 | P a g e
printf("%d is even number",number);
}
return 0;
}
3.2 Switch-Case
Switch statement executes one statement from multiple conditions. It is like if-
else-if ladder statement. The switch statement works with byte, short, int, long,
enum types, String and some wrapper types like Byte, Short, Int, and Long.
Since Java 7, you can use strings in the switch statement. In other words, the
switch statement tests the equality of a variable against multiple values.

Syntax:
switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
......
default:
code to be executed if all cases are not matched;
}
4. Iteration constructs
4.1. For Loop
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.
Syntax:
for (initialization; condition; increment/decrement) {
//statement or code to be executed
}
4.2.While Loop
A while loop in C programming repeatedly executes a target statement as long
as a given condition is true.
while(condition) {
statement(s);
}

14 | P a g e
4.3.Do While Loop
A do...while loop is similar to a while loop, except the fact that it is guaranteed
to execute at least one time.
do {
statement(s);
} while( condition );
5. External modules/Functions
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. printf( )
It is used to print the strings, integer, character, etc on the output screen.
5.3. scanf( )
It reads the character, string, integer, etc from the keyboard.
6. A specific example program in C
Example: Write a program to identifies odd or even number.
int main () {
int num;
printf("Enter A Number: ");
scanf("%d", &num);

if (num % 2 == 0)
printf("%d is Even Number.", num);

else
printf("%d is Odd Number.", num);
return 0;
}

15 | P a g e
TASK 3 (P3, M2)
(P3. Write a Procedural Program for the given scenario)
1. Identify The scenario
• Select a Functions in the Menu
• Input Student information (IDs, Grade)
• Print all Student information (IDs, Grade)
• Print Student have the highest Grade
• Print Student have the lowest Grade
2. Diagram to demonstrate the scenario

Figure 6
The diagram shows the process of the given scenario

16 | P a g e
3. Flowchart
3.1. Input ID and Grade

Figure 7
The Flowchart shows the process of Input ID and grade of student
3.2. Print all Student ID, Grade

17 | P a g e
Figure 8
The Flowchart shows the process of print all student ID, grade
3.3. Print Student Highest Grade

18 | P a g e
Figure 9
The Flowchart shows the process of finding student with the highest
grade
3.4. Print Student Lowest Grade

19 | P a g e
Figure 10
The Flowchart shows the process finding student with the lowest grade

4. Structure Code
4.1. Select Menu
Begin
Do
Display Menu
1. Input Student’s information
2. Print Student’s information
3. Print Highest grade

20 | P a g e
4. Print Lowest grade
5. Exit
While (option = 5)
End

4.2. Input ID, Grade


Begin
Do
Display Menu
1. Input ID, Grade
2. Print ID, Grade
3. Print highest grade
4. Print lowest grade
5. Exit
If(option=1)
Begin
Input student’s information
End
While (option = 5)
End

4.3. Print all student ID, Grade


Begin
Do
Display Menu
1. Input ID, Grade
2. Print ID, Grade
3. Print highest grade
4. Print lowest grade
5. Exit
If(option=2)
Begin
Print student’s information
End

21 | P a g e
While (option = 5)
End

4.4. Print Student’s highest Grade


Begin
Do
Display Menu
1. Input ID, Grade
2. Print ID, Grade
3. Print highest grade
4. Print lowest grade
5. Exit
If(option=3)
Begin
I=2
max_grade = Grades [1];
for (i = 2; i <= n; i++)
{
if (Grades[i] > max_grade
max_grade = Grades[i];
End
}
Display max_grade
End.

4.5. Print Student lowest Grade


Begin
Do
Display Menu
1. Input ID, Grade
2. Print ID, Grade
3. Print highest grade
4. Print lowest grade
5. Exit
If(option=4)
Begin
min_grade = Grades [1];

22 | P a g e
for (i = 2; i <= n; i++)
if (Grades[i] <= min_grade)
min_grade = Grades[i];
End
Display min_grade
End
(M2 Review the design of a procedural programming solution.)
5. Review and evaluate the design
Procedural programming is closer to the task being performed than the way it is
performed. This is the standard approach used by many computer languages
like C, Pascal, and BASIC. There is no perfect programming paradigm, but it is
important to understand that the right paradigm always changes based on the
type of language you use and program you write. To get the best results and a
strong portfolio, you need to be proficient in both of the three major
programming paradigms.

23 | P a g e
REFERENCES
1. From Wikipedia (31 July 2021): https://en.wikipedia.org/wiki/Programming_language
2. From Britannica Computer Programming Language by David Hammendinger(2000):
https://www.britannica.com/technology/computer-programming-language
3. From Wikipedia (13 August 2021): https://en.wikipedia.org/wiki/Low-level_programming_language
4. From Hackr.io What is Procedural Programming: https://hackr.io/blog/procedural-programming
5. Factors influencing the choice of programming languages:
https://divisionartistcom.wordpress.com/factors-influencing-the-choice-of-programming-
languages/
6. From Wikipedia (November 2009): https://en.wikipedia.org/wiki/Variable_(computer_science)
7. C Variable, Datatypes, constants: https://www.guru99.com/c-variable-datatypes-constants.html
8. Enumeration (or Enum) in C: https://www.geeksforgeeks.org/enumeration-enum-c/
9. The Void Type (3 July 2021):
https://en.wikipedia.org/wiki/Void_type#:~:text=The%20void%20type%2C%20in%20several,writi
ng%20to%20their%20output%20parameters
10. Derived types (22 October 2020): https://hackr.io/blog/data-types-in-
c#:~:text=Array%2C%20pointers%2C%20struct%2C%20and,derived%20data%20types%20in%20
11. From Computer Programming Integer Data Type: https://sites.google.com/site/cpge6151/c-
pro/data-types
12. From IBM Float Data Type: https://www.ibm.com/docs/en/informix-servers/12.10?topic=types-
floatn
13. From IBM Char Data Type: https://www.ibm.com/docs/en/informix-servers/14.10?topic=ocdt-
char-data-type
14. From TMGM Void Data Type: https://fresh2refresh.com/c-programming/c-interview-questions-
answers/what-is-void-in-c/
20. Tutorialspoint. Header files “stdio.h” and “stdlib.h” in C https://www.tutorialspoint.com/header-
files-stdio-h-and-stdlib-h-in-c
21. The characteristics of procedural programming https://www.knowledgeboat.com/question/what-
are-the-characteristics-of-procedural-programming--28311496451138200
22. Key Features of Procedural Programming and pros and cons about Procedural Programming
https://hackr.io/blog/procedural-programming
23. Characteristics of Procedural Programming https://www.knowledgeboat.com/question/what-are-
the-characteristics-of-procedural-programming--28311496451138200

24 | P a g e

You might also like