Procedural Programming: Understanding the Basics and Key Features, Assignments of Procedural Law

An introduction to procedural programming, explaining what it is, its key features, and the advantages and disadvantages of using this programming model. It also covers the concept of predefined functions, parameter passing, and data types in C, as well as the use of variables and iteration constructs such as while, for, and do-while loops.

Typology: Assignments

2021/2022

Uploaded on 12/06/2022

thai-van-chien
thai-van-chien 🇻🇳

5 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
PRG102: Procedural Programming
Submission date
19 June 2022
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Thai Van Chien
Student ID
GCH210162
Class
GCH1103
Assessor name
Lai Manh Dung
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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Procedural Programming: Understanding the Basics and Key Features and more Assignments Procedural Law in PDF only on Docsity!

ASSIGNMENT 1

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title PRG102: Procedural Programming Submission date 19 June 2022^ Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Thai Van Chien Student ID GCH Class GCH1103 Assessor name Lai Manh Dung 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

 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 Procedural Programming? Procedural programming may be the first programming model a new developer will learn. Basically, the procedure code is the code that directly instructs the device how to complete a task in reasonable steps. (Bhatia, 2022) This model uses a top-down linear approach and processes data and procedures like two different entities. Based on the concept of a procedural call, Procedural programming that divides the program into procedures, also known as routines or functions, simply contains a series of steps that are taken. As a program grows in size, it is divided into smaller units called procedures or functions. To complete a certain task, several functions are expected to be written. Since the same function is called from different locations, these functions prevent code duplication. Only medium-sized software systems are suitable for this technique. To put it simply, Procedural programming involves writing down a list of instructions to let the computer know what it must do step by step to complete the task at hand. 1. Procedural Programming

1.2 Introduction to Computer Programming Languages A programming language is a set of commands, instructions, and other syntax that is used to develop software. The languages used by programmers to write code are referred to as "high-level languages." This code can be turned into a "low-level language" that is immediately recognized by computer hardware. (Hemmendinger, 2021) There are two classifications:

  • Low-level programming languages are closer to machine code or binary code so it's harder for humans to read. But they are fast and give us the ability to control the computer accurately.
  • High-level programming languages are closer to human communication because they use words closer to the words we use in life( object, order, run,request,...). They are easier to program than low-level programming languages. 2. Programming languages
  1. 3 Key Features of Procedural Programming
  • Predefined functions: A predefined function is usually a command defined by name. Typically, predefined functions are built into higher-level programming languages, but they are derived from libraries or registers, not programs. An example of a predefined function is 'charAt ()', which looks for character positions in a string.
  • Local Variable: A local variable is a declared variable in the main structure of a method and is limited to the local extent to which it is provided. The local variable can only be used in the

3. Examples for Procedural Programming

The problem that need to resolve by making a small application is about Student Management: A math teacher wants to manage the grades of a class. He asks you to help him write a small app to do it. He needs to enter the student's full name, the student's score, and store this information in two separate arrays (integer array for full name and float array for grades). Finally, he needs to know which student has the highest and lowest grades. Your program must have a menu based on the options above. When an option is made, the program will return to the main menu so that he can choose another option. There should be an option to exit the program. Task II. Analysis of variables, data types, structure and usage

1. Identify the variables and data types required in C

A variable is nothing more than a name for a storage space that our programs may access. In C, each variable has a distinct type that determines its memory size and layout, as well as the range of values that may be stored in that memory and the set of operations that can be done on it. (tutorialspoint, 2022) Variable names can contain letters, digits, and underscores. It must start with a letter or an underline. Because C is case-sensitive, the upper and lowercase characters vary. The following basic variable types will be based on the preceding chapter's basic types: No. Type & Description 1 char Typical is a single octet (a byte). It's a kind of integer. 2 int The most natural size of the 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 various naming conventions for C variables: 1 .1 Variable definition The variable definition tells the compiler where and how much storage space to create for the variable. The variable definition specifies a data type and contains a list of one or more variables of that type as follows:

type variable_list; Here, the type must be a valid C data type including char, w_char, int, float, double, bool or any object defined by the user; and variable_list may include one or more identifiers separated by comma. Some valid declarations are displayed here: int i, j; char c; float f; double d; The line int i, j; declares and defines the variables i, j; which instruct the compiler to create variables named i, j of type int. Variables can be initiated (assigning the original value) in their declaration. The initializer consists of an equal sign followed by a constant expression as follows: type variable_name = value;

  1. 2 Data types The data types in c refer to an extended system used to declare variables or functions of different types. The type of a variable determines how much space it occupies in memory and how the bit pattern is interpreted. The following table provides detailed information about standard integer types with their storage size and value range: Data Type Format Specifier Minimal Range Typical Bit Size unsigned char %c 0 to 255 8 char %c - 127 to 127 8 signed char %c - 127 to 127 8 int %d, %i - 32,767 to 32,767 16 or 32 unsigned int %u 0 to 65,535 16 or 32 short int %hd - 32,767 to 32,767 16 unsigned short int %hu 0 to 65,535 16 long int %ld, %li - 2,147,483,647 to 2,147,483,647 32 long long int %lld, %lli - (263 – 1) to 263 – 1 (It will be added by the C standard) 64 unsigned long int %lu 0 to 4,294,967,295 32 unsigned long %llu 264 – 1 (It will be added by the C99 standard) 64

