Monday 10 December 2018

Generations of Programming Languages


Programming language:
A programming language is a set of rules that tells the computer what operations to do. These languages are used by the programmers to create other kinds of software.

Generations of Programming Languages
The five generation of programming languages start at the lowest level with
(l) machine language. They then range up through
(2) assembly language,
(3) high level languages (procedural and object-oriented languages), and
(4) very high level languages (problem-oriented languages). At the highest level are
(5) natural languages.

First Generation: Machine Language
Machine language is the basic language of the computer, representing data as 1s and Os. Each CPU model has its own machine language: Machine language programs vary from computer to computer, i.e., they are machine-dependent. . These binary digits, which correspond to the on and off electrical states of the computer, are clearly not convenient for people to read and use.
Advantages:-
·         Very efficient
·         Require less storage space
 Disadvantages:-
·         Machine dependent
·         Programming is difficult

Second Generation: Assembly Language
assembly language is a low-level programming language that allows a computer user to write a program using abbreviations or more easily remembered words instead of numbers, A programmer can write instructions in assembly language more quickly than in machine language, In these languages, each numeric instruction is assigned a short name (called a mnemonic) that is easier to remember than a number.
Advantages:-
  • It is easier to modify than machine language
  • Easier to understand and use
Disadvantages:-
  • The coding to assembly language is time consuming
  • They are also machine dependent
An assembler, or assembler program, is a program that translates the assembly-language program into machine language.
Assembler
An assembler is a computer program that translates assembly language statements into machine language codes. The assembler takes each of the assembly language statements from the source code and generates a corresponding bit stream using O's and 1 's. The output of the assembler in the form of sequence of O's and l's is called object code or machine code. This machine code is finally executed to obtain the results.

Third Generation: High-Level or Procedural Languages
A high level or procedural language resembles some human language such as English. For example, COBOL, which is used for business applications. A procedural language allow users to write in a familiar notation, rather than numbers or abbreviations, Also, unlike machine and assembly languages, most of procedural languages are not machine­dependent-i.e., they can be used on more than one kind of computer. Few examples, are FORTRAN, COBOL, BASIC and Pascal.
For a procedural language we need language translator to translate it into machine language. Depending on the procedural language we may use either of the following types of translators: -
Compiler
The compiler is a computer program that translates the source code written in a high-level language into the corresponding object code of the low-level language. This translation process is called compilation. The entire high-level program is converted into the executable machine code file. Compiled languages include COBOL, FORTRAN, C,C++, etc.  
Interpreter
The interpreter is a translation program that converts each high-level program statement into the corresponding machine code. This translation process is carried out just before the program statement is executed. Instead of the entire program, one statement at a time is translated and executed immediately. The commonly used interpreted language is BASIC and PERL.
Compiler
(a) Scans the entire program first and translates it into machine code.
(b) Converts the entire program to machine code
(c) Slow for debugging (removal of mistakes from a program).
(d) Execution time is less.
Interpreter
(a) Translates the program line by line.
(b) Each time the program is executed, every line is checked for syntax error and then converted to equivalent machine code.
(c) Good for fast debugging.  
Advantages:-
·        These are easy to learn.
·        Easier to maintain.
·        They are not machine dependent.
·        Programs are portable.

Fourth Generation:  Problem Oriented Languages
Third-generation languages tell the computer how to do something. Fourth generation languages, in contrast, tell the computer what to do. Very high-level or problem-oriented languages, also called fourth-generation languages (4 GLs), are much more user-oriented and allow users to develop programs with fewer commands compared with procedural languages, although they require more computing power. These languages are known as problem-oriented because they are designed to solve specific problems, whereas procedural languages are more general-purpose languages.

Three types of problem-oriented languages are report generators, query languages, and application generators.

Report generators
A report generator, also known as a report writer, is a program for end-users that produces a report. The report may be a printout or a screen display.
Query languages
A query language is an easy-to-use language for retrieving data from a database management system.
Application generators
An application generator is a programmer's tool consisting of modules that have been preprogrammed to accomplish various tasks

