Wednesday, 5 December 2018

Programming languages


Programming languages:
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.

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

Flow chart


Flow charts:
Flowchart is a graphical or symbolic representation of an algorithm. It is the diagrammatic representation of the step-by-step solution to a given problem.
Def: An algorithm in pictorial form is called a flow chart.
The flow chart is primarily used as an aid in formulating and understanding algorithms. The sequencing of instructions and repetition of groups of instructions may be quickly seen by inspecting a flow chart.
For easy visual recognition, a standard convention is used in drawing flow charts. In this standard convention the following shapes are used for various blocks in a flow chart.


Algorithm & Key features / Characteristics of an Algorithm


Algorithm
  • The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.
  • An algorithm may be defined as a finite sequence of steps each of which is precise, unambiguous and executable in finite time.
  • Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.
  1. Input :> There are zero or more quantities which are externally supplied.
  2. Output :> At least one quantity is produced.
  3. Definiteness :> Each instruction must be clear and unambiguous.
  4. Finiteness :> If we trace out the instructions of an algorithm, then for all cases the algorithm will terminate after a finite number of steps.
  5. Effectiveness: Every instruction must be sufficiently basic that it can in principle be carried out by a person using only pencil and paper.
 
Key features / Characteristics of an Algorithm
Not all procedures can be called an algorithm. An algorithm should have the following characteristics −
  • Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning.
  • Input − An algorithm should have 0 or more well-defined inputs.
  • Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.
  • Finiteness − Algorithms must terminate after a finite number of steps.
  • Feasibility − Should be feasible with the available resources.
  • Independent − An algorithm should have step-by-step directions, which should be independent of any programming code.
Example:
1. Write an algorithm to convert the temperature in centigrade to the temperature in Fahrenheit. 
Solution:
Step 1. Read the numeric value of C.
step 2. Calculate F using Formula F= (9/5)*c+32.
Step 3. Write numeric value of F.
Step 4. Stop
2. Write an algorithm to checking whether a number is even or odd.
Solution:
Step 1. Read the given number, say x.
Step 2. Devide x by 2.
Step 3. If the remainder is 1, then print x is odd
Step 4. Otherwise print x is even.
Step 5. Stop.
3. Write an algorithm to find the area of circle.
Solution:
Step 1. Read the value of radius.
Step 2. Calculate area using formula area=3.14*radius*radius.
Step 3. Write the value of area.
Step 4. Stop.

Compile a C program in Ubuntu Linux

Step 1: press Alt + Ctrl + T to open a terminal

Step 2: create a directory with your name Ex. mkdir Sateesh

Step 3: to change the director type cd Sateesh

Step 4: to create a c file type gedit welcome.c
           now it will open the editor, type the following code.


#include<stdio.h>
void main()
{
  printf("welcome to c!");
}


Step 5: Save and close the file.

Step 6: Now to compile the c program, command is..
           cc welcome.c

Step 7: To run the c program command is ..
           ./a.out

Step 8: It will display welcome to C! as output.