ASM 1 For Procedural Programming, this document is useful for BTEC students including FPT or Greenwich. When you submit this document, you will pass the course right away. If you want to own more documents about computing or all course in school, please contact me to get more. Hope it useful to you
ASSIGNMENT FRONT SHEET Qualification BTEC Level 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 Bui Quang Minh Class Student ID GCD1104 GCD210325 Assessor name Phan Thanh Tra 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 Summative Feedback: Grade: Lecturer Signature: Resubmission Feedback: Assessor Signature: Date: Contents I.INTRODUCTION Scenario Programming language Background of C 4 Procedural programming …………………………………………………………………………………………………… 5 Key factors User requirement Use case diagram Advantages and disadvantages of procedural programming II.ANALYSIS Date types and date structures 10 Date types used 12 Condition statement 12 condition statement used 14 Loop statement 14 Loop statement used 15 III DESIGN Work breakdown structure 16 Flowcharts 16 Review flowcharts 20 Finding ID with the grade given before 20 Alternative solution 20 IV EVALUATION Evaluate my solution 21 Evaluate how procedural programming is applied to my problem 22 I INTRODUCTION: P1 1) Scenario: A math teacher told me that he wants a program that can be used to monitor the grades of a class He can enter student IDs and student grades into the program The former should be stored in an integer array and the latter should be stored in a float array When he enters the program, there is a menu containing four options The first option would be to enter the student IDs and student grades The next option is printing all student IDs with their grades The third one is printing student who has the highest and lowest grade When he gets what he needs, he can go back to the main menu to choose another option Moreover, if he wants to turn off the program, he selects the last option: to quit the program 2) Definition of programming language: A programming language is a computer language that is used by programmers (developers) to communicate with computers It is a set of instructions written in any specific language (C, C++, Java, Python) to perform a specific task A programming language is mainly used to develop desktop applications, websites, and mobile applications According to Stack Overflow’s 2020 Developer Survey, JavaScript currently stands as the most commonlyused language in the world (69.7%), followed by HTML/CSS (62.4%), SQL (56.9%), Python (41.6%) and Java (38.4%) 1.1 the most commonly used language in the world 2020 3) Background of C programming language: C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A Dennis Ritchie is known as the founder of the c language It was developed to overcome the problems of previous languages such as B, BCPL, etc Initially, C language was developed to be used in UNIX operating system It inherits many features of previous languages such as B and BCPL Features of C Programming Language: 1.2 Features of C Programming Language 4) Definition of procedural programming: Procedural programming is a programming paradigm built around the idea that programs are sequences of instructions to be executed They focus heavily on splitting up programs into named sets of instructions called procedures, analogous to functions A procedure can store local data that is not accessible from outside the procedure's scope and can also access and modify global data variables Surprisingly, it can often be broken down into three simple programming structures called sequences, selections, and loops These come together to form the most basic instructions and algorithms for all types of software The three basic programming constructs Programs are designed using common building blocks These building blocks, known as programming constructs (or programming concepts), form the basis for all programs There are three basic building blocks to consider: sequence is the order in which instructions occur and are processed selection determines which path a program takes when it is running iteration is the repeated execution of a section of code when a program is running 1.3 Three basic building blocks 5) Key factors: Predefined functions A predefined function is a function available in a procedural programming language from a library of available functions These functions allow a programmer to complete common tasks without creating the required code themselves This can help a developer save time during production One example of a predefined function is sqrt() which returns the square root of a number 1.4 Example of predefined functions Local variables A local variable is a programming variable that has a local scope of use This means the variable only functions in the function in which the developer defines it Local variables only work in this capacity, so they can cause code to fail, leaving a task unfinished if a professional or user attempts to use the variable in a method outside of its scope Global variables Global variables increase functionality when local variables are insufficient Developers can use global variables in nearly all functions When defined globally, a variable makes itself available to all methods and functions in the code, allowing the developer to access key data throughout the program's many procedures 1.5 Example of local and global variables Modularity Modularity is a structure in which a developer divides the functionality of its code into a series of smaller blocks The programmer can then call these blocks, often called methods or functions in procedural programming languages, in their code to access them This makes important functions repeatable to create a more efficient setup code, compared to one that requires the programmer to reuse the same code at multiple points when including a task that they need more than once Parameter Passing Parameter passing involves passing input parameters into a module (a function in C and a function and procedure in Pascal) and receiving output parameters back from the module For example, a quadratic equation module requires three parameters to be passed to it, these would be a, b and c Pass By Value: This method uses in-mode semantics Changes made to formal parameter not get transmitted back to the caller Any modifications to the formal parameter variable inside the called function or method affect only the separate storage location and will not be reflected in the actual parameter in the calling environment This method is also called as call by value // C program to illustrate // call by value #include void func(int a, int b) { a += b; printf("In func, a = %d b = %d\n", a, b); } int main(void) { int x = 5, y = 7; // Passing parameters func(x, y); printf("In main, x = %d y = %d\n", x, y); return 0; } Output: In func, a = 12 b = In main, x = y = Pass by reference(aliasing): This technique uses in/out-mode semantics Changes made to formal parameter get transmitted back to the caller through parameter passing Any changes to the formal parameter are reflected in the actual parameter in the calling environment as formal parameter receives a reference (or pointer) to the actual data This method is also called as call by reference This method is efficient in both time and space // C program to illustrate // call by reference #include void swapnum(int* i, int* j) { int temp = *i; *i = *j; *j = temp; } int main(void) { int a = 10, b = 20; // passing parameters swapnum(&a, &b); printf("a is %d and b is %d\n", a, b); return 0; } Output: a is 20 and b is 10 Programming libraries Programming libraries are a collection of classes, values, and subroutines and they come ready built into programs The programming libraries can be used whenever the developer wishes to Many different libraries are used in programs however; they will all serve different functions Many programs will use libraries in programming and each will be unique to their own program The line of codes that are used will different to other programs , , Procedures When you have procedures in programming, the program that has them in will follow the procedures step by step, systematically The program does exactly what it is told to in the order that has been set by the programmer Procedure for answering customer calls: Answer the phone before the third ring Greet customer by saying, "Hello, you've reached Lead Strategy Incorporated This is [your name] speaking How can I help you today?" Use positive language Answer the customer's questions Ask the customer to please hold while you transfer them Dial the extension number Press the send button Procedural programming paradigm Procedural programming is derived from structured programming Procedures, also known as methods, functions, routines or sub-routines, simply contain a series of computantional steps to be carried out Procedures cna be carried out during any point of the program, sometimes other procedures can call out another procedure during it's cycle of runn function pourIngredients() { - Pour flour in a bowl - Pour a couple eggs in the same bowl - Pour some milk in the same bowl } function mixAndTransferToMold() { - Mix the ingredients - Pour the mix in a mold } function cookAndLetChill() { - Cook for 35 minutes - Let chill } pourIngredients() mixAndTransferToMold() cookAndLetChill() 6) User quirements: As a teacher, I want to enter the IDs and grades of my students, so that they are stored in the program As a teacher, I want to print the student IDs and grades, so that I can see all of the IDs and grades of my students As a teacher, I want to know the student who has the highest and lowest grades, so that I can see the student who has the highest and lowest grade As a teacher, I not want to use the program, so that I can turn off the program M1 1) Use case diagram: 1.4 Use case diagram 2) Advantages and Disadvantages of Procedural Programming Procedural Programming comes with its own set of pros and cons, some of which are mentioned below Advantages: Procedural Programming is excellent for general-purpose programming The coded simplicity along with ease of implementation of compilers and interpreters A large variety of books and online course material available on tested algorithms, making it easier to learn along the way The source code is portable, therefore, it can be used to target a different CPU as well The code can be reused in different parts of the program, without the need to copy it Through Procedural Programming technique, the memory requirement also slashes The program flow can be tracked easily Disadvantages: The program code is harder to write when Procedural Programming is employed 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 importance is given to the operation rather than the data, which might pose issues in some data-sensitive cases The data is exposed to the whole program, making it not so much security friendly II ANALYSIS P2 1) Date types and data structures: Date types: Data Type Format Specifier Minimal Range Typical Size unsigned char %c to 255 char %c -127 to 127 signed char %c -127 to 127 int %d, %i -32,767 to 32,767 16 or 32 unsigned int %u to 65,535 16 or 32 signed int %d, %i Same as int Same as int 16 or 32 short int %hd -32,767 to 32,767 16 %hu to 65,535 16 signed short int %hd Same as short int 16 long int %ld, %li -2,147,483,647 to 2,147,483,647 32 long long int %lld, %lli -(263 – 1) to 263 – (It will be added by the C99 standard) 64 signed long int %ld, %li Same as long int 32 unsigned int short Bit unsigned long int %lu to 4,294,967,295 32 unsigned long long int %llu 264 – (It will be added by the C99 standard) 64 float %f 1E-37 to 1E+37 along with six digits of the precisions here 32 double %lf 1E-37 to 1E+37 along with six digits of the precisions here 64 long double %Lf 1E-37 to 1E+37 along with six digits of the precisions here 80 2.1 Data types Data Structures: in C are used to store data in an organised and efficient manner The C Programming language has many data structures like an array, stack, queue, linked list, tree, etc A programmer selects an appropriate data structure and uses it according to their convenience ARRAY An Array is a sequential collection of elements, of the same data type They are stored sequentially in memory An Array is a data structure that holds a similar type of elements The array elements are not treated as objects in c like they are in java Imagine you are at a musical instrument store and I tell you to arrange all the keyboards under the brand Casio at one place one above the other This sequential collection of records is called an Array An array is a sequential collection of elements of the same data type In our example above, Casio is the data type and all the keyboards you collected are of the brand Casio All the elements in an array are addressed by a common name There are two types of arrays: Single dimensional array Multidimensional array //Employee IDs example #include int main() { int i=0; int empID[5]; empID[0]=10280; empID[1]=10260; empID[2]=10270; empID[3]=10285; for(i=0;i