You are on page 1of 21

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 Doan Vo Quy Student ID GCH210660

Class GCH1101 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 Quy

Grading grid

P1 P2 P3 M1 M2 D1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Table of Contents

A. INTRODUCTION. ...........................................................................................................3
I. Programming Language .................................................................................................................... 4
1. Definition. ....................................................................................................................................... 4
2. Programming Languages ................................................................................................................ 4
3. Programming Language Features ................................................................................................... 4
II. Procedural Programming. .................................................................................................................. 4
1. Introduction and general concept .................................................................................................... 4
2. Features ........................................................................................................................................... 5
B. ANALYSIS ........................................................................................................................................ 5
I. Analyse the problem ........................................................................................................................ 5
II. Variables needed............................................................................................................................... 6
1. What is data type?. .......................................................................................................................... 6
2. Declaring variables .......................................................................................................................... 6
3. How to declare variable .................................................................................................................. 6
III. Data types needed in the problem .................................................................................................. 7
1. What is data type?. .......................................................................................................................... 7
2. Types of Data Types in C................................................................................................................ 7
3. Data types needed in the problem ................................................................................................... 8
IV. Data structures needed in the problem. ...................................................................................... 9
1. Definition ........................................................................................................................................ 9
2. Data structures needed in the problem .......................................................................................... 10
3. Conclusion..................................................................................................................................... 10
V. Conditional statements needed in the problem. ...................................................................... 10
1. What is Conditional Statements? .................................................................................................. 10
2. Conditional Statements ................................................................................................................. 10
VI. Loop statement needed in the problem ............................................................................... 13
1. Loop statement in C ...................................................................................................................... 13
2. Types of Loops in C ...................................................................................................................... 13
C. DESIGN ............................................................................................................................................... 18
I. WBS. ............................................................................................................................................ 18
II. Use case diagram ........................................................................................................................ 19
III. Flow chart diagrams ...................................................................................................................... 19
D. EVALUATION. .................................................................................................................................. 21
E. REFERANCES. ................................................................................................................................... 21

A INTRODUCTION
I. Programming Language

1. Definition

A programming language consists of a vocabulary containing a set of grammatical rules intended


to convey instructions to a computer or computing device to perform specific tasks.

Each programming language has an unique set of keywords along with a special syntax to organize
the software‟s instructions.

2. Programming Languages

- There about 700 programming languages in the world, but 10 most popular Programming
Languages are Python, JavaScript, Java, C#, C, C++, GO, R, Swift, PHP.

3. Features

The popularity of a programming language depends on the features and utilities it provides to
programmers. The features that a programming language must have to stand out are the following:

Simplicity: the language must offer clear and simple concepts that facilitate learning and application, in a
way that is simple to understand and maintain. Simplicity is a difficult balance to strike without
compromise the overall capability.

Naturalness: this means that its application in the area for which it was designed must be done naturally,
providing operators, structures and syntax for operators to work efficiently.

Abstraction: it is the ability to define and use complicated structures or operations while ignoring certain
low level details.

Efficiency: Programming languages must be translated and executed efficiently so as not to consume too
much memory or require too much time.

Structuring: the language allows programmers to write their code according to structured programming
concepts, to avoid creating errors.

Compactness: with this characteristic, it is possible to express operations concisely, without having to
write too many details.
Locality: refers to the code concentrating on the part of the program with which you are working at a
given time.

II. Procedural Programming.

1. Introduction and general concept

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.

2. Features

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.

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.

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.

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.

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

B. ANALYSIS

I. Analyse the problem

Problem: write a small application to manage the grades of a class.

To enter student ID, student's score and store this information in 2 separate arrays (integer
array for ID and float array for grades), we need to declare the correct data type for each
attribute. To have a menu based on options and an option to exit the program, we need to
use a do-while loop. To display all the data of all students, we need to use for loop in void
function. To know which student has the highest score and the lowest score, we need to use
the function that returns no input parameters (int main()), and a conditional statement (if).
II. Variables needed

1. Variables

Variables are containers for storing data values.

In C, there are different types of variables (defined with different keywords), for example:
int - stores integers (whole numbers), without decimals, such as 123 or -123.
float - stores floating point numbers, with decimals, such as 19.99 or -19.99.
char - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes.

2. Declaring variables
To create a variable, specify the type and assign it a value:
Syntax:
type variableName = value;

Where type is one of C types (such as int), and variableName is the name of the variable (such as
x or myName). The manner in which variables are declared varies by programming language.

3. How to declare variable


To save time, we can declare as many variables and assign as many values to them as we like
according on the circumstances.
Example:

The table below can be used to better understand how declared types are formatted in my
assignment:

