Download as pdf or txt
Download as pdf or txt
You are on page 1of 39

Higher Nationals in Computing

Unit 0: Procedural Programming


ASSIGNMENT 1

Learner’s name: Vo Duc Tai


ID: GCS210942
Class: GCS1005C
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

Student Name Vo Duc Tai Student ID GCS210942

Class GCS1005C 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
P age |1
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.

P age |2
Table of Contents

P1. Provide an introduction to procedural programming


1. Introduction an introduction to procedural programming .................................................... 6
1.1. Definition ........................................................................................................................... 6
1.2. High level programming ..................................................................................................... 6
1.3. Low level programming ...................................................................................................... 7
2. Introduction to procedural programming .............................................................................. 8
2.1. Definition ........................................................................................................................... 8
2.2. Introduction to C Programming Language .......................................................................... 9
3. Criteria to select a programming language to use ............................................................... 10
P2. Identify the program units and data and file structures required to implement a given
design.
1. Variables ............................................................................................................................. 10
1.1. Definition ......................................................................................................................... 10
1.2. Rules for naming a variable ............................................................................................. 11
2. Data types ........................................................................................................................... 11
2.1. Definition ......................................................................................................................... 11
2.2. Types of data types in C .................................................................................................... 11
3. Selection structures(Conditional Statements)
3.1. If statement ...................................................................................................................... 13
3.1.1. Syntax ............................................................................................................................ 13
3.1.2. Example ......................................................................................................................... 13
3.2. if..else ............................................................................................................................... 14
3.2.1. Syntax ............................................................................................................................ 14
P age |3
3.2.2. Example ......................................................................................................................... 14
3.3. If.. else if ........................................................................................................................... 15
3.3.1. Syntax ............................................................................................................................ 15
3.3.2. Example ......................................................................................................................... 16
3.4. Switch..case ...................................................................................................................... 17
3.4.1. Syntax ............................................................................................................................ 17
3.4.2. Example ......................................................................................................................... 17
4. Iteration structures ............................................................................................................. 18
4.1. For statement ................................................................................................................... 18
4.1.1. Syntax ............................................................................................................................ 18
4.1.2. Example ......................................................................................................................... 18
4.2. while statement ............................................................................................................... 18
4.2.1. Syntax ............................................................................................................................ 18
4.2.2. Example ......................................................................................................................... 19
4.3. do..while .......................................................................................................................... 19
4.3.1. Syntax ............................................................................................................................ 19
4.3.2. Example ......................................................................................................................... 19
5. External modules ................................................................................................................. 20
5.1. stdio.h library ................................................................................................................... 20
5.1.1. printf ............................................................................................................................. 20
5.1.2. scanf .............................................................................................................................. 20
5.2. string.h library .................................................................................................................. 21
5.3. math.h library ................................................................................................................... 21
P3. Design a procedural programming solution for a given problem
1. Requirements of the given scenario .................................................................................... 22
2. Use case diagram ................................................................................................................ 22

P age |4
3. Flowcharts ........................................................................................................................... 23
4. pseuso code ....................................................................................................................... 30

References ........................................................................................................... 33

P age |5
ASSIGNMENT 1 ANSWERS
P1. Provide an introduction to procedural programming
1. Introduction to computer programming languages.
1.1. Definition
-Computer programming languages allow us to give instructions to a computer in a language
the computer understands. Just as many human-based languages exist, there are an array of
computer programming languages that programmers can use to communicate with a
computer. The portion of the language that a computer can understand is called a “binary.”
Translating programming language into binary is known as “compiling.” Each language, from C
Language to Python, has its own distinct features, though many times there are commonalities
between programming languages.
- A programming language is a computer language programmers use to develop
software programs, scrips,or other sets of instructions for computers to execute.
- Although many languages share similarities, each has its own syntax. Once a
programmer learns the languages rules, syntax, and structure, they write the source code in
a text editor or IDE. Then, the programmer often compiles the code into machine
language that can be understood by the computer. Scripting languages, which do not require a
compiler, use an interpreter to execute the script

1.2. High level programming


