Tuesday, 11 November 2014

Suitability of Procedural Languages for Graphical Applications.

Suitability of Procedural Languages for Graphical Applications.

Procedural programming is most definitely suitable for making graphical applications, this is because procedural programming allows you to keep re-reusing a block of code over and over again. It is also known as one of the best alternatives for making graphical based applications due to operating systems such as Linux. Also graphical applications have to be given certain and specific steps in order to work and because of this it is a perfect match with procedural programming as the whole concept of procedural programming languages are to set straight and simple or in other words specific steps for a program to work. However there are better methods for graphical applications out there. Procedural programming is suitable for making graphical based application however they are not the best. A better method to use is Event driven programming as they are made for the purpose of making graphical applications.






This is my Example of a graphical application, as you can see when you run this program a pop up box pops up and ask's for your name. There are many techniques to make a graphical application and procedural programming is one of them however it is not the best way , in my opinion event driven programming is the best way to create graphical based applications. 





Modular Elements Are Important (M1)

Modular Elements Are Important !

Modularity is a general concept which applies to the development of software. It allows individual modules to be developed, in many cases this is done with a standardized interface to allow modules to work and communicate properly. Each module works independent to each other. Large software systems are really hard and complex to build this is where modularity comes in to break down a large system into separate physical entities that in a nutshell make it easier and more straightforward to understand.
In procedural programming modular elements are a programming style in which the program is split up into small parts or chunks, each one of these chunks contribute to the program and perform a task. Procedural programming gives a computer  specific steps however modular makes it easier for the computer to understand the instructions.
As you can see this is my example of modular code. The code has been separated into modular elements. Skin colour, Name, Son, Weight and sex are all now modular elements. The whole code has been put in modular elements because it makes it easy to understand and it makes it easier for the computer to understand. 




To activate the modular codes you have to add Set before the element. For e.g. (setWeight) then  you can set the weight to what you want. As you can see the whole code has been set into sub codes which makes it easier to solve and if any problems occur then its easier to solve. Also the code has been set into order such as name, sex and weight which is really good and easy top understand.

Advantages of using modular elements:
  • Modules can be re-used over and over again.
  • This technique is used when working as a part of a team as each member will have a different module to work on. 
  • It is easier to test a small modular program than a whole program and easier to find mistakes.
  • Programs which are not written in modules are harder to understand.
  • You can work on each module independently, Working on small parts at a time makes making a program a much faster and efficient process. 









































































Key features of procedural programming (P1)


Key features of procedural programming (P1)

Introduction: During this assignment i have been asked to discuss the key features of procedural programming and how and why it is used.


  1. Predefined functions.
  2. Local variables.
  3. Global variables.
  4. Parameter passing.
  5. Modularity.
  6. Procedures.
  7. Programming libraries.
  8. Procedural programming paradigm.
  9. Include two example programming languages as examples.
  10. Include samples of code including: if, else, else if, for, int, char, String, double and boolean explaining what parts do.

A: pre-defined functions, Predefined functions are methods which are already defined or in other word are built in the library of the program your using. For e.g. java have many pre-defined functions. I will give a few examples….
String sName;
SName = sName.toUpperCase ();
This is a pre-defined function within java as it is automatically tells the program to put the text into uppercase letters. This phase is already built into java therefore it is a pre-defined function. Alternatively another pre-defined function is….
SName = sName.toLowerCase ();
This is the exact opposite to the first phase as this time it is telling the program automatically to turn the letters into lower case letters.  Both examples are pre-defined functions as they are already built into the program. There are many predefined functions.

