Showing posts with label PROGRAMMING. Show all posts
Showing posts with label PROGRAMMING. Show all posts

Tuesday, September 6, 2011

CONSTANTS, VARIABLES, DATA TYPES

Form5 : Constants & Variables & Data Type

5 Basic elements in programming.

1. Constant.
2. Variable.
3. Data Type.
4. Operators.
5. Control Structures.

Constants
Constant is a data container that stores information. The value will never change (remains constant) at any time during the course of a program.

Declare is the official term used in programming to announce to the program
the condition of statement in programming.

Variables
Variable is a data container that stores information. The value inside may change at any time during the course of a program.

DATA EXAMPLES FOR DIFFERENT DATA TYPES

Data type determines the type of data a variable can store, for example a number or a character. Examples of data types are integer, double, string and boolean.

Integer
Integer data type contains any whole number value that does not have any fractional part.
This is how we declare an integer type constant in Visual Basic statement.
This is how we declare an integer type variable in Visual Basic statement.

Double
Any number value that may and could contain a fractional part.
This is how we declare a double type constant in Visual Basic statement.
String
Any value that contains a sequence of characters.
This is how we declare string type constant in Visual Basic statement.

Boolean
Boolean type consists either a True or False value. Programmers usually use it to store status.
This is how we declare a boolean type constant in Visual Basic statement.

LOGICAL OPERATORS, FLOW CHART, CONTROL STRUCTURE

Form 5 : Logical Operators, Flow Chart, Control Structure

FUNCTIONS OF LOGICAL OPERATORS
Logical operators are notations that tell the computer to perform logical operations.
Examples of Logical operation are: AND, OR, and NOT.
Logical operator compares 2 conditions and returns a TRUE or FALSE value.


AND operator
Notice that truth value of X AND Y is True ( 1 ) if only both X and Y are True ( 1 ).
Else it is false ( 0 )


OR operator
Notice that truth value of X OR Y is only True ( 1 ) if either X or Y are True ( 1 ) or both X and Y are true ( 1 )
Else it is false ( 0 )


NOT operator
The diagram shows the truth table of NOT operator NOT X is the negation of X, it is essentially the 1's complement operation.
Notice that truth value of NOT X is True
( 1 ) when X is False and vice versa.


FLOW CHART
Let’s identify some of the main elements in the flow chart. We have five main elements in a flow chart.

Flowline and arrowhead use to connect symbols and indicate the sequences of operation.
Input or output shows either an input operation (e.g. an INPUT from the
user) or an output operation (e.g. PRINT some messages).

Process shows a process to be carried out (e.g. calculation).
Decision shows a decision (or choice) to be made. The program should continue along one of two routes (e.g. if...else).

A flow chart is a diagram using symbols to show the step-by-step sequence of procedures in a program. A flow chart describes the logic and program flow of a computer program graphically.


CONTROL STRUCTURES
Control structure is a structure of statements in programming that allows
the programmer to control the flow of a program.
Control structure can be divided into sequence, selection and repetition control structures.


SEQUENCE CONTROL
Sequence control refers to the linear execution of codes within a program. In sequence control, the statements are executed one by one in consecutive order.
In sequence control, the statements are executed one by one in consecutive order.

This program will request the user’s date of birth and then request today’s date, calculate the age and finally will print the user’s age.
It will execute statement 1 followed by statement 2 and any following statements.


SELECTION CONTROL
There are times when you want your program to make a decision based on the situation given.
For example, a program that stores student’s marks may respond differently to different marks.
Or maybe a simple mathematical program will display its result as odd or even, based on the result.
Selection control enables the programmer to assign different events for different situations.

An example of selection control is “If...Then...Else” statement. The basic pseudo code for “If...Then...Else” statement is as follows.
A student requests her service hours in a library from the program, the
program will then check whether her service hours are more than/equal to 30 or not.

If the service hours are over or equal to 30, the program will print a message, “Thank you for your service”.

If the service hours are lower than 30 then the program will print a message, “Please continue to serve in the library”.

PROGRAM DEVELOPMENT PHASES

Form 5 : Five Program Development Phases

In program development, there are five main phases. These phases are a series of steps that programmers undertake to build computer programs. The program development phases guide computer programmers through the development of a program.

The five main phases of program development are as follows:

PROBLEM ANALYSIS PHASE
During the problem analysis phase, the programmer will interview the client to find out what the client’s needs are.

For example, the client might be a school that wishes to set up a school registration program. So the school administrator might tell the programmer that they need to record students’ data such as name, date of birth, gender, class, parents’ names, address and contact numbers.

PROGRAM DESIGN PHASE
Based on that, the programmer will design a flow chart that represents the needs of the client, which in this case is the school registration program.

CODING PHASE
Once the flow chart is confirmed, the programmer will perform coding.

TESTING AND DEBUGGING PHASE
The school registration program will be tested by the users at the client’s site. In this case, it will be the school office administrators. If there are any errors, the programmer will do a debugging of the program.

They either show up as you type the program code, or if you have turned off the automatic syntax error check, the syntax errors show up when you try to run or compile the program.


DOCUMENTATION PHASE
After this, the programmer will complete the documentation for the program; this includes the user manual, a clear layout of the input and output records and a program listing.


LATEST PROGRAMMING LANGUAGE

Form 5 : Latest Programming Language

THE LATEST TYPE OF PROGRAMMING LANGUAGES

1. FIFTH GENERATION LANGUAGES

Fifth generation programming language (5GL) is an advance programming language which concentrates on solving problems using constraints given to the program.

In fifth generation language, the programmer just need to define the problem to be solve and the program will automatically code the program based on the problem definition.

Fifth generation languages are designed to make the computer solve the problem for you.
Fifth generation languages are mostly used in artificial intelligence research.
Examples of fifth generation languages include Prolog and Mercury.

2. NATURAL LANGUAGE

Natural Language programming aims to use natural language such as
English to write a program.

Instead of using a specific programming language syntax, natural language
programming will use normal English as the input to program software.

Such a technique would mean less technical programming knowledge
is required to write a program.
The programmer needs to define the program using normal language.

3. OPENGL (GRAPHIC LIBRARY)

OpenGL (Graphics Library) is a standard specification to describe the standard Application Programming Interface (API) for 3D/2D computer graphic applications.

OpenGL specification describes a set of functions and the exact behaviours that the 3D/2D application must perform.
OpenGL was developed by Silicon Graphics.

OpenGL is widely used in virtual reality, scientific visualisation, flight simulation and video game development.