Variable’s name Data type Explanation


name[100] char I declare name[100] with the
function to add each
student's name with a
maximum of 100 characters.
id int declared as a global variable.
Letters will be unavailable
when we use int variable.
grade float the float variable helps me to
print out the most accurate
student score with decimals.
s int This variable represents the
number of elements in the
array.
i int This variable is used in the for
loop, it represents an element
in the array.
choice int It is used as a global variable.
max, min float They are used in function
„findMax‟ or „findMin‟, I
declare them as local variables.
They help me to find the actual
maximum or minimum value
with the float variable.

III. Data types needed in the problem

1. What is data type?

Just like the name suggests, here, data types refer to the type of data that we are using in a C
program. Whenever we utilize a data type in a C program, we define the variables or functions used in it.
We do so because we must specify the type of data that is in use, so that the compiler knows exactly what
type of data it must expect from the given program.

2. Types of Data Types in C

Here are the five major categories into which data types are divided in C language:
The basic data types are also known as the primary data types in C programming.

3. Data types needed in the problem

- The char Data Type

This data type basically refers to all the character values that get enclosed in single quotes. Also, this data
type ranges from -127 to 127.

As we can see, we can use any of the smaller integer values in a char data type.

For instance,

- The float Data Type

We use the float data type for storing all the real numbers. These may have both, the exponential part as
well as the decimal part (or the fraction part). It is basically a single-precision type of number.

For instance,

Just like the data type „int‟, we can also use the float data type along with various modifiers.

- The int Data Type

We use the int data type for storing the whole numbers that might be values that have no exponential
part or decimal part in the number.

We can store the octal (or base 8), hexadecimal (or base 16), and decimal (or base 10) in the data
types.
For instance,

When we use the int data type in a program, then we must use the suffix “u” or “U” so that the compiler
can interpret the available value of the unsigned data type. On the other hand, we use the suffix “l” or “L”
when using a long int value in a program.

- Structure

Structure is one of the derived data types, it‟s basically derived out of the fundamental data types. A
derived data type won‟t typically create a new data type – but would add various new functionalities to the
existing ones instead.

Structure is a collection of various different types of data type items that get stored in a contagious
type of memory allocation is known as structure in C.

Example:

IV. Data structures needed in the problem

1. Definition

A data structure is a specialized organization for arranging, processing, recovering, and storing data.
While there are several basic and propelled structure types, any data structure is designed to mastermind
data to suit a specific purpose so that it very well may be accessed and worked in unseemly ways.

in C programming language, Data Structures are used to store data in an organised and efficient
manner. The C Programming language has many data structures like an array, stack, queue, linked list,
tree, etc. A programmer selects an appropriate data structure and uses it according to their convenience.
2. Data structures needed in the problem
- ARRAY

An Array is a sequential collection of elements, of the same data type. They are stored sequentially in
memory. An Array is a data structure that holds a similar type of elements.

Element − Each item stored in an array is called an element.

Index − Each location of an element in an array has a numerical index, which is used to identify the
element.

One - Dimensional Arrays:

3. Conclusion

Data structures are essential for properly managing large amounts of data, such as data stored in
databases or ordering administrations. Data structures can assist with memory designation, data
relationships, and data processes, all of which are necessary for the legitimate support of data systems.
Data structures are therefore extremely important in business. In a nutshell, it's the initial, fundamental
step toward actually achieving something worthwhile with your data.

V. Conditional statements needed in the problem

1. What is Conditional Statements?

Conditional Statements in C programming are used to make decisions based on the conditions.
Conditional statements execute sequentially when there is no condition around the statements. If you put
some condition for a block of statements, the execution flow may change based on the result evaluated by
the condition. This process is called decision making in „C.‟

In „C‟ programming conditional statements are possible with the help of the following two constructs:

1. If statement
2. If-else statement

It is also called as branching as a program decides which statement to execute based on the result of
the evaluated condition.

2. Conditional Statements
- If statement
If statement is responsible for modifying the flow of execution of a program. If statement is always
used with a condition. The condition is evaluated first before executing any statement inside the body
of If. The syntax for if statement is as follows:

The condition evaluates to either true or false. True is always a non-zero value, and false is a value
that contains zero. Instructions can be a single instruction or a code block enclosed by curly braces { }.

Following program illustrates the use of if construct in „C‟ programming:

Output:

The above program illustrates the use of if construct to check equality of two numbers.

- The if - else statement


The if-else is statement is an extended version of if. The general form of if-else is as follows:

In this type of a construct, if the value of test-expression is true, then the true block of statements
will be executed. If the value of test-expression if false, then the false block of statements will be
executed. In any case, after the execution, the control will be automatically transferred to the
statements appearing outside the block of if.

