0% found this document useful (0 votes)
167 views23 pages

Assignment 1 Front Sheet: Qualification BTEC Level 5 HND Diploma in Computing

The document outlines an assignment for a programming unit, including: 1) Tasks that involve identifying variables, data types, selection structures, iteration constructs, and splitting a program into functions. 2) A section summarizing key features of procedural programming such as predefined functions, local/global variables, modularity, and passing parameters. 3) Details on defining and declaring variables in C including allowed characters, case sensitivity, basic variable types like char, int, float, and void.

Uploaded by

steve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views23 pages

Assignment 1 Front Sheet: Qualification BTEC Level 5 HND Diploma in Computing

The document outlines an assignment for a programming unit, including: 1) Tasks that involve identifying variables, data types, selection structures, iteration constructs, and splitting a program into functions. 2) A section summarizing key features of procedural programming such as predefined functions, local/global variables, modularity, and passing parameters. 3) Details on defining and declaring variables in C including allowed characters, case sensitivity, basic variable types like char, int, float, and void.

Uploaded by

steve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

ASSIGNMENT 1 FRONT SHEET

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 GCH200329

Class GCH0903 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 D1

1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:

2
A Task 1
I. PROGRAMMING LANGUAGE
1. Programming language
2. Compile

3. Types of language
4.Interpreter
II. MAIN FEATURES OF PROCEDURAL PROGARMMING
B. TASK 2
I. Identify the variables and data types required in the program.
1. Variable Definition
2. Variable Definition
3. Variable Declaration
4. Data type
II. Identify and describe 2 different selection structures

1. 2 control structures:
III. Identify and describe any iteration constructs
1. For loop
2. While loop
3. Do..while loop.
4.Conclude

IV. Split the program into functions (sub-functions)


1. Modules

C. Task 3.

I. A use case diagram for actions required

III. Reviewing
D. REFERENCES

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

4
(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)

5
B. TASK 2
I. Identify the variables and data types required in the program.
A variable is nothing but a name given to a storage area which can be controlled by our programs. Each
variable in C has a particular form that specifies the variable's memory size and layout; the range of values
that can be stored in that memory; and the collection of operations that can be applied to that variable.
A variable name may consist of letters , numbers, and underscores. It has to start either with a letter or
with an underline. There are different upper and lowercase letters because C is case-sensitive. Based on
the basic types explained in the previous chapter, there will be the following basic variable types:

No. Type name and 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.
4
Double
A double-precision floating point value.
5
void
Represents the absence of type.

There are also some rules for naming C variable:


1. Variable name must begin with letter or underscore.
2. Variables are case sensitive
3. They can be constructed with digits, letters.
4. No special symbols are allowed other than underscore.
5. sum, height, _value are some examples for variable name

2. Variable Definition
A variable definition tells the compiler where and how much storage to create for the variable. A variable
definition specifies a data type and contains a list of one or more variables of that type. For example:
Int I, j, k;
Char c, ch;
Float f;
Double d;

6
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
- unsigned short int
- unsigned int
- int
- long int
- unsigned long int
- long long int
- unsigned long long int
- signed char
- unsigned char
- float
- double
- long double

7
MEMORY FORMAT
DATA TYPE (BYTES) RANGE SPECIFIER

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

-2,147,483,648 to
int 4 2,147,483,647 %d

-2,147,483,648 to
long int 8 2,147,483,647 %ld

unsigned long int 8 0 to 4,294,967,295 %lu

long long int 8 -(2^63) to (2^63)-1 %lld

unsigned long 0 to
long int 8 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

8
II. Identify and describe 2 different selection structures
1. 2 control structures:
Algorithm: A problem solving technique with regard to the actions to execute the order in which will
perform the actions
Pseudocode:" fake "code for" fake "code, describing the action status in English lets a programmer "think
out" the issue and "think out" the problem.Alternative but does not execute.

Control / Execution Flow: implemented with three simple basics Structure forms.
Sequential: default mode; Line by line, one right after the other, executed.
When there are two or more alternatives. Three types:
If
if...else

if(current + k <= N){

for(int i = current; i < current + k; i++){


printf("%d. Nvien %d: \n", i+1, i+1);
printf("Nhap ten: \n");
getchar();
scanf("%[^\n]s", ten[i]);

printf(" ID: \n");


scanf("%d", &ids[i]);

printf("Tgian: \n");
scanf("%f", &tgin[i]);

}
current += k;
system("cls");
}else{

9
printf("\chi co the luu tru nhieu nhat %d nhan vien.\n\n", N);
}

Switch
Example for Switch case:
1. switch(choice){
2. case 1:
3. printf("ban chon lua chon 1!!!\n");
4. break;

5. case 2:
6. printf("ban chon lua chon 2 !!!\n");
7. break;
8. case 3:
9. printf("ban chon lua chon 3 !!!\n");
10. break;

11. case 4:
12. printf("ban chon lua chon 4 !!!\n");
13. break;
14. case 5:
15. printf("ban da thoat chuong trinh\n");
16. printf("Tam biet.\n");

17. break;
18. default:
19. printf("khong co lua chon %d. ", choice);
20. printf("Hay nhap lai\n");
21. break;

10
22. }

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***

11
I will use the Switch case to split Menu requests into multiple options. Allows users to select the required
requirements.

III. Identify and describe any iteration constructs


A loop is used to execute a block of statements repeatedly until a certain condition returns false.

1. For loop

“This statement is used to repeat a statement or a set of statements for a specified number of times or
until a condition satisfied.”
(Cognizant, Handout: Problem Solving, 2007)

