Monday 10 November 2014

Key Features of Procedural Programs

Procedural Programming Paradigm

Procedural Programming is a paradigm which programmers use to create a structured program. Procedural Programmed applications tend to use procedures (routine of steps) to collaborate and run effectively.

Examples of procedural  languages

One example of a procedural language is C. C or versions of the C programming languages allow the programmer to create steps for the program to follow and carry out. It executes each bit at a time. The code to run a function has to look at what the function does and once you have the code for what it does then it will execute and continue onto the next step. C is one of the most popular languages and has similar programming language derivatives such as C++ which is used in android programming.

Another example of a procedural language is Pascal. Pascal was invented around the time of when personal computers were first made.  Pascal is a high-level language, like C so the code has to be translated so the computer can understand and execute it.

Pre-defined Functions

A predefined function is a function that is already there to use when coding in a language.
An example of a pre-defined function is StartsWith() which lets you find the character which is first in a particular string. 
Example
String sLocation;
sLocation = “Middlesbrough”;
if (sLocation.StartsWith(“M”) ) {   System.out.println(“You live in a very nice place”);      }
The code above shows the application creating a string called sLocation, setting sLocation as a place, then there is an if statement depending on if the string starts with the letter M.
Another example of a pre-defined function is println() which lets you display the line of text on the screen
Example
System.out.println(“ Hello there, this is a printed line”);


The code above shows the application printing the line of text . The text that is printed is the one placed in the speech marks.

Programming Libraries

A programming library is a library that contains files and functions which can be used in the project you are developing.
An example of a programming library is Swing. The code to import the Swing library into java is:
Import javax.swing.*;

Once you have imported swing, you can use functions like JOptionPane which can load up question messages where users can input text.

Modularity

Modularity in programming is where you split the program into key sectors or different parts. The code for each part does not rely on the other parts code. If you write all your program code in one part then it will not be efficient as some code may have to change which will affect other code. However if you modulated your code so that everything is set into different parts then your code will be more effective.

Global Variables

A global variable is a variable that can be used in all parts of your program. 

"Public Class GlobalVariables                               
                                              
    Public Shared UserName As String = "Tim Johnson"
    Public Shared UserAge As Integer = 39
End Class"

  http://stackoverflow.com/questions/14423568/how-to-have-a-global-dictionary-in-vb-net-wpf-application-to-save-data-from-diff - code reference 

This is an example of 2 global variables declared in visual basic. A global variable is declared in a public class so all forms can use the variables. The first one is declared as a string and is equal to “Tim Johnson”. The second declared variable is an integer which is equal to 39.

Local Variables

A local variable is a variable created which can only be used and defined in the part of the program where you have created it. 

" int iNumber = 10;
   String sNumberinwords = "Ten"
   char cCharacter = 'a'
"
This is an example of creating 3 local variables, an integer, a string and a character. As these are not in a global module, these can only be used in this one section of your application.

Procedures

Procedures in programming are routines which hold a series of steps and instructions. A procedure can be called to execute in your program. Procedures are the physical implementation of modularity. A procedure will begin and end with the series of instructions inside of them. For example,
Reference : http://pascal-programming.info/lesson7.php
Procedure DrawLine; 
{This procedure helps me to 
 avoid the repetition of steps [1]..[3]}
Var Counter : Integer;

Begin
 textcolor(green);
 For Counter := 1 to 10 do
  Begin {Step [1]}
   write(chr(196)); {Step [2]}
  End; {Step [3]}
End;
Begin
 GotoXy(10,5);
 DrawLine;
 GotoXy(10,6);
 DrawLine;
 GotoXy(10,7);
 DrawLine;
 GotoXy(10,10);
 DrawLine;
 Readkey;
End.

The example above is a program that can draw a line. The procedure is how to draw a line. The begin and end are the actual actions that are going to be executed. The first begin is a loop and another begin is nested in the first one. Then the procedure ends. Then the new begin and end run.

Parameter Passing

Paramters are the information which variables hold. This could be a boolean, string or an integer. Parameter passing is when different classes and function swap the parameters over so that they can all use them.
if - an 'if' in programming is a statement used to start a condition and a consequencing action. A condition is set and if the condition is true then you will run code to perform an action. For example,
if(iNumber == 10){System.out.println("Your Number is 10")}; is a piece of code which uses an if statement, in this case if the number is equal to 10 then display the text "Your Number is 10".

else - an 'else' in programming is a piece of code which allows an action to be performed if the an if statement is false. For example, you can add an else statement to the example code above. Eg.
if(iNumber == 10){System.out.println("Your Number is 10")};
else{System.out.println("Your Number is not 10"); }
Now the code has two actions, one if the condition is true and one if it is false.

else if - an 'else if' statement is used to create multiple if statements in one section of a program. For example,  if(iNumber == 10){System.out.println("Your Number is 10")};
 else if(iNumber == 13){System.out.println("Your Number is 13")};
 else if(iNumber == 15){System.out.println("Your Number is 15")};
else{System.out.println("Your Number is not 10,13 or 15"); }
means that if the number is 10 then say your number is 10, if your number is 13 then say your number is 13 and if your number is 15 then say your number is 15, if it is not any of them then say your number is not 10,13 or 15.
for -  a 'for' is a loop which can be used in programming. It is used when you know how many times you want a particular action to repeat itself. For example,
you set and create a variable in the first section of your brackets so you could create an integer called iNumber and it is equal to 1. The next part of the bracket would be, when to stop the part of the program so you could say stop the program when iNumber is equal to 5 and the last part of the bracket you would set it to what happens to the integer each time it loops, so you could say iNumber = iNumber + 2. Your code would look like
for(int iNumber = 1; iNumber = 5; iNumber = iNumber +2){'your action would be set in these curly brackets};
Everytime the code loops, 2 will be added to iNumber so 1 +2 = 3 which is not equal to 5 so loop again. So iNumber is equal to 3 so 3 + 2= 5 which is the desired number so the prgram would stop.
int - int is used to create a variable which is an integer (a whole number). For example the code, '
int iNumber' creates an integer variable which is called iNumber.
char - char is used to create a variable which is a character (one letter, number or symbol). For example the code,'char cCharacter1; creates a character called cCharacter1.
String - String is used to create a variable which is a piece of text. For example, the code,'String sWord' creates a string called sWord and can be set to a line of text or a word.
Double - double is used to create a variable which is a number which can have decimals in it. For example, the code,'Double dPrice' creates a double variable called dPrice and can have decimals such as '1.56'.
Boolean- A boolean is a variable that can either be true or false. For example, the code, 'Boolean bOver50' creates a boolean called bOver50 and that can either be true or false so you can or cannot be over 50.





No comments:

Post a Comment