Following programs illustrate the use of the if-else construct:

We will initialize a variable with some value and write a program to determine if the value is less
than ten or greater than ten.
Output:

In „C‟ programming we can use multiple if-else constructs within each other which are referred to
as nesting of if-else statements.

VI. Loop statement needed in the problem


1. Loop statement

Looping Statements execute the sequence of statements many times until the stated condition becomes
false. A loop consists of two parts, a body of a loop and a control statement. The control statement is a
combination of some conditions that direct the body of the loop to execute until the specified condition
becomes false. The purpose of the loop is to repeat the same code a number of times.

2. Types of Loops

Depending upon the position of a control statement in a program, looping statement in C is classified
into two types:

1. Entry controlled loop


2. Exit controlled loop

In an entry control loop, a condition is checked before executing the body of a loop. It is also called as
a pre-checking loop.

In an exit controlled loop, a condition is checked after executing the body of a loop. It is also called as
a post-checking loop.
The control conditions must be well defined and specified otherwise the loop will execute an infinite
number of times. The loop that does not stop executing and processes the statements number of times is
called as an infinite loop. An infinite loop is also called as an “Endless loop.” Following are some
characteristics of an infinite loop:

1. No termination condition is specified.


2. The specified conditions never meet.

The specified condition determines whether to execute the loop body or not.

„C‟ programming language provides us with three types of loop constructs:

+ The while loop


+ The do-while loop
+ The for loop
- While Loop

A while loop is the most straightforward looping structure. While loop syntax programming language is as
follows:

Following program illustrates while loop example:

Output:
- Do - While loop

A do…while loop is similar to the while loop except that the condition is always executed after the body
of a loop. It is also called an exit-controlled loop.

Syntax of do while loop is as follows:

The following loop program illustrates the working of a do-while loop:

Output:
- For loop

A for loop is a more efficient loop structure in „C‟ programming. The general structure of for loop
syntax is as follows:

The initial value of the for loop is performed only once.

The condition is a Boolean expression that tests and compares the counter to a fixed value after each
iteration, stopping the for loop when false is returned.

The incrementation/decrementation increases (or decreases) the counter by a set value.

Following program illustrates the for loop example:

Output:
The for loop can have multiple expressions separated by commas in each part.

C. DESIGN
I. WBS

It is the work breakdown structure of the system, or more specifically, it is the WBS of breaking
down the issues of the Students Management System into manageable chunks, as you can see in
the picture below. And as you can see, when users access the system, the menu will be the first
thing they have. All of the features that are available in the system, in this case, the student
management system. These had three main functions: input ID, name, grade of the student, show
the highest and lowest grade, and quit. After Input student's information, users can also display all
the student's data.
II. Use case diagram

III. Flow chart diagrams

1. Menu operation
As you can see, after input menu, there are 3 options with each function for user to choose. After you
choose option 1 or option 2, the program could still continue, only when you select the 3rd option will the
program end.

2. print data

As the diagram shows, when you input all the data, it will display all the data that you entered.

3. Finding max grade and min grade.


Find min: first we need to assign 1 value in array to min. Use for loop to compare the elements in the array
with each other, the element less than min will become min.

Find max: first we need to assign 1 value in array to max. Use for loop to compare the elements in the
array with each other, the element greater than max will become max.

D. EVALUATION
To evaluation my solution, the knowledge of the programming language, procedural programming, data
types, data structures, conditional statements, loop statement is covered in what I mentioned above. I
believe that my proposed solution is still insufficient; there are still some drawbacks that must be
remedied, such as the absence of some student properties and some teacher-useful functions. But in
exchange, my program functions flawlessly and without any errors.

E. REFERANCES
Anon., n.d. CHAKRAY. accessed 26.6.2022
https://www.chakray.com/programming-languages-types-and-features/

Sagar Bhatia, 2020. Hackr.io. accessed 26.6.2022


https://hackr.io/blog/procedural-programming/

Anon, n.d. BYJUS. accessed 26.6.2022


https://byjus.com/gate/data-types-in-c/

Barbara Thompson, June 4, 2022. accessed 26.6.2022


https://www.guru99.com/c-loop-
statement.html#:~:text=A%20loop%20in%20C%20consists,code%20a%20number%20of%20times.

PREETI GHOSH. MAY 18, 2020. accessed 26.6.2022


https://whataftercollege.com/business-analytics/data-structures-in-business-analytics/

Barbara Thompson. Updated April 23, 2022. accessed 26.6.2022


https://www.guru99.com/c-if-else-statement.html

You might also like