- A high-level language (HLL) is a programming language such as C, FORTRAN, or
Pascal that enables a programmer to write programs that are more or less independent of a

P age |6
particular type of computer. Such languages are considered high-level because they are closer
to human languages and further from machine languages.
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.
- Examples: Python, Visual Basic, Delphi, Perl, PHP, ECMAScript, Ruby, C #, Java,
Pascal.
- 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

1.3. Low level programming


- Low-level languages are designed to operate and handle the entire hardware and
instructions set architecture of a computer directly.

Low-level languages are considered to be closer to computers. In other words, their prime
function is to operate, manage and manipulate the computing hardware and components.
Programs and applications written in a low-level language are directly executable on the
computing hardware without any interpretation or translation.

P age |7
Machine language and assembly language are popular examples of low-level languages.

2. Introduction to procedural programming


2.1. Definition
- Procedural programming is a concept of programming that specifies a sequence of
well-structured steps and procedures (functions or sub-routines) within its programming
context to create a program.
It is set of instructions step by step that a computer must follow.
A procedural programming can consists of a series of conditions and function called logic and
it's output is very
linear. Procedures or functions or sub-routines are implemented on the data and variables to
perform a task. These procedures can be called anywhere between the program hierarchy,
and by other procedures as well.
Procedural language is also called as imperative language.
Example:C, Pascal, and Basic.

P age |8
2.2. Introduction to C Programming Language
- C is a mid-level structured oriented programming language that is extremely popular, simple,
and flexible to use. It is a structured programming language that is machine-independent and
extensively used to write various applications, Operating Systems like Windows, and many
other complex programs like Oracle database, Git, Python interpreter, and more.
- The base or father of programming languages is ‘ALGOL.’ It was first introduced
in 1960. ‘ALGOL’ was used on a large basis in European countries. ‘ALGOL’ introduced
the concept of structured programming to the developer community. In 1967, a new
computer programming language was announced called as ‘BCPL’ which stands for Basic
Combined Programming Language. BCPL was designed and developed by Martin
Richards, especially for writing system software. This was the era of programming
languages. Just after three years, in 1970 a new programming language called ‘B’ was
introduced by Ken Thompson that contained multiple features of ‘BCPL.’ This
programming language was created using UNIX operating system at AT&T and Bell
Laboratories. Both the ‘BCPL’ and ‘B’ were system programming languages.
- ‘C’ is a powerful programming language which is strongly associated with the
UNIX operating system. Even most of the UNIX operating system is coded in ‘C’. Initially
‘C’ programming was limited to the UNIX operating system, but as it started spreading
around the world, it became commercial, and many compilers were released for cross-
platform systems. Today ‘C’ runs under a variety of operating systems and hardware
platforms. As it started evolving many different versions of the language were released.
At times it became difficult for the developers to keep up with the latest version as the
systems were running under the older versions. To assure that ‘C’ language will remain
standard, American National Standards Institute (ANSI) defined a commercial standard
for ‘C’ language in 1989. Later, it was approved by the International Standards
Organization (ISO) in 1990. ‘C’ programming language is also called as ‘ANSI C’.

P age |9
3. Criteria to select a programming language to use
- we don't choose the language. We choose the field, which is accompanied by
one, two or three languages. They are already "chosen" for us. By whom? By the industry,
market, historical accident, after all.

It is characteristic for beginners to concentrate on the language. The syntax, the grammar... –
they seem so important, so unfamiliar that draw all our attention. But it turns out that this is
just the tip of the iceberg. What's beneath the water?

- The environment (and the way) of executing: The Compiler / The Virtual Machine.

- Vendors and the Platform

- Ecosystem and Community.

- The demand and industry trends.

- Connections with other languages and ecosystems.

- The vision of the language.

P2. Identify the program units and data and file structures required to implement a given
design.
1. Variables
1.1. Definition:

Variable (computer science), a symbolic name associated with a value and whose
associated value may be changed
Variable (mathematics), a symbol that represents a quantity in a mathematical
expression, as used in many sciences
Variable (research), a logical set of attributes
- 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

