Introduction to Procedural Programming in C Language, Assignments of Computer Science

Introduction and presentation about programming language

Typology: Assignments

2020/2021

Uploaded on 03/26/2021

Janesmithlol
Janesmithlol 🇻🇳

5

(2)

1 document

1 / 31

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 0: Procedural Programming
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Dong Minh Quan
Student ID
GCH200669
Class
GCH0905
Assessor name
Nguyen Dinh Tran Long
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
Quan
Grading grid
P1
P2
P3
M1
M2
D1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f

Partial preview of the text

Download Introduction to Procedural Programming in C Language and more Assignments Computer Science in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 0 : Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Dong Minh Quan Student ID GCH Class GCH0905 Assessor name Nguyen Dinh Tran Long 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 Quan Grading grid P1 P2 P3 M1 M2 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Task I. Introduction to Procedural Programming

  1. Introduction and presentation about programming language

1.1 What is programming language?

  • A programming language is a standardized language that follows a set of rules that allows programmers to describe working programs for electronic devices, as well as humans and other devices that understand it.
  • A computer's vocabulary consists solely of the numbers 1 and 0 (binary). (Nguyễn, 2019) Figure 1 - Programming language.

1.2 Levels of programming languages

  • There are two classifications Low-Level High-Level
  • Low-Level programming languages are closer to machine code, or binary so they are more difficult for humans to read. But they are fast and give us precise control of the computer.
  • High-level programming languages are closer to humans’s communication because they use words that are closer to words we use in our lives ( object, order, run,request,…). They are easier to program in than low-level programming languages. (Team, 2020) Figure 2 - Low-Level programming language Figure 3 - High-Level programming language
  1. Examples for programming languages
    • Program to display “Hello World”
    • Output:
    • If_else codition program Figure 5 - Display “Hello World” Figure 6 - If_else codition program
  • Output:
  • Program to find size of variables
  • Output: Figure 7 - Program to find size of variables

A. Features of Procedural Programming

  • 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.
  • 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. Advantages and Disadvantages of Procedural Programming a) Advantages

  • Procedural programming is a great way to program in general.
  • The coded simplicity, as well as the ease with which compilers and interpreters can be implemented.
  • A wide range of books and online course materials on tried algorithms are available, making it easier to learn as you go.
  • Since the source code is versatile, it can also be used to target a different CPU as well.
  • The code can be reused without having to copy it in various sections of the software.
  • The memory requirement is also reduced using the Procedural Programming technique.
  • The program flow can be tracked easily. b) Disadvantages
  • If Procedural Programming is used, the program code is more difficult to write.
  • 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 process is prioritized over the data, which can cause problems in data-sensitive situations.
  • The data is exposed to the whole program, making it not so much security friendly. (Bhatia, 2021)

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

1.1 Variable definition

  • A variable definition tells the compiler where to store the variable and how much of it to create. A data type is specified by a variable definition, which contains a list of one or more variables of that type, as shown below: 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.

1.2 Variable Declaration

A variable declaration assures the compiler that there is only one variable of the given type and name, allowing the compiler to continue compiling without needing all of the variable's details. A variable declaration only has meaning when the program is being compiled; the compiler requires actual variable definition when the program is being linked.

1.3 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 Data Type Memory (bytes) Range Format 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 int 4 - 2,147,483,648 to 2,147,483,647 %d long int 4 - 2,147,483,648 to 2,147,483,647 %ld unsigned long int 4 0 to 4,294,967,295 %lu long long int 8 - (2^63) to (2^63)- 1 %lld

If users want to input students’ information, they should choose option 1. And choose option 2 to print it on screen. With this function, my program can have more functions that users need to do with their information, ex: finding the highest mark and who has that.

  • “If” statement function: Allows us to make a decision in the programs. Allow programs to test certain condition and make decision about which code block to be executed. In my program, “if” statement is used for finding the highest or the lowest mark in memory that users input.
  • Example: In this example, min is known as the lowest mark that we need to find out. If min is higher than one element (the condition is true), min will get new value and this new value is equal to that elemen
  1. Identify and describe any iteration constructs
    • A looploop is used to execute a block of statements repeatedly until a certain condition returns false.
    • For loop:
    • The initialization statement is executed only once.
    • 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. (Anon., n.d.) Figure 9 - For loop Flowchart

Output:

  • While loop: Figure 10 - While loop flow chart

Example: Output: