Unit 18 Procedural programming Assignment copy

Unit 18 Procedural programming Assignment copy

Unit 18 Procedural programming Assignment copy

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:

 If our code is organized into small “procedures” (Functions) which can use and change our data, it is called procedural programming. These procedures (functions) receive some input, do their processing and then produce some result.
Ideally these functions behave as “Black Boxes” where input data goes in and output data comes out. Functions have no intrinsic relationship with the data they operate on. As long as we provide the correct the correct number and type of arguments, the function will do its work and faithfully return its output.
We can define as many procedures in our program as we want and we can call our procedures as many times as we want. It is a good programming practice that, all procedures defined by us should be independent from each other. In other words a procedure should use its arguments only to complete its task instead of using global or shared data. A procedure must not perform task of another procedure, instead it should call another procedure which is performing specific task.

Methods:
          A method is a named block of code which executes as a single unit. Optionally methods can take parameters (also known as arguments) which make them more flexible. Parameters are variables which are received by the method each time it is called.  “return” keyword is used to return values from function to calling environment.

CODING

Variables:
        A variable is a named value holder in primary memory which is used to store data. The name we use for a variable is called an identifier. Identifier can be of any length but it must begin with an alphabet or an underscore, rest of the identifier can have digits also.
Ex:     int length = 10;

Loops:
Repetitive execution of a statement of a statement is knows as iteration or loop. There are two kinds of loop:
Top Tested Loops: In these loops condition is tested first then statements execute.
Example: for loop, while loop.
Bottom Tested Loops: In these loops conditions is tested at the bottom of the loops.
Example: do…while loop.

For Loop:

CODING 1

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

Benefits of Procedural Programming: Benefits of procedural programming is as follows:

  1. Procedural programming is easy to learn
  2. Procedural programming is easy to use.
  3. Procedural languages execute quickly.
  4. Procedural programming helps us to develop our program in separate procedures which perform specific tasks.
  5. In Procedural programming each task is defined in separate and independent procedure so that our application can be modified any without effecting other procedures.

Benefits of procedural programming is not limited to above points. Following points describe few major benefits or advantages of procedural programming:

Code Readability:
In procedural programming first of all a task is divided into small subtasks. These subtasks work together to achieve a desired goal. Now a procedure is defined for each of the subtask. Now these procedures are called accordingly to achieve the final result.
Since every single subtask is defined in separate function our final implementation to get result remain very small, neat and readable. If we want know details of a specific task we can jump to specific procedure’s code. Since a procedure perform a single specific independent task its implementation is also small, neat and readable.

Code Usability:
In procedural programming a procedure can be called from anywhere and anytime. We can call a procedure as many times as we want. In this way we can use our code again instead of rewriting our code. Thus procedural programming increases code reusability.

Maintenance:
In procedural programming, a procedure performs a single piece of work and it is independent from other procedures, so if we want to modify or maintain any procedure we can modify it without worrying about other code. In this way our code is always easily maintainable in procedural programming

Error Tracking:
In procedural programming error tracking is very simple. Since every procedure perform a specific task it is so much easier to determine which part of code (Procedure) has errors.

For complete copy of this solution, order from Assignment Help