Monday 20 October 2014

Key Features of Procedural Programs. P1

TASK 1 Unit 16


A.Pre Defined functions:
  
   Pre defined functions are unique inbuilt functions that do specific jobs to meet the end user need.        They are inbuilt hence their name is "Pre defined".

       An example can be:

cPosition= sLastName.charAt(0);  //charAt(0) is a pre defined function. It links variable sLastName with cPosition to detect a position at position "0"

 System.out.println( cPosition); //System.put.println is a pre defined function. It prints out a message that shows position at 0 (of sLastName)


B.Local variables:

Local variables are variables that are defined to a specific function or subroutine or class/module and can't be accessed by other functions/sub routine.If some programmers are working on a big program then it is useful to use local variables as they can be accessed easily for specific jobs,

     public class HelloWorld{

     public static void main(String []args){


   String sLastName= "Abbas";  // sLastName is a local variable inside the class HelloWorld

}
 }



C. Global Variables:


Global Variables exist outside all functions and are accessible throughout the program by any function/class. They are used for storage hence they can be accessed later on in the program. However programmers do not like to work with Global Variables as they often cause bugs can consume memory behind the processes even though they are not being used in particular. Also, if the function is repeatedly, the global variable does not get renewed. Java does not have global variables.
In VB6 it goes like this

Dim Num as Integer

Private Function PrintNum()

End sub



D. Parameter Passing:
Parameters are needed for a pre defined function in order for it to work. I will show you an example I have used previously for "Pre Defined functions".
 If we take a look at "cPosition= sLastName.charAt(0);". The integer in the brackets of .charAt(0) is the parameter that is being passed. It finds the character at position 0 . This is known as Parameter Passing.

E. Modularity:

Modularity is the concept/idea or process of dividing the program into different parts or sections. After it is divided, it can be tested and debugged section by section. This helps programmers to maintain the program more efficiently. For example, if there is a bug, they would not go through all the code, they can test each function separately,for ease. It saves time and energy. Each function/module is independent from the other module/function. In the program the user inputs are specific in the form or medium of "arguments" and the "result" or "output" is in the form of "return values"

F. Procedures:
Procedures are a compilation or a body of statements that interact with each other to perform a specific function/operation or task for the user. The following is an example of a function/procedure from VB6. It takes two numbers and adds them together.  

"Function Add(ByVal Number1 As Integer, ByVal Number2 As Integer) As Integer Add = Number1 + Number2 End Function"
G. Programming Libraries: 
Pre compiled modules are saved,in object form, in a place called "library". The advantage of programming libraries is that once the routine is saved, it can be used again by a "linker" so we do not need to insert them to every software that requires the module. It could be accessed easily by the linker. It is usually stored in a .DLL file. Basically, without Libraries, we can not run a program as the procedures are stored in it.

H. Procedural programming paradigm:

Procedural programming is a form of structural programming where the programmer types something similar to an "algorithm" and the program does its work. The advantage of this is that the programmer or anyone who sees the code does not have much difficulty in understanding the code as it has some "English terminology" in it. Which means basic English language words. Procedural Programming paradigm involves procedures, which anyone can tell by the name of it. The basic concept is that it follows "steps" to give an output using procedures.

I. Two examples of Procedural programming paradigm languages
 Two common languages are:

   1) Basic              2) Pascal


J. I will start by explaining the if, else if, else statements

  if: The if statement is continued by the "{ " statement and ended with "}" (in java). As the name tells us, this command is given in specific circumstances where if the user gives a specific input then       ("") the program should give a unique output (And then ended with a "}" ). An else if statement can be used when there is a selected alternative in-putted by the user. The else if is again continued by the "{ "statement which outputs information accordingly and ended with "}".. An else statement is used where the user inputs something that is not recognized by the program. It is also followed by a "{" statement that outputs information accordingly and is ended by,once again "}".
An example for all 3 of these statement can be

public class HelloWorld{

     public static void main(String []args){
       if (2>1){
    System.out.println("2 is bigger than 1");
       }
       
else if(1==1){
    System.out.println("1 is equal to 1");
}
    
else {
    System.out.println ("Error");
}

                                          }
                      }
 

Now I will explain what "char" is,
The full form of "char" is character. It is a data type. In computing terminology, a character is a single letter,number, symbol or space. This data type can be used as demonstrated below

char cFirstInitial="A";

Now I will explain what "double" and "int" are.
This data type is a bit similar to integer. However it is used for decimal numbers such as "9.1"  "2.3" whereas integers can not be applied to decimals and are used for whole numbers such as "9"  "1"  "23". If we take a look at the range of double, it is 4.94065645841246544e-324d to 1.79769313486231570e+308d but for int it is -2,147,483,648 to 2,147,483,647.

A variable can be used as an integer and doubles as follows

int iYearOfBirth //for Integer

double iPriceOfCake //for double




I will now explain "for".


"for" is used where the program loops a specific code. The number of times it is "looped" has to be specific amount of times. I will demonstrate an example. If I wanted to increase the value of "iTotalScore" by 3, 5 times, then I would use:



int iTotalScore = 5;

int iAdd = 3;

for( int iLoops=0; iLoops<6; iLoops++) {

System.out.println ("Total score is " + iTotalScore);

iTotalScore+= iAdd;
}
 Which would look something like so,


I will now talk about String. String is made up of different characters. By characters, I can mean symbols,spaces or even numbers and letters. These all add up to make a String. A String is usually in speech marks, And example can be

String sSurName = "Abbas";


Lastly, I will talk about boolean. Boolean is identified by just two things. It is either "true" or "false". An example can be boolean bFirstNameMuhammad = "true";
My first name is Muhammad that means it is correct.


3 comments: