Sunday, April 12, 2009

Introduction to C++

INTRODUCTION TO C++
OBJECT ORIENTED PROGRAMMING:

Object oriented program development is a new programming style having real world thinking. It is not a programming technique. So each and every programmer has his own way of thinking.

1. object
2. class`
3. data abstracation
4. data encapsulation
5. inheritance
6. polymorphism
7. dynamic binding
8. message passing

Object:
An object is defined as an entity that contain data and its related functions. The functions operate on that data. The objects may be either physical or logical.

Class:
A class is defined as a collection of objects with same type of data and functions. The functions of the class should be defined. With the help of the class we can create number of objects of type class.

Data abstraction:
Abstraction is defined as a grouping of essential details and ignoring other details. Data abstraction is defined as a named collection of data that describes a data object in a class

Data encapsulation:
Encapsulation is a technique used to protect the informations in an object from other objects. In an object data and its functions are encapsulated into a single entity. Because of this other objects and programs cannot aces the data in an object directly. This concept is called data encapsulation or data hiding

Inheritance:
Inheritance is defined as sharing of attributes and functions among classes based on a hierarchical or sequential relationship
Main class or supper class
Derived class or sub class

Polymorphism:
A function is said to be polymorphic, if it is applied to many different classes with different operation.

Dynamic binding:
Binding is defined as the connection between the function call and its corresponding program code to be executed. There are 2 types of binding
1. static binding
2. dynamic binding

Static binding: the binding occurs during compilation time
Dynamic binding: the binding occurs during run time. This is also called late binding.

Message passing:
Message passing is a process of locating and executing a function in response to a message. Locating means matching the given message with the list of available functions.

Benefits of OPP:

1. Reusability
2. Code sharing
3. Data hiding
4. Reduced Complexity of a problem
5. Prototyping
6. Message passing technique
7. Extendibility

Resuability:
In OOP’S, programs, functions, modules written by a user can be reused by other users without any modification.

Code sharing:
In OOP’S, the programmer can share the codes which are common to more than one class by defining it in the parent classes in hierarchical order.

Data hiding:
In OOP’S, the programmer can hide data and functions in a class from other classes.

Reduced complexity of a problem:
In OOP’S the given problem is viewed as a collection of different objects. Each object is responsible for a specific task. The problem is solved by interfacing the objects. This tehnique reduces the complexity of the program design.

Prototyping:
In OOP’S, software system can be developed more quickly and easily by using the existing defined components. This technique of development is called prototyping

Message passing technique:
This technique reduces the complexity of interfacing two objects.

Expendability:
Object oriented software can be easily extended from small to large

Application of OOP:
1. real-time systems
2. object-oriented databases
3. simulation and modeling
4. AI and expert systems
5. hypertext, hypermedia and expert text
6. neural networks and parallel programming
7. decision support and office automation systems
8. CAD/CAM systems


Object Oriented Programming Languages:

Language that support these features include
1. object PASCAL
2. c++
3. small task
4. Eiffel
5. java
6. CLOS(Common Lisp Object system)
7. A d a

These language can be classified into 2 groups
i. object-oriented programming language
ii. object-based programming language

object oriented programming languages are languages which supports all OOP concepts. Object-oriented programming incorporates all object-based programming features along with two additional features, namely, inheritance and dynamic binding. Oop can therefore be characterized by the following statement:

Object-based features + inheritance + dynamic binding

Ex:
C++, small talk, object PASCAL

Object-based programming languages are languages which supports all OOP concepts except inheritance and dynamic binding. Object-based programming is the style of programming that primarily supports encapsulation and object identity. Major features that are required for object-based programming are:

Data encapsulation
Data hiding and access mechanisms
Automatic initialization and clear-up of objects
Operator overloading

Ex:
Ada

Procedure oriented Programming:

In this type of programming, the given problem is divided into number of sub-problems is defined as a function or procedure. The total problem can be viewed as a collection of functions or procedures.

Features:
1. large problems are divided into smaller problems known as functions or procedures
2. it uses top-down programming technique
3. data moves freely from one function to another
4. functions can share global variables.
5. data hiding is not possible
6. it is difficult to add new functions and data structures

Object oriented programming:
In this type of programming, the given problem is divided into a number of entities called objects. The related functions, data and its structures are all defined inside the objects. The data inside the objects are called attributes and the related functions are called operations. The data of an object can be accessed only by the function associated with that object. Finally all the objects are interfaced to solve the problem

Features:
1. problems are divided into objects.
2. it is not possible to access data freely
3. data hiding is possible
4. it uses bottom-up programming technique
5. it is easy to add new data and functions
6. objects can exchange data through its function

Wednesday, July 2, 2008

Introduction to C

C LANGUAGE

Introduction:
‘C’ is an efficient and portable general purpose programming language. It was developed in the year 1972 at Bell telephone laboratories (AT&T) by DENNIS RITCHIE.

Features of ‘C’ language:
it is a flexible high level structured program language
it includes the features of low level language like assembly language.
it is much faster and efficient.
it has a number of built-in functions, which makes the programming task simple

The ‘C’ language is used for developing:
Database system.
graphics packages.
scientific and engineering applications.

Format of C program:

Headerfile include
Main()
{
variable declaration;
program statements;
}

Ex:
\* c program using printf *\
#include
main()
{
printf(“god is great”);
}

Keywords:
Keywords are words belong to C language. The users have no right to change its meaning. Keywords also referred, as reserved words are words whose meaning has been already defined in the C compiler. All keywords have fixed meanings and their meanings cannot be changed.

Ex:
auto, goto, if, int, while, do, switch, case, char, else…..

Data type:
The data types supported in a language dictates the type of values, which can be processed by the programming language. C language is rich in its data types. It supports a wide variety of data types each of which may be represented differently within the computer’s memory.

TYPE                       SIZE (bits)             RANGE

Char                         8                          128 to 127

Unsigned char        8                           0 to 255

int                            16                         32,768 to 32,767

Unsigned int           16                         0 to 65,535

Long int                  32                        2,147,483,648 to2,147,483,647

unsigned long int  32                        0 to 4,294,967,295

float                        32                        3,4E-38 to 3,4E+38

double                    64                       1.7E-308 to 1.7E+308

long double            80                        3.4E-4932 to 1.1E+4932


Variables:
C variable refers to the name given to the memory location to store data. A particular memory location is given only one name. Yet this name is called a variable because this memory location can store sequence of different values during the execution of the same program.

Rules:
1) variable name is formed with alphabets, digits and a special character underscore( _ )
2) the first character must be an alphabet.
3) no special characters are used other than underscore
4) both upper case and lower case letters are used.

Declaration variables:
Syntax:
Data-type     list of variables;
Ex:
int x,y,z;

Initializing variables:
syntax:
data-type variable=initial value;
Ex:
int a=10;
float b=43.3;