Đang tải... (xem toàn văn)
He needs to enter student IDs and students'''' grades and store this information into 2 separate arrays integer array for IDs and float array for grades.. Variables, data types -Integer arr
Trang 1ASSIGNMENT 1 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing
Unit number and title Prog102: Procedural Programming
Submission date 6/22/2022 Date Received 1st submission
Trang 3 Summative Feedback: Resubmission Feedback:
Lecturer Signature:
Trang 51 Introduction (P1, M1) 4
1.1 General concepts (P1) 4
a) Definition 4
b) Advantages and disadvantages of C programming 4
c) Procedural language types 5
Trang 63.2 Flowchart (P3) 12
a) Option menu 12
b) Input students’ IDs and grades sub-function 13
c) Display all student’s IDs and grades sub-function 14
d)Display IDs and grades of students with highest and lowest grades sub-function 14
4 References 15
Trang 71 Introduction (P1, M1) 1.1 General concepts (P1)
a) Definition
Procedural programming is derived from imperative programming Its concepts are based on procedure calls, a series of computational steps to be carried out The execution of the instructions takes place step by step according to direct instructions from a human telling the
computer how to achieve a goal through processes Procedural programming focuses on the process rather than data (Object-oriented Programming) and function (Functional Programming)
Fundamentally, procedural code is the code that tells a device how to do a task in logical steps This paradigm employs a top-down linear approach and treats data and methods as distinct entities To do computations, it uses procedures or subroutines
Imperative programming is another name for procedural programming
b) Advantages and disadvantages of C programming
Advantages
Trang 8-Building block for many other programming languages -Powerful and efficient language
-Portable language -Built-in functions -Quality to extend itself
-Structured programming language -Middle-level language
Trang 9-Implementation of algorithms and data structures -Procedural programming language
-Dynamic memory allocation -System-programming
Disadvantages
-Concept of OOPs -Run-time checking -Concept of namespace -Lack of Exception Handling -Constructor or destructor -Low level of abstraction
c) Procedural language types
Example: FORTRAN, ALGOL, COBOL, BASIC, PASCAL, C/C++, Java, etc
The first major procedural programming languages around 1957-1964 were FORTRAN, ALGOL, COBOL, PL/I and BASIC The procedural Programming paradigm is one of the first paradigms to emerge in the computational world
Java and C/C++ are popular procedural languages these days.
Trang 101.2 Characteristics (M1)
-A top-down method is used in procedural programming
-The program is organized into functions, which are blocks of code that each execute a specified purpose -Real-world processes are modeled as 'procedures' that operate on 'data' in procedural systems
-Data and functions are separate from one another -In a software, data is free to move about -It's simple to follow a program's logic
-By invoking another function, a function can have access to its data
Trang 12e) Programming libraries
A programming library is a collection of previously written code that can be used whenever a programmer needs it
Trang 14Pass array (C only) Pass by reference (C only)
pass by value (C/C++)
Trang 15Constant reference (C only)
2 Analysis (P2)
“A math teacher wants to manage the grades of a class He asks you to help him write a small application to do that He needs to enter student IDs and students' grades and store this information into 2 separate arrays (integer array for IDs and float array for grades) Then he needs to print all the student IDs together with their grades Finally, he needs to know which student has the highest grade and the 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 the program ”
2.1 Variables, data types
-Integer array IDs[]: store students’ IDs
-Integer variable n: option indicator for the program’s menu
-Integer variable i: number of students and also size of IDs[] and grades[] arrays -Integer variable d: array index indicator
-float array grades[]: store students’ grades
Trang 16-float variables min: lowest grade -float variables max: max grade 2.2 Data structures
a) Option menu
-Switch case can be used in the program's option menu to start a case (sub-function)
Trang 17-While loop is required for the program to return to the main menu when a sub-function is completed and only end the program when the user selects the option to do so
b) Case 1
-For loop can be used to input student IDs and grades according to the number of students declared
Trang 18c) Case 2
-For loop can be used to display every student's IDs and grades according to the number of students declared
Trang 19-If condition can be used to check the student's score corresponds to that student's ID number
d) Case 3
-For loop can be used to create a loop that continuously checks and compares the scores of all students in
Trang 20turn to find the highest and lowest scores
-If condition can be used to compare each student s grade with the highest and lowest score ’
Trang 213 Design (P3)
3.1 Use-case and WBS (P3)
Trang 233.2 Flowchart (P3)
a) Option menu
If the user enters a number between 1 and 3, a sub-function corresponding to that number will run, and when that sub-function is finished, the user will be sent back to the options menu to input another number, as long as the user does not enter the number 4 If the number entered was not between 1 and 4, a notice stating "invalid option" would appear, prompting the user to return to the menu and enter a new number The user can command the program to stop when the number 4 is entered
Trang 25b) Input students’ IDs and grades sub-function
The variable I will be used to represent the number of students for whom the user wants to submit their IDs and grades, as well as the size of the IDs [] and grades [] arrays Students' IDs are stored in the IDs [] array, while their grades are stored in the grades [] array The d variable is the element index indication for both arrays; depending on which array it's in, each element holds the ID or grade of one student Because index numbering begins at 0, the last index number in an array with a large number of entries will be (i-1) The user initially enters a number I which determines the size of the two arrays
Trang 26stated The user can then enter the IDs and grades of students into the arrays from the first element using a loop When the user enters the value for the last element of both arrays, the sub-function will terminate
Trang 27c) Display all student’s IDs and grades sub-function
All arrays and variables will be passed to this sub-function to display all students' IDs and grades The elements of both arrays will then be displayed in order from the first to the last index using a loop
d)Display IDs and grades of students with highest and lowest grades sub-function
Trang 28This function will also accept variables and arrays The highest and lowest grades will be the variables max and min, but their values must first be set as the first element of the grades [] to serve as a baseline for later comparison Starting at index 1, the first loop will go through each element of the grades [] array and compare it to the min and max values When an element is larger than max, the new value of max is assigned to that element; when an element is smaller than min, the new value of min is assigned to that element When the loop has finished going through all of the elements in the array, the highest grade is stored at max and the lowest grade is stored at min The sub-function will then enter another loop, this time going through the grades [] array starting at index 0 and checking if the current element is equal to min or max If it is, that element will be displayed, along with the element with the same index in the IDs [] array
Trang 294 References
1 Dev, A., Prep, A., Learning, D., Mining, D., Learning, M., Experiences, I and Dev Ruby React JavaScript, W., 2022 Procedural Programming: Everything You Need To Know Coding Ninjas Blog– [online] Coding Ninjas Blog Available at: <https://www.codingninjas.com/blog/2021/03/15/procedural-programming-everything-you-need-to-know/#Frequently_Asked_Questions> [Accessed 21 June 2022] 2 Learn Computer Science 2022 Procedural Programming | Procedural Programming Paradigm Explained [online] Available at: <https://www.learncomputerscienceonline.com/procedural-programming/> [Accessed 21 June 2022]
3.2022 [online] Available at: <https://data-flair.training/blogs/advantages-and-disadvantages-of-c/> [Accessed 22 June 2022]