Showing posts with label programing. Show all posts
Showing posts with label programing. Show all posts

Friday, November 3, 2017

Programing languages lesson 1



COMPUTER PROGRAMMING LANGUAGES

Introduction

By the end of this Topic, you should …

• Explain the concept of programming

• Understand the different types of programming languages.

• Describe the programming life cycle.

• Select appropriate programming Language

• Understand the concept of algorithms

• Use pseudo-code and flow-charts to solve problems

• Identify data structure

• Design a program

• Apply Control structure in program design.

• Develop functions.

• Develop array and string.


Concept of Programming

l Program – a very specific set of instructions (or command lines) that making a computer do what you want it to do


l Programming – the process of creating a program the development of a solution to an identified program, and setting up of a related series of instructions which, when directed through computer hardware, will produce the desired results


l A programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human communication


For example:-

- PASCAL, C, JAVA, C++, VISUAL BASIC, ADA, LISP, FORTRAN, COBOL, PROLOGUE, PYTHON, C# etc

WHY STUDY PROGRAMMING LANGUAGES?

1. To improve your understanding of the language you are using.

- Many languages provide features when used properly are of benefit to the programmer but when used improperly may waste large amounts of computer time or lead the programmer into time-consuming logical errors.

Eg. Use of array and single variable data storage



2. To increase your vocabulary of useful programming constructs.

- Language or the syntaxes/commands aid the programmer to implement the logic of the program

- In searching for the data and program structures suitable to the solution of a problem, one tends to think only of structures that are immediately expressible in the languages with which one is familiar.

- By studying the constructs provided by the wide range of languages and the manner in which these constructs are implemented, the programmer increases his programming “vocabulary”.


3. To allow better choice of programming language

- Ex. C and Java


4. To make it easier to learn a new language

- A thorough knowledge of a variety of programming language constructs and implementation techniques allows the programmer to learn constructs and implementation techniques allows the programmer to learn a new language more easily when the need arises


5. To make it easier to design a new language

- The user interface can be designed by a programmer if he has a thorough knowledge of the p.l.

- The user interface consists of the commands and data formats that are provided for the user to communicate with the program

- The aspect of program design is often simplified if the programmer is familiar with a variety of constructs and implementation methods from ordinary programming languages.





Types of Programming Ltanguages

l Three types of programming languages

– Machine languages

l Strings of numbers giving machine specific instructions

l Example:

+1300042774 (these would really be in binary)

+1400593419

+1200274027

MACHINE LANGUAGES

v Comprised of 1s and 0s

v The “native” language of a computer

v Difficult to program – one misplaced 1 or 0 will cause the program to fail.

Example of code;
1110100010101 111010101110
10111010110100 10100011110111

– Assembly languages

l English-like abbreviations representing elementary computer operations (translated via assemblers)

l Example:

LOAD BASEPAY

ADD OVERPAY

STORE GROSSPAY

ASSEMBLY LANGUAGES

v Assembly languages are a step towards easier programming.

v Assembly languages are comprised of a set of elemental commands which are tied to a specific processor.

v Assembly language code needs to be translated to machine language before the computer processes it.

Example:
ADD 1001010, 1011010

NB: Assembler:- A program for converting instructions written in low-level symbolic code into

machine code.

- A computer program which translates from assembly language to an object file or machine language format

- An assembler is a type of computer program that interprets software programs written in assembly language into machine language, code and instructions that can be executed by a computer.


– High-level languages

l Instructions closer to everyday English

– English is a natural language. Although high level programming languages are closer to natural languages, it is difficult to get too close due to the ambiguities in natural languages (a statement in English can mean different things to different people – obviously that is unacceptable for computer programming).

– Use mathematical notations (translated via compilers)

Example:

grossPay = basePay + overTimePay

– Interpreter – Executes high level language programs without compilation.

HIGH-LEVEL LANGUAGES

v High-level languages represent a giant leap towards easier programming.

v The syntax of HL languages is similar to English.

v Historically, we divide HL languages into two groups:

– Procedural languages

– Object-Oriented languages (OOP)

A compiler:-

- Is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses. Typically, a programmer writes language statements in a language such as Pascal or C one line at a time using an editor.The file that is created contains what are called the source statements.

- Is a program that translates a source program written in some high-level programming language (such as Java) into machine code for some computer architecture (such as the Intel Pentium architecture). The generated machine code can be later executed many times against different data each time.

An interpreter:–

- Is a program that reads an executable source program written in a high-level programming language as well as data for this program, and it runsthe program against the data to produce some results.

- One example is the Unix shell interpreter, which runs operating system commands interactively

- Note that both interpreters and compilers (like any other program) are written in some high-level programming language (which may be different from the language they accept) and they are translated into machine code. For example, a Java interpreter can be completely written in Pascal, or even Java. The interpreter source program is machine independent since it does not generate machine code. (Note the difference between generate and translated into machine code.) An interpreter is generally slower than a compiler because it processes and interprets each statement in a program as many times as the number of the evaluations of the statement.

Compilers and interpreters are not the only examples of translators. Here are few more:
Source Language
Translator
Target Language
LaTeX
Text Formater
PostScript
SQL
database query optimizer
Query Evaluation Plan
Java
javac compiler
Java byte code
Java
cross-compiler
C++ code
English text
Natural Language Understanding
semantics (meaning)
Regular Expressions
JLex scanner generator
a scanner in Java
BNF of a language
CUP parser generator
a parser in Java


NB:-Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed.
Procedural Languages
v  Early high-level languages are typically called procedural languages.
v  Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure.
v  Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript

Object-Oriented Languages
v  Most object-oriented languages are high-level languages.
v  The focus of OOP languages is not on structure, but on modeling data.
v  Programmers code using “blueprints” of data models called classes.
v  Examples of OOP languages include C++, Visual Basic.NET and Java.