Docsity

Procedural Programming: Understanding Types, Functions, and Flowchart Diagrams, Assignments of Computer Programming

Toggle sidebar
bg1
xxxx ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: Procedural Programming
Submission date
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Student ID
Class
Assessor name
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
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20

Partial preview of the text

Download Procedural Programming: Understanding Types, Functions, and Flowchart Diagrams and more Assignments Computer Programming in PDF only on Docsity!

xxxx ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog 102 : Procedural Programming Submission date Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Student ID Class Assessor name 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:

TABLE OF CONTENS

I. INTRODUCTION

  1. Programming language 1.1. Definition A programming language is a collection of grammatical rules and a set of terminology for commanding a computer to conduct certain tasks. Some high-level languages such as BASIC, C, C++, FORTRAN, Java, COBOL, Ada and Pascal are recognized as programming languages. Each programming has an especial collection of keywords (words it recognizes) and syntax for structuring program instructions. (Beal, 2022) According to the 2021 Stackoverflow survey, there are the following popular programming languages: Figure 1 : Top most popular programming languages 2021 1.2. Types of programming language Programming langues set apart two species. They may be low-level or high-level languages Each kind of programming languege has its own purpose. Studying the difference between the two is a necessary step to figuring out which to use.

So, what exactly is the difference between them? And what does it mean for learning to write code? High-level programming languages are problem-oriented rather than machie-oriented. There are many diffirent high-level languages, and which high-levels you choose depends on the kind of problem you are trying to solve.

  • Feature abstraction
  • Are closer to human languages, and are more readable
  • Do not compromise with memory management
  • Example comprise: Python, C#, Jave and Ruby Low-level programming languages are defined by processor they are designed to run on; we can describe these languages as machie-oriented. They have no built-in funtions and can access specific registers in the processor.
  • Do not feature abstraction
  • Are readable by machies, and are not close to human language
  • Involve memory management
  • Examples comprise assembly language and machie code
  1. Introduction to C language C is a computer programming language. Used to generate instructions for the computer. C is a procedural programming language. It was created by Dennis Rich in 1972. Its primary purpose was to serve as a system programming language for the development of operating systems. Low-level memory access, a simple keyword set, and a compact style are all properties of the C language that make it suited for system programming, such as operating systems and compiler development.

Figure 3 : Procedural programming 3.2. The characteristics of procedural programming are:

  • A large program is divided into smaller, more manageable procedures or functions. A program written under the procedural programming paradigm has an easy-to-follow code flow. However, in this case, functions take the predence over data.
  • Different functions can exchange data using global variables. As a results, the programming paradigm comsumes less computer memory. Because functions are completely separated, we must declare data in a higher scope if we want to intercharge it. Furthermore, the usage of global data is error-prone and maybe a challenge in terms of maintenance and upgrades.
  • Functions have the ability to modify global data. The update of global data demands theadjustment of the funtions that rely on it. Because global data is sent from function to function, the global data in function chains to be altered throughout the transformation.
  • Procedural programming fllows a top-down approach, with workflow moving from top to bottom. In a program developed in the procedural programming paradigm, it is simpler to follow the flow of code. 3.3. Procedural Programming’s Key Features The following are the main characteristics of procedural programming: Predefined functions: A predefined is a kind of instruction that has a name attached to it. Predefined functions are usually included in higher-level programming languages. However,

they are drawn from a library or registry rather than a program. A pre-defined function that looks for a character position in a string is “charAt()”. Figure 4 : Predefined function Local Variable: A local variable is a variable that is primary to the method’s main structure and is only valid inside the method’s scope. The local variable can only be used in the method in which it is defined; if it is used outside of that function, the code will fail. Global Variable: A global variable is one that is declared outside of every other function in the program. As a result, unlike local variables, global variables can be utilized in any function. Modularity: When two different systems are assigned two discrete tasks to fulfill, they are combined to to complete a bigger task first. The tasks of each system would be completed one by one until all taks were accomplished. A parameter passing is the symbolic name for “data” that goes into a function. In C, there are two methods to pass parameters: Pass by Value, Pass by Reference.

  • Pass by Value Pass by value, means that a copy of the data is made and stored by way of the name of the parameter. The data in the calling function is UNAFFECTED by changes to the parameter.