B; Local variables.  A local variable is a variable that is declared in the body of a method that you make. They you can use that variable only in the method you made. If you have other methods in the class they will not even be aware that the variable even exists. Here is an example of a program using a local variable…..
Public class HelloWorld
{
String sMyName;
      sMyName="Husnain";
      System.out.println(sMyName);
This is an example of a local variable. You don’t specify the static on declaration for a local variable, but if somehow you do the compiler will read the program and in return send you an error message and will refuse to compile your program.   

C; Global variables;

int g_nX; // global variable
int main()
{
int nY; // local variable nY
// global vars can be seen everywhere in program
// so we can change their values here
g_nX = 5;
} // nY is destroyed here

This is an example of a Global variable. Variables that are declared outside a block are known as Global Variables. Global variables have a program scope, in other words this means they can be accessed anywhere/everywhere within the program. The only way they can be destroyed is when the program ends as they are global. Unlike local variables Global variables can be accessed anywhere throughout the program. A global variable maybe used when you want to declare a variable that needs to be accessed by all parts of your program.        

D; Parameter passing; A parameter is a type of variable that you can pass into a function. Variables are the listed parts of each methods declaration. Each parameter must have a unique name and have a defined data type. For e.g. when you first open up java you get this code..
Public static void main (String[]args)
This this a type of function that takes one argument, an array of strings that’s called args. Furthermore there is a tye of way you write stuff to get input back.. System.out.println(“HelloWorld”). To sum up you have a function that takes one parameter. The value of the parameter is the string “HelloWorld”.

E: modularity;
Modularity is a general concept which applies to the development of software. It allows individual modules to be developed, in many cases this is done with a standardised interface to allow modules to work and communicate properly. Each module works independent to each other. Large software systems are really hard and complex to build this is where modularity comes in to break down a large system into separate physical entities that in a nutshell make it easier and more straightforward to understand.

F: Procedure; Procedures are just small programs. They are sometimes known as sub-programs. The purpose of a procedure is to help a programmer avoid repition. A procedure start off with a begin and end up with end;. The procedure can also have its own variables which cannot be used the main program. In a nutshell a procedure is a section of a program that performs a specific task or in other words an ordered set of tasks for performing some sort of action.

G: Programming Libraries; There are many Libraries in programming. They each contain some unique functions and subroutines for a specific program. For e.g. when I was programming to make graphical sub boxes to appear I had to write a specific code before inputting my codes.
  import,.javax.swing.*;
This code allowed me to have graphical boxes to pop up. When I typed this code it gave me access to a specific library. So I could use its functions and subroutines.

H: Programming paradigms; there are three standard programming paradigms that can be used to implement algorithms. The three paradigms are….
Procedural programming – this is a high level programming paradigm. This has a basic rhythm/sequence of statements. This is straightforward and simple way of programming as it does not get complicated.
Object orientated programming- this is more of a problem modelling. And has a specific way of structuring a program. This method contains data and methods.
Flow programming- flow programming involves chaining a sequence of smaller processes together and allowing a flow of information through the sequence.
There are many programming languages however some vary in the way they are written. Two examples of good programming languages are Java and C++.Here are two examples of the languages.
Public class HelloWorld
{
String sMyName;
      sMyName="Husnain";
      System.out.println(sMyName);
This is a example of java, as you can see this is a small and straightforward program. There are many advantages of using a program like java for instance..

I)
Advantages of Java....
Java is fast and easy to learn.
Java is object-orientated meaning you can create modular programs and re-usable codes.
Java is secure
And lastly java is platform independent……
Here are some advantages of c++
Great program for people who are interested in making games.
It is a good language to learn enabling you to limitless benefits
It is relatively clear and mature language
C++ is a great language however it may take more time to learn that a program like java as there is a lot more to learn

J) There are many samples of codes, here I will explain a few.
Integer: Known as an int int the java program it is used to declare an whole number this is good for various things from age to birthyear.
Boolean: Boolean is used to declare a true or false statement, in other words Boolean is a data type used to hold true or false data this cannot be used with math calculations. 
Char: This is used to declare a single character it cannot hold more than a character, this is good to declare sex (M or F) and many other things.
Data types: 
byte: this can hold numbers in the range off -128 to +127
short: this can hold numbers ranging from -32,786 to + 32,767
long: this can hold number in the range of -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
IF) IF statements are used alot in java, this is a method of asking the program a question. for e.g. if you have a requested a user to use numbers instead of characters then you may use an IF to detect any characters and to tell users to use numbers, An example of an if statement....

        if(sAge.contains("A")){
                            sAge = JOptionPane.showInputDialog(null,"please input your name in numbers  " + sName,"Enter your Age please...",JOptionPane.WARNING_MESSAGE);
This is telling the program to see if the letter A is found then to send an error message to0 the user telling them to write in numbers not letters.
Else and Else if: Instead of using IF twice you can use IF then Else this make your program look better and more efficient. Else follows after a IF and is executed when a Boolean is expression is proven false.
Here is an example....
if(sAge.contains("A")){
                            sAge = JOptionPane.showInputDialog(null,"please input your name in numbers  " + sName,"Enter your Age please...",JOptionPane.WARNING_MESSAGE);

        }else if(sAge.contains("B")){
                sAge = JOptionPane.showInputDialog(null,"please input your name in numbers  " + sName,"Enter your Age please...",JOptionPane.WARNING_MESSAGE);
As you can see this is an Else statement this is just a shorter way for the program to read through and find an expression which proves the Boolean false. If the first condition does not work then the program will check the second one.

FOR: The for statement provides a good and compact way of repeating a range of values, this is often referred to as a for loop by programmers as it repeatedly loops until a certain condition is satisfied. 

for (initialization; termination;
increment) {
statement(s)
}
This is an example of a For or for loop.
WHILE LOOP: The while loop is used to control a structure and it allows you too repeat a task a number of times. The while loop keeps repeating until the condition is satisfied, here is an example... 
    
int x = 10;
        
        while( x < 20 ) {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("\n");
      }
This is basically telling the program to keep looping until the value of x is near 20, this means it will only loop till the number 19.