P a g e | 10
because C is case-sensitive. Based on the basic types explained in the previous chapter, there
will be the following basic variable types.
- C programming language also allows to define various other types of variables,
which we will cover in subsequent chapters like Enumeration, Pointer, Array, Structure, Union,
etc. For this chapter, let us study only basic variable types.
1.2. Rules for naming a variable
* A variable name can only have letters(both uppercase and lowercase letters),
digits and underscore.
* The first letter of a variable should be either a letter or an underscore.
* There is no rule on how long a variable name(identify) can be. However, you may
run into problems in some compilers if the variable name is longer than 31
characters.
* Examples:
2. Data types
2.1. Definition
2.2. Types of data types in C
- A data type, in programming, is a classification that specifies which type of value a
variable has and what type of mathematical, relational or logical operations can be
applied to it without causing an error. A string, for example, is a data type that is used to
classify text and an integer is a data type used to classify whole numbers. - 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 a float 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. - Technically,
the concept of a strongly typed or weakly typed programming language is a fallacy. In
every programming language, all values of a variable have a static type -- but the type
might be one whose values are classified into one or more classes. And while some classes
specify how the data type’s value will be compiled or interpreted, there are other classes
whose values are not marked with their class until run-time. The extent to which a
programming language discourages or prevents type error is known as type safety.

P a g e | 11
Sr.no. Type & Description
1 Char
Typically a single octet(one byte). It is an integer type.

2 Int
The most natural size of integer for the machine.

3 Float
A single-precision floating point value.

P a g e | 12
4 Double
A double-precision floating point value.

5 Void
Represents the absence of type.

3. Selection structures(Conditional Statements)


3.1. If statement
3.1.1. Syntax
If (condition)
{
}

P a g e | 13
3.2. If..else
3.2.1. Syntax
If(condition)
{
}
Else
{
}
3.2.2. Example

P a g e | 14
3.3. If..else if
3.3.1. Syntax
If(condition 1)
{
}
Else if(condition 2)
{
}
Else
{
}

P a g e | 15
3.3.2. Example

3.4. Switch..case
3.4.1. Syntax
switch(expression)
{
case constant1:
break;
case constant2:
P a g e | 16
break;
.
.
.
default:
break;
}
3.4.2. Example

P a g e | 17
4. Iteration structures
4.1. For statement
4.1.1. Syntax()
For(condition)
{
}
4.1.2. Example

4.2. While statement


4.2.1. Syntax
while(condition)
{
}

P a g e | 18
4.2.2. Example

4.3. Do..while statement


4.3.1. Syntax
do {
.
.
.
} while(condition);
4.3.2. Example

P a g e | 19
5. External modules
5.1. Stdio.h library
5.1.1. printf

5.1.2. scanf

P a g e | 20
5.2. String.h library

5.3. Math.h library

P a g e | 21
P3. Design a procedural programming solution for a given problem
1. Requirements of the given scenario
- A small program has a menu
- Input IDs and Grades
- Show IDs and Grades
- Print highest grade
- Print lowest grade
- Exit application
2. Use case diagram

P a g e | 22
3. Flowchart
3.1. Input IDs, Grades
. Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
P a g e | 23
- 2 Print all student impressions
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 1
- 5 if selection is 1 then start to print IDs, Grades
- Save ID and Grade into it to array
- if choice is 5, exit the program and return to the menu
- End

P a g e | 24
3.2. Show IDs and Grade
P a g e | 25
Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
- 2 Print all student impressions
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 2
- 5 if selection is 2 then start to show ID and Grade
- if choice is 5, exit the program and return to the menu
- End

P a g e | 26
3.3. Print highest grade

P a g e | 27
. Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
- 2 Print all student impressions
P a g e | 28
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 3
- 5 if selection is 3 then start to find the highest grade else check if the
selection is 5
- if choice is 5, exit the program and return to the menu for the user to re-
enter the program to select other options. If it is a choice other than1,2,3,4,5 the same
will force the user to re-enter the options included int the condition

3.4. Print lowest grade