case y: // code block break; default: // code block } (W3school, n.d.) In my program, I use it to specify several choices that users may report and utilize in the "Menu options" section. For example, 1 is let the user Edit student, 2 for Delete student and 3 is Back to main menu. 2.2 If – else a) If Statement The if statement is used to check a supplied condition and conduct some operations based on the correctness of that condition. It is often employed in scenarios when we need to run multiple operations for distinct situations. The syntax of the if statement is shown below. b) If – else Statement The if-else statement is used to do two actions for a single circumstance. The if-else statement is an expansion to the if statement that allows us to do two separate actions, one for the correctness of the condition and the other for the incorrectness of the condition. We must keep in mind that the if and else blocks cannot be run concurrently. Using an if-else statement is usually preferable since it always invokes an otherwise case with every if condition. The syntax of the if-else expression is shown below.

In my program, the "if" statement is used to identify the highest or lowest mark in memory that users have entered.

3. Identify and describe iteration constructs

You may encounter situations where a block of code needs to be executed several times. In general, the statements are executed sequentially: The first statement in a function is executed first, followed by the second statement, etc. A repeating statement allows us to execute a statement or a group of statements over and over again. Here's the general form of repeating statements in most programming languages: (tutorialpoint, n.d.) 3.1 While The loop while in programming C repeatedly executes a target statement as long as a given condition is correct. while(condition) { statement(s); }

3.3 Do…while In contrast to for and while loops, which test the loop condition at the top of the loop, the do...while loop in C programming tests the loop condition at the bottom of the loop. A do...while loop is similar to a while loop in that it is guaranteed to run at least once. The syntax of a do...while loop in C programming language is: do { statement(s); } while( condition ); (tutoralpoint, n.d.) 6 Flow diagram in Do...while In the main body of my program, I employ the do...while loop. The goal of constructing the menu. If a digit is selected outside of the program menu. The loop will be executed by the software.

4. Hierarchy Diagram

7 Hierarchy Diagram In my program:

  1. The first option is to choose the input information of the student, Input information of the student: Fullname, Grades.
  2. The second option is to display student information on the screen.
  3. Finally, you may select Locate max, Min to find the students on the list with the highest and lowest scores.
  4. The application then loops so you may choose and import new students.
  5. And last, exit the application. Task 3: Design

1. Use-case diagram

Step 10: Read choice 4 Step 11: Print the value step 4 stored and go to step 2. Step 12: Read choice 0 Step 13 Print the value in choice 0, stored and then go to step 2. Step 14: Stop, Exit programing. 2.1 Display Explain flowchart: Step 1: Start Step 2: Set char fullname[100][31], float mark[100], size, i = 0. Step 3: Check the condition; if true, Go To step 4; if false go to step 5. Step 4: Print the fullname, mark. Step 5: i = i + 1. Step 6: Repeat step 3. Step 7: Next option. Step 8: Stop.

2.2 Find highest and lowest grades Explain flowchart: Step 1: Start Step 2: Set float mark[100], int I; imax = 0, imin = 0, size. Step 3: Check the condition, if true go to step 4, if false go to step 5. Step 4: Check the condition, if true go to step 6, if false go to step 5. Step 5: i = i + 1. Step 6: Check condition, if true go to step 7 , if false go to step 5. Step 7: Assign imax = i, imin = i Step 8: Print mark[imax], mark[imin]. Step 9 : Repeat step 3. Step 10: Next option. Step 11: Stop.

c) Improve:

  • Know numerous procedural languages without languages C.
  • Exploit more procedural programming difficulties.
  • Write more precise code. There are still many things to improve in my program, such as entering characters and creating variables into the scan, and storing information, which can create program issues. Based on my analysis of the benefits and negatives, I will assign myself needs and duties ranging from simple to complex to my thinking system.

Bibliography

Procedural Programming [Definition] (2022). Available at: https://hackr.io/blog/procedural-programming (Accessed: 7 June 2022). What are the characteristics of procedural programming? | KnowledgeBoat (2022). Available at: https://www.knowledgeboat.com/question/what-are-the-characteristics-of-procedural-programming-- 28311496451138200 (Accessed: 7 June 2022). Variables and Data Types - Writing Word Macros, Second Edition [Book] (2022). Available at: https://www.oreilly.com/library/view/writing-word-macros/9781565927254/ch05s04.html (Accessed: 7 June 2022). C - Variables (2022). Available at: https://www.tutorialspoint.com/cprogramming/c_variables.htm (Accessed: 7 June 2022). C - switch statement (2022). Available at: https://www.tutorialspoint.com/cprogramming/switch_statement_in_c.htm (Accessed: 7 June 2022). C if else Statement (2022). Available at: https://www.javatpoint.com/c-if-else (Accessed: 7 June 2022). C - Loops (2022). Available at: https://www.tutorialspoint.com/cprogramming/c_loops.htm (Accessed: 7 June 2022).