Chapter 1

  1. Introductory Concept


1.1 History of Programming Languages


            All digital computers are basically electronic devices that can transmit, store and manipulate information (data).

 

The data may be numeric, character, graphics and sound. So, a computer can be defined as it is an electronic device which gets raw data, processes under instruction given to it.

 

            To process a particular set of data, the computer must be given an appropriate set of instructions are written using codes which computer can understand such set of codes is known as language of computer.

 

            Many different languages can be used to program a computer. As we know that computer is composed of millions of switches which acts like electric switch. Such a switch has two states, ON and OFF, and can be represented with 1 and 0. So, a computer can understand only 0 and 1, which is known as BInary digiTS, in short BITS. So language which uses these binary codes to instruct a computer is known as Machine language.

 

            Machine Language is very rarely used to instruct a computer because it is very difficult and machine dependent (different machine may need different machine codes).

            A low level programming language is a language closer to what machines can understand. Assembly language is an example of low level language. In an assembly language, each machine language instruction is assigned a code. So, instead of having to remember a string of 0’s and 1’s, the programmer would only need to remember short codes like ADD, MOV or SUB.

 

            Low level languages are also processor dependent. A language written for INTEL Processor doesn’t work in MOTOROLA processor. Since, the low level language isn’t understood by CPU, it needs conversion. A computer program which needs to convert the “ASSEMBLY language instruction” into “Machine language instruction” is known as ASSEMBLER.

 

** Computer viruses are mostly written in Assembly.

 

            Today, most programs are written in high level languages, which are quite similar to written English and are therefore easier to use than “machine language” or “low level languages”.

 

            (FORmula TRANslation i.e FORTRAN) introduced in 1956 was the first high level language.


            Instructions written in high level language is more compatible with human languages. Hence, it is easier to instruct computer using it, however it is necessary to be translated into machine codes using translator such as compiler and interpreter. Such programs written in High level language are portable.

 

            A high level language source program is read as input by a program called a translator, which checks its syntax and, if it is free from errors, translates into equivalent machine code object program.

 

            If the source program contains syntax errors, the translators generate a number of messages indicating the nature of the errors and why they occur.

 

Although, it is in machine code, the object program I incomplete because it includes references to sub programs which it requires for such common tasks as reading input, producing output and computing mathematical functions. These sub programs are grouped together in libraries which are available for use by all object programs. To create an executable program, the object program must be linked to the subprogram libraries it requires. The executable program may then be loaded into memory and run.

 

            The steps required to compile, link and run a program is illustrated by figure.



A compiler or interpreter is itself a computer program that accepts a high level program as input and generates a corresponding machine language program as output. The original high level program is called the source program and the resulting machine language program is called the object program. Every high level language must have its own compiler or interpreter for a particular computer.

 Algorithms and Flowcharts

 

            Algorithms:

 

            An algorithm is a finite set f instruction that, if followed, accomplishes a particular task. An algorithm is composed of a finite set of steps, each of which may require one or more operations.

 

            1. Making tea

            2. Find biggest no. between three.

 

 

Flowcharts:

 

            A flowchart is a step by step pictorial representation of the logic paths contained within a computer program, and flow charting is the technique of drawing flowchart.

            Flowchart helps a person to understand at a glance the sequence of steps necessary to solve a given problems. A flowchart indicates direction of flow of a process. Flowchart can be system or program.

 

 

Advantages of using flowchart

 

1.     They are brief and to the point.

2.     They express clearly the logic of a given procedure.

3.     They are unambiguous as there can be only one direction.

4.     Flowcharts may be used as working models in the design of new programs and systems.

5.     Flowchart provides valuable information which cannot be expressed by words.

 

Disadvantages

1.     Complex and detailed charts can be laborious to plan.

2.     Drawing and following the actions to be taken in specified situations can be difficult when many decision paths are involved.

3.     The translation of flowchart into computer programs is not easy.

4.     It takes a long time to draw.



This symbol is used for decision making and therefore known as decision box. A decision box may contain a single question and the answer may be “yes” or “no” and depending on the answer the computer will follow the further path.



Some examples on algorithm and flowchart

 

Finding largest of 3 numbers

Algorithm

a.      Input the three numbers

A, B, C

b. Compare A with B

c. If A>B

Then, B is largest

Otherwise

Compare A with C

d. If A<C

C is largest

Otherwise

A is largest


Program Development Life Cycle

 

Problem Analysis

            The first stage of program development phase is problem analysis. That means, before taking any action, we have analyze the nature and types of the problems. This phase consists of identifying main purpose of the program. For that, we should carefully decide:

            What kind of data will go in,

What kind of outputs are needed and

What are the constraints and conditions under which the program has to operate

