















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A mostly original report about Procedural Programming
Typology: Essays (university)
1 / 23
This page cannot be seen from the preview
Don't miss anything!
















Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Unit 0 : Procedural Programming
Submission date 16/10/2020 Date Received 1st submission
Re-submission Date Date Received 2nd submission
Student Name Nguyễn^ Minh^ Hiếu^ Student ID GCH^200329
Class GCH 0903 Assessor name Đỗ Hồng Quân
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 D
Grade: Assessor Signature: Date:
Lecturer Signature:
A Task 1
I. PROGRAMMING LANGUAGE
1. Programming language
A program is a number of commands that can be executed by a computer to be programmed by
The people. The program operates on the commands of programmers to accomplish the purpose of
Which it was created. It is also up to programmers to write code to run the program.
And training its consumers.
The data is obtained by the system and translated into a bit sequence 0 1. The Bit is the
The smallest data to be interpreted on the machine. The language of programming is the language for
programmers to write computer programs. Programming language refers to the degree of high
Tongue, language. C, C++, Ada, Pascal, ... For example , the purpose of these languages is to convert
Human languages are used in languages understood by computers. There are two ways of converting grogram: Program compilation and program interpretation.
2. Compile
Compile is a program that translates programming-language commands into a programming language In the form of a programming language and a lower level language, another equivalent program
3. Types of language
Low-level coding languages have a lower abstraction level and are the opposite of high-level languages, as you might expect. They are similar to the binary language and further from the language of man. Low- level languages are more difficult to learn and use, but offer more computer functionality and direct control.
While it can take more time and code lines to do the same as a high-level language, low-level languages are much less restrictive and allow programmers to produce much more comprehensive and efficient programming.
The languages of high-level coding have a higher abstraction level. This suggests that they are similar to the language of humans, and further from machine code. It is easier to learn and use high-level languages, but they generally offer less functionality and direct control over the computer.
High-level languages tend to be more automated, where many pre-programmed things are actually done by a single programming command to facilitate and make programming more efficient.
(Bunch, 2020)
(Types Of Programming Language [ With Explanation ] - Learnprogramo, 2020)
4.Interpreter
An interpreter is a program that implements instructions written in high level language
II. MAIN FEATURES OF PROCEDURAL PROGARMMING
Predefined functions: A predefined function is usually a name-identified instruction. The predefined functions are usually built into higher-level programming languages, but rather than the software, they are derived from the library or the registry. 'charAt)' (is an example of a predefined function, which searches for a character position in a string.
Local variable : A local variable is a variable that is declared in a method's main structure and limited to the local scope given to it. The local variable may only be used in the system in which it is specified, and the code will stop functioning if it is to be used outside of the defined method.
Global variable: A global variable is a variable that is declared beyond any other code-defined function. Owing to this, unlike a local variable, global variables can be used in all functions.
Modularity : Modularity is when two different systems have two separate tasks at hand, but are grouped together to first complete a larger task. When all tasks are completed, each group of systems will then have its own tasks completed one after the other.
Passing Parameters: Passing Parameters is a procedure that is used to pass parameters to functions, subroutines or processes. The passing of parameters can be done by 'pass by value', 'pass by reference', 'pass by result', 'pass by value-result' and 'pass by name'.
Programming libraries: Programming libraries are a collection of pre-built codes , routines, sub- routines, classes and values which can be used at any time by the program and it's users
(What is Procedural Programming? [Definition] - Key Features, 2020)
In which The line int i, j, k; declares and defines the variables i, j, and k; which instruct the compiler to create variables named i, j and k of type int.
3. Variable Declaration A variable declaration informs the compiler that a variable of the stated type and name exists, so that the compiler can continue with further compilation without needing full details of the variable. A variable definition only has its value at the time of compilation, at the time of linking the program, the compiler requires real variable definition.
(C variable with examples, 2020)
4. Data type 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. There are 13 types of primitive data types:
short int 2 - 32,768 to 32,767 %hd
unsigned short int 2 0 to 65,535 %hu
unsigned int 4 0 to 4,294,967,295 %u
int 4
long int 8
unsigned long int 8 0 to 4,294,967,295 %lu
long long int 8 - (2^63) to (2^63)- 1 %lld
unsigned long long int 8
0 to 18,446,744,073,709,551,615 %llu
signed char 1 - 128 to 127 %c
unsigned char 1 0 to 255 %c
float 4 %f
double 8 %lf
long double 16 %Lf
(Data Types in C - GeeksforGeeks, 2020)
Concluse:
With my plan, I will create 4 variables with integer data, 2 variables with float data and 1 with char data.
int x,y,z, choice;
float max,min;
char name[N]
I will enter multiple variables with two data types: int and float and the max and min variables store the values as real numbers
printf("\chi co the luu tru nhieu nhat %d nhan vien.\n\n", N);
}
Switch
Example for Switch case:
Repetition: used for looping, or repeating a section of code multiple times. Three types:
while
do...while
for
True and False: Statements that are executed are dependent on certain conditions that are evaluated either true or false. Condition represented by logical (Boolean) expression - can be true or false. An expression that evaluates to 0 is false. An expression that evaluates to a non-zero value is true
b. Relational operator
Relational operators : Allow comparisons, require two operands (binary). Return 1 (or nonzero integer) if expression true, otherwise 0 false. Comparing values of different data types may produce unpredictable results For example: 6 < '5' (compares integer 6 with character '5')
= = equal to
x == y
!= not equal to
x != y
< less than
x < y
<= less than or equal to
x <= y
greater than
x > y
= greater than or equal to
x >= y
BE CAREFUL!
'a' < 'A' evaluates to false!
Under the ASCII Collating Sequence: numbers < ucase letters < lcase letters
Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is terminated.
However, if the test expression is evaluated to true, statements inside the body of for loop are executed, and the update expression is updated.
Again the test expression is evaluated.
This process goes on until the test expression is false. When the test expression is false, the loop terminates.
Example 1: for loop
// Print numbers from 1 to 10 #include <stdio.h>
int main() {
int i;
for (i = 1 ; i < 11 ; ++i) { printf( "%d " , i); } return 0 ; }
Output
1 2 3 4 5 6 7 8 9 10
I is initialized to 1. The test expression i < 11 is evaluated. Since 1 less than 11 is true, the body of for loop is executed. This will print the 1 (value of i) on the screen. The update statement++i is executed. Now, the value of i will be 2. Again, the test expression is evaluated to true, and the body of for loop is executed. This will print 2 (value ofi) on the screen.
Again, the update statement ++i is executed and the test expression i < 11 is evaluated. This process goes on until i becomes 11.
When i becomes 11, i < 11 will be false, and the for loop terminates.
Example 2: for loop
// Program to calculate the sum of first n natural numbers // Positive integers 1,2,3...n are known as natural numbers
#include <stdio.h> int main() {
int num, count, sum = 0 ;
printf( "Enter a positive integer: " ); scanf( "%d", &num);
// for loop terminates when num is less than count for(count = 1 ; count <= num; ++count) { sum += count; }
printf( "Sum = %d" , sum);
return 0 ; }
Output Enter a positive integer: 10 Sum = 55
The value entered by the user is stored in the variable num. Suppose, the user entered 10.
(Flow Diagram of while loop,C - while loop in C programming with example, http://beginnersbook.com/ , https://beginnersbook.com/2014/01/c-while-loop/ ) “Example of while loop:
#include <stdio.h> int main() {
int count=1; while (count <= 4) { printf("%d ", count); count++; } return 0;
}
Step1: The variable count is initialized with value 1 and then it has been tested for the condition.
Step2: If the condition returns true then the statements inside the body of while loop are executed else control comes out of the loop.
Step3: The value of count is incremented using ++ operator then it has been tested again for the loop condition. ”
(2020, while loop in C programming with example, http://beginnersbook.com/ , https://beginnersbook.com/2014/01/c-while-loop/ )
3. Do..while loop****.
“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.”
(2020, C - do while loop in C programming with example, http://beginnersbook.com/ , https://beginnersbook.com/2014/01/c-dowhile-loop/ )
(Flow Diagram do-while loop, C/C++ do while loop with Examples – GeeksforGeeks, GeeksforGeeks, https://www.geeksforgeeks.org/c-c-do-while-loop-with-examples/ )
“Example of do while loop
Function Name − This is the actual name of the function. The function name and the parameter list together constitute the function signature.
Parameters − A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
Function Body − The function body contains a collection of statements that define what the function does.
C. Task 3.
I. A use case diagram for actions required
Menu
1: Insert name, ID, working hours
2: Print employee informations
ID Working hours Name
3:find maximum, avarage, minimum
Maximum hours Avarage Minimum
4: Determine overtime 5: end
(Flow chart diagram for main menu)
I will use the while loop and switch case so that the user can use the menu. they can select other menu functions after they complete the function. If you select 1 to 5, the program may repeat. The option number 6 is for the user to exit the program.