Wednesday, 22 October 2014

Key features of procedural programs

Predefined functions

Predefined function in java are are functions which are defined inside of the java library. These functions are things like "System.out.println("Hello world!")". This predefined function displays a message on your screen saying "Hello world!". This predefined function can also be used to display other predefined functions, for example:
"String sName=”Alex";
char cPosition=sName.charAt(0);
System.out.println(“The letter at position 0 is “ + cPosition);"
In this, the first letter of the string sName is identified and then displayed on the screen.

Local variables
Local variables are variables that are declared within methods and they are only visible withing the declared method. Local variables are useful for storing data but they are only available within the class it is defined in. Examples of local variables in java:
char cInitial='A';
int iAge=16;
boolean bAlive= true
string sName="Alex"
The char method can hold one letter like in this example is "A". Whilst the int method can contain integers between -214748367 and 214748367. Boolean is a true and false question like for example asking if someone is alive. A string is a variable which can hold a mixture of numbers, letters and symbols, these are very useful for storing all types of data.

Global variables
A global variable is a variable that is visible throughout the entire program (unless the variable is shadowed). The set of all of the global variables is known as the global environment or the global state. But global variables are only accessible once they have been declared. For example in C++ a global variable that can modify age:
int age;
int main(){
           age = 18;
           int newage = age + 5;
}


Parameter passing

Parameter passing is the mechanism/method used to pass parameters to produce a function. The most common method used is to call/ pass the value of a parameter or to pass the location of the parameter. The less used method for parameter passing is to change the value of a parameter. For example using C# this example shows both of these methods.

class Program
{
    static void Main(string[] args)
    {
        int arg;

        // Passing by value. 
        // The value of arg in Main is not changed.
        arg = 4;
        squareVal(arg);
        Console.WriteLine(arg);
        // Output: 4 

        // Passing by reference. 
        // The value of arg in Main is changed.
        arg = 4;
        squareRef(ref arg);
        Console.WriteLine(arg);
        // Output: 16 
    }

    static void squareVal(int valParameter)
    {
        valParameter *= valParameter;
    }

    // Passing by reference 
    static void squareRef(ref int refParameter)
    {
        refParameter *= refParameter;
    } 
}

Modularity

Modularity is designing a program or a system where it is divided into sets of modules that are can be used to create a larger application allowing it to be used and created easier as you can use the modules in other programs other than the one intended. Creating modules also makes the code a lot easier to read and debug and test. Here is a example of how modularity works.

Procedures
Procedures are a structured section of a program that . Procedures are also known as methods, routines, functions etc... During any time of the program being executed a procedure may be called for example a string may be called at any time. A procedure is like a set of basic instructions for the computer to follow.

Programming libraries
Programming libraries allow different methods to be used. Each programming library has its own preset routines/methods but if you use a programming language like java then you have to import the library each time. For example, the package in java to use graphical resources is written like this:
import javax.swing.*;
Using this package/ library allows you to use methods such as:
String sName= JOptionPane.showInputDialog(null,"What is your name?","Name",JOptionPane.QUESTION_MESSAGE);
This will display a box on your screen asking for your name and if nothing is input it is saved as "null" or the string will be saved as what was input.

Procedural programming paradigm

Procedural programming can be defined as a subtype of imperative programming as a programming paradigm based on the concept of calling procedures, this means that statements are structured into procedures (also known as subroutines or functions). A procedural program is usually made of several modules.

No comments:

Post a Comment