Thursday, July 16, 2015



Programming Concept                                                 Saman Withanage

A computer program is a sequence of instructions that can be executed by a computer (CPU) that performs a certain task intentioned by the programmer.
Programming language
A programming language is a language used to write computer programs, which involve a computer performing some kind of computation or algorithm and possibly control external devices such as printers, robots, and so on.

Evolution of computer programming Languages
1.      A first Generation Language- 1GL- Used from 1940s
·         Low-Level Language
·         Machine-Level Programming Language- consist 1 and 0 (need not a keyboard to write program
       using 1GL, front panel switch of the computer can be used to write the program.)
·         Program execution Very fast and efficient because CPU can directly execute
·         Difficult use front panel switch then difficult to write and edit
·         Portability is significantly reduced  then Machine Dependent programming language

Example:
ADD       [BX+SI], AX
INT         21
MOV      [00A8], AX
DEC       AX
MOV      ES, AX
MOV      AH, 49

2.A second Generation Language -2GL- from 1950
·         Low-Level Language
·         Some code used for Digits, These codes was called mnemonics.
·         Assembly Langue is introduced as 2GL
·         Assembler is used to convert code into machine language
·         Difficult to write and read large application
·         Machine dependent
3.      A third Generation  Language – 3GL – form late 1954
·         High-Level Language –Machine-independent – Procedural Language
·         Closer to English and Mathematics.
·         High Level Programming Languages.
·         Easy to learn and program.
·         Computer cannot understand programs written in High Level Languages.
·         A translator is needed to convert the program into machine code.
·         Most Languages used today are third generation Languages.
·         FORTRAN (Formula Translation ) -1954 , ALGOL 58 -1958 were earlier 3GL
·         After introducing COBOL (Common Business Oriented Language) in 1959, high-level modern
     Languages come to common use (C, Basic, C++, C#, Java, Delphi, RPG, Self, Perl, Ruby,Python) 
4.      A Fourth Generation Language -4GL  -1982
·         High-Level Language –Machine-independent – nonprocedural Language
·         Like natural language
·         Shorten development time
·         SQL and some scripts languages
5.      A Fifth Generation Language – 5GL – 1990s
·         Very High-Level Language
·         Without certain algorithm and constrains
·         Artificial Intelligence (AI) programs
·         Prolong, OPS5, Mercury , Miranda
·         Yet in research base future developing

Translators
      Used to translate instructions given in a high level language into machine code.
      Two types
     Interpreters
     Compilers
Interpreter: executes a program directly, translation is done while executing. Line by line of a high-level program converted into machine language and execute by the interpreter.   e.g. BASIC, Lisp







Compiler: Changes program to another form before being executed. Source code is converted into object code (at once altogether) that is in machine language.




Source code and byte code
Programming code that once compiled is run through a virtual machine instead of the computer’s processor. By using this approach, source code can be run on any platform once it has been compiled and run through the virtual machine.
Byte code and Binary code
Byte code is a binary data format that includes loading information and execution instructions for the virtual machine. In that sense, Java byte code is a special kind of binary code.
When you use the term "binary code" to mean machine instructions for real processors architecture then it is different. Byte code is not a binary code in that sense. It is not processor-specific. It works on only virtual machine but binary code works on real processor.
Assembler
A computer program to translate between lower-level representations of computer programs; it converts basic computer instructions into a pattern of bits which can be easily understood by a computer and the processor can use it to perform its basic operations

Linkers
A linker is a program that takes one or more objects generated by a compiler and combines them into a single executable program.

Syntax: are codes in which computer programs are written. Different syntax is used in different Programming languages. This can be identified as source code.

Executable code
Software in a form that can be run in the computer. It typically refers to machine language, which is the set of native instructions the computer carries out in hardware. Executable files in the DOS/Windows world use .EXE and .COM file extensions, while executable files in UNIX and Mac do not require specific extensions. They are identified by their file structure.

Problem solving process


Before you try to work any problem, read it carefully to be sure you understand it; then follow this plan:
  1. Identify the problem
  2. Understand the problem
  3. Identify alternative way to solve problem
  4. Select best alternative
  5. Evaluate Solution(test)


.


Algorithm
A technique is to show a process of problem solving. Sequential instructions are presented to solve a well identified problem.  
  • Pseudo code is textual method of Algorithm.
  • Flow Chart is graphical technique of Algorithm.
Flow Chart

Flow Chart symbols
-round rectangles
-rectangles
-parallelograms
Each symbol represents a different type of operation
Start/Finish


Input/Output
Process
Decision
Data Flows
Terminators show the start and stop points in a process..
The Data flowchart shape indicates inputs to and outputs from a process.
Show a Process or action step..
Indicates a question or branch in the process flow. Typically, a Decision  flowchart shape is used when there are 2 options (Yes/No, No/No-Go, etc.)
Flow line connectors show the direction that the process flows.
Connector
Indicates that the flow continues where a matching symbol (containing the same letter) has been placed.

Control Structure
Programs written in procedural languages, the most common kind, are like recipes, having lists of ingredients and step-by-step instructions for using them. The three basic control structures in virtually every procedural language are:

    1. Sequence—combine the liquid ingredients, and next add the dry ones.
    2. Selection—if the tomatoes are fresh then simmer them, but if canned, skip this step.
    3. Iterative—beat the egg whites until they form soft peaks.