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 abstraction
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
a. 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
User – Defined Data Types:
Structures:
A structure is a collection of simple variables. The variables in a structure can be of different types, some can be int, some can be float, and so on. The data items in a structure are called the members of the structure.
Ex:
Struct part
{
int partno;
float cost;
}s1;
Union:
A union is similar to a struct, except it allows you to define variables that share storage space.
Ex:
Union part
{
int a;
long b;
} p1;
Enumerated Data Type:
An enumerated data type is another user – defined type which provides a way for attaching names to numbers, thereby increasing comprehensibility of the code.
Syntax;
Enum user-define-name { valu1, value2,…valuen};
Ex:
Enum color { rose=10, pink, blue=30, white};
Structure in c++
Include file
Class definition
Data declaration
Member function definition
Main function
Object declaration
Body of main function
#include
class stu ……………class defintion
{
private: ………………visibility modifier
int x,y; …………….data declaration
public:
void read() …………….member function
{
cout<<”enter the val”;
cin>>x>>y;
}
void print()
{
cout<<”x=”<
};
void main() …………….main function
{
stu a; …………..data(object) declaration
a.read(); ……….called member function
a.print();
}
Control structures
A large number of functions are used that pass messages, and process the data contained in objects. A function is set up to perform a task. When the task is complex, many different algorithms can be designed to achieve the same goal. Some are simple to comprehend, while others are not.
1.Decision making (or) conditional statement
2.Looping statement
Decision making statement
• DMS are used to skip or to execute a group of statements based on the result of some condition.
• The decision making statements are,
• (i) simple if statement
• (ii) if…else statement
• (iii) switch statement
Simple if statement:
• Simple if statement is used to execute or skip one statement or group of statements for a particular condition.
• The general form is
• If(test condition)
{
– Statement block;
}
Next statement;
When this statement is executed, the computer first evaluates the value of the test condition. If the value is true, statement block and next statement are executed sequentially. If the value is false, statement block is skipped and execution starts from next statement.
Example:
• #include
• #include
• Void main()
• {
– Int mark;
– Char grade;
– Clrscr();
– Cin>>mark>>grade;
–
– If(grade= =‘a’)
– {
– Mark=mark+10;
– }
–
– Cout<– Getch( );
}
(ii) if …else statement
if..else statement is used to execute one group of statements if the test condition is true or other group if the test condition is false
The gentral form
If(test condition)
{
statement block-1;
}
else
{
statement block-2;
}
next statement;
when this statement is executed, the computer first evaluates the value of the test condition. If the value is true, statement block-1 is executed and the control is transferred to next statement. If the value is false, statement block-2 is executed and the control is transferred to next statement.
Ex:
#include
#include
void main()
{
int mark;
clrscr();
cin>>mark;
if(mark=>35)
cout<<”pass";
else
cout<<”fail”;
getch();
}
(iii) Switch statement;
Switch case is used for multiple branching. The switch statement checks the value of an expression against a list of integer or character constants. When match found, the statements associated with that constant are executed. If no match found the statements under default section are executed.
Switch(expression)
{
case label-1:
statement block-1;
break;
case label-2:
statement block-2;
break;
case label-3:
statement block-3;
break;
……………………………………….
………………………………………
case label-n:
statement block-n;
break;
default:
default statement;
break;
}
next statement
ex:
#include
#include
void main()
{
int day;
cout<<”enter the number is 1 to 7”;
cin>>day;
switch(day)
{
case 1:
cout<<”Sunday”;
break;
case 2:
cout<<”Monday”;
break;
case 3:
cout<<”Tuesday”;
break;
case 4:
cout<<”Wednesday”;
break;
case 5:
cout<<”Thursday”;
break;
case 6:
cout<<”Friday”;
break;
case 7:
cout<<”Saturday”;
break;
default:
cout<<”Enter the current val”;
break;
}
}
No comments:
Post a Comment