In this phase we should define how the problem is solved what actions should be performed in each phase. Before carrying to a conclusion, we must fully understand the nature of the problem and what we want the program to do.

 

Program Design

            After problem analysis, program design phase begin which is the foundation for a good program and is therefore an important part of the program development life cycle. Program design is to write the instruction code to produce desired output or to solve the problem. Despite, it is not good idea to sit to write code at once. It is very complicated job and may take lot of time than estimated to complete, if not taken proper plan.

 

Coding

            After designing, the problems must be translated into a set of instructions that a computer can understand. The process of converting the problems into the program code is called coding. The major emphasis in coding should be simplicity and clarity. Complex logic and tricky coding should be avoided. The elements of coding style include internal documentation, construction of statements, generality of the program and input/output formats.

 

Compilation and Execution

            When the program coding phase ends, the compilation phase begins, It is the process of converting the source program into the object code. For this purpose, interpreter and compiler are used. C language was developed with compilation in mind. An interpreter reads the source code of the program one line at a time, performing the specific instructions contained in that line. A compiler whereas read the entire program and converts it into the object code, which is the translation of the program’s source code into a form that the computer can execute directly. The compilation keys in C are Alt+F9 or select compilation from the menu to compile any new program.

 

Testing and Debugging

            Testing refers to the task of detecting logical mistakes called bugs, in a program so that the program produces the desired result on all occasions. Despite of every care taken one can’t be assured of the perfect ness of the program i.e. 100% error free. Necessary to make efforts to detect, isolate and correct any errors that are likely to be present in the program. Debugging is the process of isolating and execution the bugs.

 

Documentation

            It refers to the details that describe a program. It is final report of the whole program development phase. It consists of detail about what activity has been performed and problems faced in each phase. Generally, it is prepared for the future references.

 

 

 

History of C Language

 

By 1960, many programming language came into existence but each for specific purposes. For e.g. COBOL was being created for commercial purposes,

·       FORTRAN for engineering and scientific applications.

·       International Committee was set up to develop such language.

·       CPL was developed at Cambridge University and turned out to be so big with many features and is hard to learn and implement.

·       BCPL developed by Martin Richards developed by bringing good features. At same time, a language called B was written by Ken Thompson at AT and T Bell Labs. But like BCPL it became too specific.

Ritchie inherited the features of B and BCPL and also add some of his own and developed C.

C was created by Dennis Ritchie at the Bell Telephone Lab in 1972.

The ANSI formed a committee in 1983 to establish a standard definition of C.

 

Introduction to C

 

It is a general purpose high level programming language. In C, program can be broken down into small modules. Hence, it is called structured programming language.

Though there are many high level languages, many computer professionals feel that C is at the top of the list.

·       Flexible to use as system programming as well as application programming.

·       Huge collection of operators and library functions.

·       C is a portable language.

·       C is a language of few words, containing only a handful of terms, called keywords (reserved words).

·       User can create own user defined functions.

·       C is a machine independent.

·       It is low level and high level support.

·       It is only as few as 32 keywords.

Structure of a C program

 

In English Language:

 

Alphabets-> Words->Sentences->Paragraph

 

In C,

Alphabets, Digits and Symbols   Constants, Variables, Keywords Instruction Program

 

Every C program consists of one or more functions, one of which must be called main. The program will always begin by executing the ‘main’ function.

 

 

Each function must contain:

  • A function heading, consisting function name and arguments enclosed in parenthesis.
  • A pair of compound statement {curly braces}.
  • It may consist of number of input/output statements.
  • Library file access) include directive)
  • Comments

 

 

  1. Header file Section(Link Section)
  2. Documentation Section
  3. Definition Section
  4. Declaration Section
  5. Function main()
  6. Subprograms or User-defined section

 

1. Header files Section

            It provides instruction to the compiler to link functions from the system library. Each header file has extensions .h. e.g. #include<stdio.h>

 

2. Documentation Section

            This section consists of a set of comment lines giving the name of program and other details of program.

            /*………*/

3. Definition Section

            This section defines “Symbolic constant”.

            #Define PI 3.14

4. Declaration Section (Global)

            This section declares some variables that are used in more than one function. These variables are known as global variables. This section must be declared outside of the function.

5. Function main ()

            The execution of the program always begins with main ().

6. Subprograms or user-defined section.

 

 

 

General format looks like

            Documentation section

            Header file section

            Definition section

            Declaration section

Main function section

{

Declaration part

Executable part

}

 

Program 1.

/* program to print hello */    Comment

#include <stdio.h>                  Library file access

main()                                     Call of main function

{                                              Compound statement start

printf (“hello”);                      output statement

}                                              compound statement end

 

Note: Save this file or Hello.c in your directory

 

Hello.c-------compile-------à Hello.obj-----run----àhello.exe

  Full Width

 



Post a Comment

0 Comments