Fifth Generation: Natural Languages
Natural languages are of two types. The first are ordinary human languages: English, Spanish etc. The second are programming languages that use human language to provide people a more natural connection with computers.
Natural languages are part of the field of study known as artificial intelligence. Artificial intelligence (AI) is a group of related technologies that attempt to develop machines capable of emulating human-like qualities, such as learning, reasoning, communicating, seeing and hearing.
Use of High Level Programming Languages for the Systematic Development of Programs
Let us now consider some of the third-generation, or high-level languages in use today.
Examples: BASIC, COBAL,  
BASIC
Advantage: The primary advantage of BASIC is its ease of use.
Disadvantages:  Its processing speed is slow.
COBOL:
COBOL is the language of business and it was formally adopted in 1960, COBOL (for Common Business-Oriented Language) is the most frequently used business programming language for large computers. Its most significant attribute is that it is extremely readable. For example, a COBOL statement might be :
MULTIPLY HOURLY-RATE BY HOURS-WORKED GIVING TOTAL-PAY
COBOL, too, has both advantages and disadvantages.
Advantages:
 (1) It is machine independent.
(2) Its English-like statements are easy to understand, even for a nonprogrammer.
(3) It can handle many files, records, and fields.
(4) It easily handles input/output operations.
Disadvantages:
(1) Because it is so readable, it is wordy. Thus, even simple programs are lengthy, and programmer productivity is slowed.
(2) It cannot handle mathematical processing as well as FORTRAN

