Download Procedural Programming Assignment for BTEC Level 5 HND Diploma in Computing: Prog102 and more Schemes and Mind Maps Programming Paradigms in PDF only on Docsity!
ASSIGNMENT 1
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 Pham Minh Dung 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:
- Procedure: Procedures are one-by-one instructions that are carried out in programming. They flow from one to the next in a sequential manner, so after the one above is finished, it will move on to the next unless the one above tells it not to (Moore, 2014).
- Programming paradigms: Procedural programming, object-oriented programming, and flow programming.
- There are many types of code samples: condition (if, if else), loop (for, do while), data type (int, double, char). For example: Problem using comparison: If (a>b) printf(“True”) else printf(“false”); Or import array from keyboard: It help us many difficult problems. We can use many data type for data, int for integer, char for name,characters, … 1.2 Problem statement 1.2.1 Problem and solution Scenario: A math teacher wants to manage grades of a class. He asksyou to help him to write a small application to do that. He needs to enter student IDs, student’s grades and store these information 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. Problem: The problem of student information management is a difficult problem. Manual management method has many disadvantages such as:
- Time consuming, complicated.
- Information may be wrong and difficult to correct.
- If the time is long, the document may be damaged.
- Difficult for searching, statistics. calculation. We need to find a solution to this problem. Solution: I think a student management program is a good choice.Input information: name, ID, gender, score, … Output information: Name, ID, age, gender, score of all students, maximum score, minimum score, average score, result, grade, rank, … Advantages:
- Enter information quickly and accurately.
- Information is stored for a long time.
- Easy search, calculation, statistics. 1.2.2 Apply procedural programming for this problem Procedural programming is a good way to create this program. To use many functions, I need to declare some necessary libraries such as,… It helps me with calculations, data entry, … Next, I will declare a structure to collect all the required input information of a student, type int, float, char will be used for name, ID, points. An interface would be necessary for any program but I need to get the number of students before I get started with the interface, initializing a variable with printf and scan will do the job. The while-do loop will be used, further initializing an array with the number of elements as the number of students. Using multiple printf statement to print a menu of functions and use switch-case to select them. The functions will be written below the main part, then they will be declared before the main section and used in each case to write the corresponding function. Import and export functions: using for loop in combination with scanf, printf, gets statements.
Data types Range Bytes Format Signed char Unsigned char Short signed int Short unsigned int Signed int Unsigned int Long signed int Long unsigned int Float Double Long double -128 to + 0 to 255 -32768 to + 0 to 65535 -32768 to + 0 to 65535 -2147483648 to + 0 to 4294967295 -3.4e38 to +3.4e -1.7e308 to +1.7e -1.7e4932 to +1.7e
%c %c %d %u %d %u %ld %lu %f %lf %Lf Note: The sizes and ranges of int, short and long are compiler dependent. Sizes in this figure are for 16-bit compiler. Figure 8: Data types in C language (Mishra, 2021) ➔ Example of Data Type in C. language
- Void: Void is a type that is not complete. Meaning "nothing" or "no kind." There is a way to conceive of the emptiness as void. A function's return type should be void if it returns nothing. We can't construct void-type variables. 2.2 Conditional statements needed in the problem 2.2.1 IF In terms of conditional statements, this is a very potent one. Program execution may be altered by the use of an if statement. The if statement must always be used in conjunction
with a condition to make it valid and valid. Any statement in the body of if is evaluated before any other statement in the condition is executed. These inspections may be performed by a variety of operators. 2.2.2 IF – ELSE
- Statements within "if" are performed and statements inside "else" are bypassed when the condition in "if" is true, which is checked first in this function. In other words, if the first condition is false, the first statement is omitted, and statements in the body of "else" are performed instead.
- It's possible that the user mistypes a request in this software and hence will get a notice error, which will prompt the user to try again. 2.2.3 SWITCH CASE If-else-else statements can be substituted. In certain cases when the expression being evaluated returns numerous values, this is the method of choice. A switch statement may be used to compare a variable to a list of values. Case refers to the value under consideration and the switch case refers to the value under consideration. 2.3 Loop statement needed in the problem 2.3.1 FOR -Only one instance of the initialization statement is performed. Then the evaluation of the test expression takes place. When the test expression evaluates to false, the "for" loop comes to an end. If, on the other hand, the test expression evaluates to true, a statement inside the body of the "for" loop is run, and the update expression is updated. The retest expression is put to the test.
- This procedure is repeated until the test phrase is found to be untrue. If the test expression returns false, the loop comes to an end. 2.3.2 DO-WHILE The "do-while" loop's body is performed just once in this way. Only if it is the case is the test expression tested.
- I built a WBS for this problem: My WBS has a few parts:
- Enter information: Enter all the necessary student information such as ID, name, age, gender, scores. For the functions to work properly, all information must be entered.
- Show information: Print ID, name, age, gender, scores of students.
- Find min, max, average of scores: It consists of lines of code that perform the main function of the program:
- Find the highest and lowest scores -> Print them.
- Calculate average of students -> Print them.
- Find result, rank, rating: Find and print them. 3.2 FLOWCHARTS According to Ned Chapin, a graphical means of recording a sequence of activities is called a flowchart (Chapin, 2003). In IT, it is often called to rewrite the sequence and the way the program works. I will draw and analyze this program as a flowchart.
- Here, the program takes the input value n (number of students).
- Next, get the input value o and array a[n] (used to select functions).
- Using switch with o, If the value of o is 1,2,3,4,5,6 (True), the program redirects to the corresponding function, if it receives False, it returns to the input step o.
- If the value of o is 0, program will finish. If o is others value, enter o. We’ll get to each of the main functions: Function 1: Enter Information of student.
Start with the value i=0. Compare i<n. If False is returned, the program terminates. If True is returned, go to the next step. Print information of a[i]. Increase the value of i by 1. Return to the i<n comparison step.
Function 3: Max, Min, Average. Start with i=0 and max=a[i]. Compare i<n. If^ i<n^ is^ True,^ compare^ max^ <^ a[i].^ If^ True,^ max=^ a[i]^ and^ increase^ value^ i^ by^ 1.^ If^ False, increase value i by 1 Go^ back^ step:^ compare^ i<n If i<n is False, print max and finishes program.
Start with i=0, average=0 and sum=0. Compare i<n;
- If True then sum=sum + a[i] and increase value i by 1. Go back step i<n.
- If False then average = sum/n and print average, program finish.
Function 4: Result of course Initialize the value i=0. Compare i<n. If False is returned, the program terminates If True is returned, compare a[i]>=5. If it returns False, then print FAILED. If it returns True, then print PASSED. Increase the value of i by 1. Return to the i<n comparison step
- If i<n-1 or y<n False, compare i<n; 2.1. If True print rank of student is i+1 and the program terminates. 2.2. If False, the program terminates.
4 Evaluation (D1)
4.1 Evaluate your solution
- About analysis: Advantages: I have used a table to describe the data type, the loop in the most intuitive way, making it easy for the reader to understand the definition and why I use it. I also added illustrations for the explanation. Each individual function will have a different picture. Disadvantages: All its benefits have not been thoroughly analyzed.
- About WBS: Advantages: Defined, draw WBS with full main functions of the program. All functions explained below. Disadvantages: Lack of extra function is Exit.
- Flowchart: Advantages: Defined, draw flowcharts for all program functions and main interface, explain in detail the steps. Disadvantages: Flowchart drawn is not intuitive, the size is not uniform. **4.2 Evaluate how procedural programming is applied to your problem
- Advantages:** Procedural programming has optimal statements for specific functions. There are built-in functions for printing and importing. There are library declarations needed for calculations or arrays. Data types like int, float, char are for the specific objects I need like name, grades, … Gather all the necessary information in one place using a struct. Loops, switch- case and conditional statement are suitable for calculating, comparing and retrieving
information in arrays. Functions are in separate places but can come together to form a perfect function. All are broken down, so it’s easy to check, repair, optimize the program.
- Disadvantages: Must use a lot of functions: min, max functions are not much different but have to reprogram a lot of commands => can’s inherit command line. The entered parameter data is not cleared causing the screen to fill up. It takes many steps to implement a simple algorithm like swapping positions. - Difficulties: If there is more input, more variables and more complex algorithms are needed. If you want to optimize the algorithm, you have to revise the whole program because the functions have some association with each other => optimization is difficult.