Figure 6 : Pass by Reference Example There are two ways to make a pass by reference parameter:

  1. ARRAYS In C, arrays are always passed by reference at all times. The value of the original array will bechanged if the parameter containing the array is changed.
  2. The ampersand used in the function prototype. function (& parameter_name) The “& param” syntax is used to convert a normal parameter into a pass by reference parameter. The ampersand (&) is the syntax to tell C that any changes made to the parameter also modify the original variable containing the data. 3.4. Advantages and disadvantages of procedural programming Each programming style has its own pros and cons, for sure, procedural programming also comes with some pros and cons, below are some pros and cons that I found:

II. ANALYSIS OF THE PROBLEM IS GIVEN

  1. Problem statement 1.1. Problem 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 informations 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 he can choose another option. There should be an option to quit program. 1.2. User requirements
  • As a teacher, I want to input my students’ IDs and grades so that I can use a function A that can store the IDs and grades of the students after once input.
  • As a teacher, I want to display students’ IDs and grades so that I can use a function B which will take the data I have just typed from the function A and display them on screen. Advantages of procedural programming Disadvantages of procedural programming
  • The coding is easy and simple.
  • The codes have the ability to be reused in several part of the program.
  • It is easier for tracking the flow of the codes in the program written in the procedural programming paradigm.
  • The programming paradigm is regarded best for general programming to learn and implement.
  • Focuson functions rather than data.
  • In larger program, it is difficult to identify the belonging of global data.
  • The use of global data is error-prone and it could be an obstracle in case of maintenance and enhancements.
  • The modification of global data requires the modification of those functions using it.
  • Maintaining and enhanching program code is still difficult because of the global data.
  • The procedural programming paradigm does not model the real-world problem very well since functions are action-oriented and do not really correspond to the elements of the issue.

unsigned short 2 byte 0 to 65, int 2 byte - 32,768 to 32, signed int 2 byte - 32,768 to 32, unsigned int 2 byte 0 to 65, long int 4 byte - 32,768 to 32, signed long int 4 byte - 32,768 to 32, unsigned long int 4 byte 0 to 65, float 4 byte - 2,147,483,648 to 2,147,483, double 8 byte - 2,147,483,648 to 2,147,483, long double 10 byte Table Variable required in my program Variable name Data type Mean IDs[50] int It show the ID of students. Grades[50] float It show the grade of students. HighestGrades float It declares the biggest masks. LowestGrades float It declares the smallest masks. IDmaxGrades int It shows the ID of the student who has the biggest mask. IDminGrades int It shows the ID of the student who has the smallest mask. i int It is used in loop function and be numeral number in array function. n int It is used in loop function and be numeral number in array function. option integer User option for menu.

  1. Conditional statements

2.1. The function of the “switch case” statement A switch statement compares a variable against a set of values to see if they are equivalent. Each value is referred to as a case, and each switch case examines the variable being toggled. This expression is used when the expression being evaluated returns several values. And I use it in my report to define the various options that users choose to report and use in the "Menu choices" section. For example, if users wish to add information about their students, they can choose option 1. Then, to print it on the screen, choose option 2. Figure 7 : Swicht case in C 2.2. Conditional statement function In C programming, conditional statements are used to make judgments based on the conditions. When there is no condition around the statements, they are executed sequentially. If you add a condition to a block of statements, the execution flow may alter depending on the condition's result. In 'C,' this is referred to as decision making. (Thompson., 202 2 ) Conditional statements are possible in C programming using the following two constructs:

  1. If condition
  2. If-else condition A program determines which statement to execute based on the result of the assessed condition, which is also known as branching.

The syntax of do-while loop in c language is given below: Figure 9 : Do while loop in C 3.2. While loop In the case where we don't know the number of iterations ahead of time, the while loop in C is utilized. The while loop runs the block of statements until the while loop's condition is satisfied. A pre-tested loop is another name for this. (Anon., 2022 ) The syntax of while loop in c language is given below: Figure 10 : While loop in C 3.3. For loop

The for loop is used when we need to execute a section of code repeatedly until the provided condition is met. A per-tested loop is another name for the for loop. If the number of iterations is known ahead of time, the for loop is preferable. (Anon., 202 2 ) The syntax of for loop in c language is given below: Figure 11 :For loop in C In my program, this function assists me in determining the greatest or lowest mark. As a result, we may compare "max" and "min" with every element in memory.

  1. Function 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. In my program have 4 function and I named my function that are: EnterID&grades: Enter ID and grades of student DisplayIDs&grades: Display IDs and Grades of student HighestGrades: Grades highest of students LowestGrades: Grades lowest of students