Unit 18 Procedural Programming Sample Assignment

Home
breadCrumb image
Solution
breadCrumb image
Unit 18 Procedural Programming Sample Assignment
Unit 18 Procedural programming sample assignment
Unit 18 Procedural Programming Sample Assignment

TASK 1: Understand the principles of Procedural Programming

1.1 (a) Write maximum 400 words explaining briefly what procedural programming is and define clearly what do we mean by methods, variables and loops with an example for each?

Procedural Programming:

Dividing a large complex program into multiple simple programs is called procedural programming. When we call a procedure is called we supply some input data to be processed, the procedure then processes data and returns a result. If we use procedures that is not designed by us we can see it like a black box, in which some data is inserted and we receives the result according to the input. If we supply a valid data then the function returns a result and if not we can check the function.
      Procedures can be called functions, methods, procedures, subroutines etc. We can have multiple methods in our code and can call them to get the result and increase code reusability. Its better practice that a procedure process its own set of data and not some shared data or variables declared as global. Global variables are against the approach of good programming practice assignment so their use should be as minimum as possible. And it is better to call another procedure to perform another task from a procedure instead of writing the same code again and again. It increases the amount of code we need to write and hence increases the coding efforts and time and decreases code reusability.

Function:

Basically a function is a separate piece of code that can be called upon to perform specific task in our program. Individually a function may not be so helpful but when it used with some other functions it can be beneficial. We specify or pass arguments to the function to increase the flexibility of code and to it makes the function more convent so that we don’t need to change it according to each problem.

Ex:     int factorial(int no) {
                   if(no==1)

return 1;

else

return no * factorial(no-1);

}

Here factorial() function receives a number as argument and makes recursive calls to itself to generate factorial of a given number.

Variables:

Also called identifier are created in primary memory and their value varies during the execution of the program. In many programing languages variables naming have rules which we need to follow while declaring variables in code. First is that the variable name cannot contain spaces, it must begin with an alphabet or underscore rest of the name can contains digits also. Variable names cannot contain keywords of the programming language that we are using, Keywords are the words that are essential for the language or we can say these are the words by which language is formed.
Ex:     float intrest_rate = 12.5;

Loops:

          If a statement is executed repetitively it is called a loop. Loops always have some condition on which it performs the iteration and terminates the iteration. If the condition is checked at the beginning of the loop it is called top tested loop and if the condition is checked after the execution of the loop it is called bottom tested loop.

For Loop:

for(int i = 0; i  < 10; i++){
          ....

          ……

}

while loop:
int i = 5;

while(i != 0){

          …

          …

}

(b) Explain briefly the benefits of procedural programming in terms of code readability, usability, maintenance and error tracking.

Benefits of Procedural Programming: There are many benefits of procedural programming these are the following:

  • It is easy to learn
  • It is easy to use.
  • It execute quickly.
  • It helps us to divide the large task into multiple simple task that performs specific task.

In modular programming every task is defined as separate and independent task so our application can be changed any without changing other modules.

Flowing are some more benefits that modular programming offers to the programmers:

Code Readability:
In modular programming a large task is divide into simple multiple subtasks. These parts are combined and works together to generate results. Every task is a separate piece of code and executes when we need to perform the specified task. It make the code neat and clean and increases the readability.

Code Usability:
A procedure can be called from anywhere in the code anytime when we want to perform a specific task and hence increasing reusability of code and need not to invest out time to code to perform the same task again and again.

Maintenance:
In modular programming each task that we want to perform in our program is clearly divide into a module. So it is easy for maintenance purpose. When we fine any bug or want to update the existing process that we want to perform in our program we just need to change the specific procedure for the change we want in our program’s execution process.

Debugging is Easy:
In modular programming debugging is very easy because every task is subdivide into simple sub task and if anything goes wrong in a particular process we just need to go that specific module and it will reflect the change in all the place where we are using it or calling it to get the result from it.

For complete copy of this solution, order from Assignment Help

FAQ's