Tải bản đầy đủ (.pdf) (30 trang)

btec level 5 hnd diploma in computing prog102 procedural programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (493.3 KB, 30 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

<b> ASSIGNMENT 1 FRONT SHEET </b>

<b>Qualification BTEC Level 5 HND Diploma in Computing </b>

<b>Unit number and title Prog102: Procedural Programming </b>

<b>Submission date </b> 6/22/2022 <b>Date Received 1st submission </b>

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

<b> </b>

<b>Summative Feedback: </b>

<b> </b>

<b>Resubmission Feedback: </b>

<b>Lecturer Signature:</b>

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

1. 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

</div><span class="text_page_counter">Trang 6</span><div class="page_container" data-page="6">

3.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

</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">

1. 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

<b>Advantages</b>

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="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

</div><span class="text_page_counter">Trang 9</span><div class="page_container" data-page="9">

-Implementation of algorithms and data structures -Procedural programming language

-Dynamic memory allocation -System-programming

<b>Disadvantages </b>

-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.

</div><span class="text_page_counter">Trang 10</span><div class="page_container" data-page="10">

1.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.

</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">

e) Programming libraries

A programming library is a collection of previously written code that can be used whenever a programmer needs it.

</div><span class="text_page_counter">Trang 14</span><div class="page_container" data-page="14">

Pass array (C only) Pass by reference (C only)

pass by value (C/C++)

</div><span class="text_page_counter">Trang 15</span><div class="page_container" data-page="15">

Constant 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.

</div><span class="text_page_counter">Trang 16</span><div class="page_container" data-page="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).

</div><span class="text_page_counter">Trang 17</span><div class="page_container" data-page="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.

</div><span class="text_page_counter">Trang 18</span><div class="page_container" data-page="18">

c) Case 2

-For loop can be used to display every student's IDs and grades according to the number of students declared.

</div><span class="text_page_counter">Trang 19</span><div class="page_container" data-page="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

</div><span class="text_page_counter">Trang 20</span><div class="page_container" data-page="20">

turn to find the highest and lowest scores.

-If condition can be used to compare each student s grade with the highest and lowest score. ’

</div><span class="text_page_counter">Trang 21</span><div class="page_container" data-page="21">

3. Design (P3)

3.1. Use-case and WBS (P3)

</div><span class="text_page_counter">Trang 23</span><div class="page_container" data-page="23">

3.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.

</div><span class="text_page_counter">Trang 25</span><div class="page_container" data-page="25">

b) 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

</div><span class="text_page_counter">Trang 26</span><div class="page_container" data-page="26">

stated. 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.

</div><span class="text_page_counter">Trang 27</span><div class="page_container" data-page="27">

c) 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

</div><span class="text_page_counter">Trang 28</span><div class="page_container" data-page="28">

This 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.

</div><span class="text_page_counter">Trang 29</span><div class="page_container" data-page="29">

4. 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: < [Accessed 21 June 2022]. 2. Learn Computer Science. 2022. Procedural Programming | Procedural Programming Paradigm Explained. [online] Available at: < [Accessed 21 June 2022].

3.2022. [online] Available at: <ining/blogs/advantages-and-disadvantages-of-c/> [Accessed 22 June 2022].

</div>

×