. Explanation:
- Selection: number of elements in array
. Steps:
1. Step 1: Declare variables: selection.
2. Step 2: Display the menu.
3. Step 3: Input selection
- 1 Enter student information
- 2 Print all student impressions
- 3 Print the highest grade
- 4 Print the lowest grade
- 4 check if the selection is 4
- 5 if selection is 4 then start to find the lowest grade else check if the
selection is 5
- if choice is 5, exit the program and return to the menu for the user to re-
enter the program to select other options. If it is a choice other than1,2,3,4,5 the same
will force the user to re-enter the options included int the condition

P a g e | 29
4. Pseuso code
4.1. Input id and grade
Start
- S1: declare variables: id, grade, option
- S2: show menu
- S3: Input option from the menu
- S4:if(option==1)
Begin
-Input id and grade
-Save id and grade in the ID array and grade array
P a g e | 30
- Back to S2
End
- S5: if(option==5)exit application
Stop

4.2. Show IDs and Grades


Start
- S1: declare variables: id, grade, option
- S2: show menu
- S3: Input option from the menu
- S4:if(option==2)
Begin
- Input id and grade
- Show IDs and grades
- Print highest grade
- Back to S2
End
P a g e | 31
- S5: if(option==5)exit application
Stop

4.3. Print highest grade


Start
- S1: declare variables: id, grade, option
- S2: show menu
- S3: Input option from the menu
- S4:if(option==3)
Begin
- Input id and grade
- Declare variables: float highest, int I=1.
Highest =grade[0]
- i< NoOfStudent
If true:
- Highest < Grades[0]
- Highest = Grades[0], i++
- Print highest grade
- Back to S2
End
- S5: if(option==5)exit application

P a g e | 32
Stop

4.4. Print lowest grade


Start
- S1: declare variables: id, grade, option
- S2: show menu
- S3: Input option from the menu
- S4:if(option==4)
Begin
- Input id and grade
- Declare variables: float highest, int I=1.
lowest =grade[0]
- I > NoOfStudent
If true:
- lowest > Grades[0]
- lowest = Grades[0], I--
- Print lowest grade
P a g e | 33
- Back to S2
End
- S5: if(option==5)exit application
Stop

REFERENCES

P a g e | 34
Instructions on how to write references:

1. Computersciencewiki.org(2022), Computer Programming Languages[Definition],[online].


Available at:

https://www.computerscience.org/resources/computer-programming-languages/[ Accessed
April 5,6 2022 ]

2. Computerhope.com,( 2021)Computer Programming Languages[Definition],[online].


Available at:

https://www.computerhope.com/jargon/p/programming-language.htm[ Accessed March


2022 ]

3. Wikipedia.org,( 2022), High Level Language[Definition],[online]. Available at:

https://en.wikipedia.org/wiki/High-level_programming_language[ Accessed May 6, 7 2022 ]

4. Wikipedia.org(2022), High Level Language[Definition],[online]. Available at:

https://en.wikipedia.org/wiki/High-level_programming_language[ Accessed May 6, 7 2022 ]


5. Wikipedia.org(2017), Low Level Language[Definition],[online]. Available at:

https://www.techopedia.com/definition/3933/low-level-language[ Accessed February 5, 6


2022 ]

6. the-definition.com, (2022) Procedural Programming [Definition],[online]. Available at:

Https://the-definition.com/term/procedural-programming[ Accessed January 2, 3 2022 ]

7. Guru99.com,(2022), C Programming Languages [Definition],[online]. Available at:

https://www.guru99.com/c-programming-language.html[ Accessed April 5 2022 ]

P a g e | 35
8. mkdev.me,( 2022 ) How to choose a programming language [Definition],[online]. Available
at:

https://mkdev.me/posts/how-to-choose-a-programming-language[ Accessed January 2, 3

2022 ]

9. tutorialspoint.com(2022), variable[Definition],[online]. Available at:

https://www.tutorialspoint.com/cprogramming/c_variables.htm[ Accessed January 2, 3 2022


]

10. Wikipedia.org(2022), Data Types [Definition],[online]. Available at:

https://en.wikipedia.org/wiki/Data_type[ Accessed January 2, 3 2022 ]

11. Techtarget.com,( 2016),Data Types [Definition],[online]. Available at:

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

P a g e | 36

You might also like