FORTRAN:
FORTRAN is the language of mathematics and the first high-level language. It was developed in 1954 by IBM; FORTRAN (for FORmula TRANslator) was the first high-level language. Originally designed to express mathematical formulas, it is still the most widely used language for mathematical, scientific, and engineering problems. It is also useful for complex business applications, such as forecasting and modeling.
FORTRAN has both advantages and disadvantages:
Advantages:
(1) FORTRAN can handle complex mathematical and logical expressions
(2) Its statements are relatively short and simple.
(3) FORTRAN programs developed on one type of computer can often be easily modified to work on other types.
Disadvantages:
(1) FORTRAN does not handle input and output operations to storage devices as efficiently as some other higher-level languages.
(2) It has only a limited ability to express and process non-numeric data.
(3) It is not as easy to read and understand as some other high-level languages.
Pascal:-
Pascal is the simple language. Named after the 17th-century French mathematician Blaise Pascal, Pascal is an alternative to BASIC as a language for teaching purposes and is relatively easy to learn. A difference form BASIC is that Pascal uses structured programming.
A compiled language, Pascal offers these advantages and disadvantages:
Advantages:
(1) Pascal is easy to learn.
(2) It has extensive capabilities for graphics programming. (3) It is excellent for scientific use.
Disadvantage: Pascal has limited input/output programming capabilities, which limits its business applications.
C++ is an Object Oriented Programming (OOP) language. In C++-the plus signs stand for "more than C"-which combines the traditional C programming language with object-oriented capability. C++ was created by Bjame Stroustrup. Three important concepts of OOP are:
Encapsulation, Inheritance, Polymorphism
Advantages
(1) It is portable.
(2) Once the programmer has written a block of program code, it can be reused in number of program.
GUI based Languages
The Graphical User Interface (GUI as the name suggests, uses illustrations for text, which help users to interact with an application. This feature makes it easier to understand things in a quicker and easier way.
Visual Basic: Visual Basic is an example of visual programming. Visual BASIC is a Windows-based, object-oriented programming language from Microsoft that lets users develop Windows and office applications.
Visual C++ : This language is a GUI extension of conventional C++ language. It is a part of Microsoft Visual Studio software package. It is an Object Oriented Programming language that has been designed for producing high level object oriented applications, that can work with hardware devices, for example-Windows applications and device drivers.
 Techniques for designing program are:-
·        Top-down Design (Stepwise Refinement)
·        Modular Approach
·        Structured Programming
Structured Programming
Structured programming takes a top-down approach that breaks programs  into modular forms. The main objectives of structured programming are
·  Efficiency
·  Readability
·  Clarity of programs
·  Easy modification
·  Reduced testing problems.
The goto statement should be avoided so far as possible. The three basic building blocks are given below
 Sequence Control Structure : It consists of a single statement or a sequence of statements with a single entry and single exit 

Loop or Iteration:- It consists  of a condition (simple or compound ) and sequence structure which is executed condition based  

Binary decision structure:- It consists  of a condition (simple or compound ) and two branches out of which one is to be followed depending on the condition being true or false   

DESIGN AND IMPLEMENTATION OF CORRECT, EFFICIENT AND MAINTAINABLE PROGRAMS
The design and development of a correct, efficient, and maintainable program depends on the approach followed by the programmer. A programmer should follow standard methodologies throughout the life cycle of program development. The entire program development process is divided into a number of phases, with each phase serving a definite purpose. Also, the output of one phase acts as an input for the next phase. Let us now understand these standard set of phases in the program development process:
Analysis phase:
 As the name suggests, the first phase of program development involves analyzing the problem in order to ascertain the objectives that the program is supposed to meet. All the identified requirements are documented so as to avoid any doubts or uncertainties pertaining to the functionality of the program.
Designing phase:
This phase involves making the plan of action before actually starting the development work. The plan is made on the basis of the program specifications identified in the previous phase. Different programs require different designing patterns depending on the program specifications.
Development phase:
This phase involves writing the instructions or code for the program on the basis of the design document created in the previous phase. The choice of the programming language in which the program will be developed is made on the basis of the type of program.
Implementation and Testing:
 In this stage, the developed program is implemented in its target environment and its key parameters are closely observed in order to ensure that the program runs correctly. Apart from ensuring the correct functioning of the program this phase primarily focuses on identifying the hidden bugs in the program.


Pseudocode


Pseudocode
Ø Pseudocode is a method of describing computer algorithms using a combination of natural language and programming language .
Ø The pseudocode is just the algorithm written by using programming language syntaxes.
Ø  Pseudo code ia an artifical and informal language that helps programmers develop algorithms. Pseudo code is very simillar to everyday english.
Ø  Pseudocode is a "text-based" detail (algorithmic) design tool.
Ø  .
Example:
  1. Write the pseudocode for calculating the area of circle.
Solution:
1. Scan radius.
2. Area=3.14*radius*radius.
3. Print radius;
4. Stop.
  1. Write the pseudo code for print the maximum number between two numbers.
Solution:
1. Input a and b.
2. If a>b then
3. Print a
4. Else
5. Print b.
6. End

Algorithm for reversing given number


Reversing  given number

Algorithm for reversing given number:
Step1  :   Start
Step2  :   Declare three variables n, rev and r
Step3  :   Read number to be reversed from keyboard ( n )
Step4  :   Assign value 0 to rev
Step5  :   Assign n modulus 10 value into r
Step6  :   Multiply rev value with 10 and add r to it. Store this value in rev.
Step7  :   Divide the number n by 10
Step8  :   Repeat steps 5  to 7 until n is not equal to 0
Step9  :   Print the reversed number ( rev )
Step10:   Stop



Algorithm for generation of Fibonacci Series( n numbers )


Generation of Fibonacci Series:
Algorithm for generation of Fibonacci Series( n numbers ):
Step1  :   Start
Step2  :   Declare three variables a, b and c
Step3  :   Declare n and I
Step4  :   Read number of terms n from keyboard
Step5  :   Assign values a =0 , b=1 and c =0, I =1
Step6  :   Print the value of a
Step7  :   Assign value of b into a
Step8  :   Assign value of c into b
Step9  :   Assign the sum of a and b to c
Step10:   Print c
Step11:   Increment I by 1
Step12:   Repeat steps 6 to 10 until I <= n-1
Step13:   Stop



Algorithm for summation of n numbers


Summation of n numbers
Algorithm for summation of n numbers:
Step1 : Start
Step2 : Declare three variables n, S and I
Step3 : Read n from keyboard
Step4 : Initialize s to 0 and I to 1
Step5 : Add values  of S and I and store it in S
Step6 : Increment value of I by 1
Step7 : Repeat steps 5 and 6 until I <= n
Step8 : Print S
Step9 : Stop




Swapping ( Interchanging ) values of two variables


Swapping ( Interchanging ) values of two variables
Algorithm for swapping values of two variables:
Step1 : Start
Step2 : Declare three variable a,b and temp
Step3 : Read values of a and b from keyboard
Step4 : Assign value of a into temp
Step5 : Assign value of b into a
Step6 : Assign value of temp into b
Step7 : Print a and b.
Step8 : Stop