(For loop Flowchart, C for Loop (With Examples), http://programiz.com/ ,

https://www.programiz.com/c-programming/c-for-loop )

“How for loop works?

The initialization statement is executed only once.

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

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

14
The count is initialized to 1 and the test expression is evaluated. Since the test expression count<=num
(1 less than or equal to 10) is true, the body of for loop is executed and the value of sum will equal
to 1.

Then, the update statement ++count is executed and the count will equal to 2. Again, the test expression
is evaluated. Since 2 is also less than 10, the test expression is evaluated to true and the body of for loop
is executed. Now, the sum will equal 3.

This process goes on and the sum is calculated until the count reaches 11.

When the count is 11, the test expression is evaluated to 0 (false), and the loop terminates.

Then, the value of sum is printed on the screen.”

(C for Loop (With Examples), http://programiz.com/ ,

https://www.programiz.com/c-programming/c-for-loop )

2. While loop

“In most computer programming languages, awhile loop is a control flow statment that allows
code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of
as a repeating if statement .”
(2020, While loop, http://en.wikipedia.org/ , https://en.wikipedia.org/wiki/While_loop )

15
(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.

16
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

17
#include <stdio.h> int main()
{
int j=0; do
{
printf("Value of variable j is: %d\n", j);
j++;
} while (j<=3);
return 0; }

Output:

Value of variable j is: 0


Value of variable j is: 1
Value of variable j is: 2
Value of variable j is: 3”

(C/C++ do while loop with Examples – GeeksforGeeks, GeeksforGeeks,


https://www.geeksforgeeks.org/c-c-do-while-loop-with-examples/ )

4.Conclude.

In my program, I use the do ... while loop in the body of the program. Purpose of creating the menu. If
the user selects a digit outside the program menu. The program will execute the loop.

IV. Split the program into functions (sub-functions)


“A function is a group of statements that together perform a task. Every C program has at least one
function, which is main(), and all the most trivial programs can define additional functions. You can
divide up your code into separate functions. How you divide up your code among different functions is
up to you, but logically the division is such that each function performs a specific task. A function
declaration tells the compiler about a function's name, return type, and parameters. A function definition
provides the actual body of the function. The C standard library provides numerous built-in functions
that your program can call. For example, strcat() to concatenate two strings, memcpy() to copy one
memory location to another location, and many more functions.”
(C - Functions – Tutorialspoint, http://tutorialspoint.com/,
https://www.tutorialspoint.com/cprogramming/c_functions.htm )

1. Modules

A function definition in C programming consists of a function header and a function body. Here are all
the parts of a function

Return Type − A function may return a value. The return_type is the data type of the value the function
returns. Some functions perform the desired operations without returning a value. In this case, the
return_type is the keyword void.

18
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, 2: Print employee 3:find maximum, 4: Determine


overtime 5: end
working hours informations avarage, minimum

ID Working hours Name Maximum hours Avarage Minimum

19
(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.

20
Flow chart diagrams for primary functions.
-- All employee IDs and their working hours must be printed. Both elements of the array ID must be
printed with the elements of the corresponding array marker.
-- With the for loop, to do this.
-- First of all, we test the variable with n. Print I d and label at position 0 if correct, then increase the count
variable to 1 and begin the loop. If the mistake has not been repeated and the loop exits,

III. Reviewing

21
I will use the while loop and the case for switching so that the menu can be used by the user. Upon
completion of the feature, they can select other menu functions. If you choose 1 to 5, it is possible to
repeat the program. The number 6 alternative is for the user to exit the software.

With the mark [n] and I d [n] arrays available. All IDs can be printed with employee accents.

-- All employee IDs and their working hours must be printed. Both elements of the array ID must be
printed with the elements of the corresponding array marker.
-- With the for loop, to do this.
-- First of all, we evaluate the variable with n. Print I d and label at position 0 if correct, then increase the
count variable to 1 and begin the loop. If the mistake hasn't been repeated, exit the loop. In order to find
the average value of the working time of that business, I will use the AVG function. The user will then
know who is working hard and who is not working hard.

22
D. REFERENCES:
Bunch, G., 2020. Types Of Coding Languages Guide | Career Karma. [online] Career Karma. Available at:
<https://careerkarma.com/blog/types-of-coding-languages/#highlevel-programming-languages> [Accessed 15
October 2020].

Tutorialspoint.com. 2020. C - Variables - Tutorialspoint. [online] Available at:


<https://www.tutorialspoint.com/cprogramming/c_variables.htm> [Accessed 15 October 2020].

fresh2refresh.com. 2020. C Variable With Examples. [online] Available at: <https://fresh2refresh.com/c-


programming/c-
variables/#:~:text=C%20variable%20is%20a%20named%20location%20in%20a,the%20data%20type%20like%20i
nt%2C%20float%2C%20char%20etc.> [Accessed 15 October 2020].

GeeksforGeeks. 2020. Data Types In C - Geeksforgeeks. [online] Available at:


<https://www.geeksforgeeks.org/data-types-in-
c/#:~:text=Following%20are%20the%20examples%20of%20some%20very%20common,point%20value%29%20wit
h%20single%20precision.%20More%20items...%20> [Accessed 15 October 2020].

Learnprogramo. 2020. Types Of Programming Language [ With Explanation ] - Learnprogramo. [online] Available
at: <https://learnprogramo.com/types-of-programming-language-5/> [Accessed 15 October 2020].

Hackr.io. 2020. What Is Procedural Programming? [Definition] - Key Features. [online] Available at:
<https://hackr.io/blog/procedural-programming> [Accessed 15 October 2020].

23

You might also like