OBJECT ORIENTED PROGRAMMING

The object oriented programming has been developed with a view to overcome the drawbacks
of conventional programming approaches. In structured or procedural programming a given
problem was divided into sub problems. Then each of these sub problems were further divided
and so on. Each sub-problem code is called a procedure or function.

Drawbacks of procedural programming:-

For eg if program is using following structure:-

struct student {
Int roll no;
Char name[25];
Int class;
And the functions in the program use and manipulate the this structure eq
void student(student s1)
{
cout<<”Enter roll no”;
cin>>s1.rollno;
cout<<”enter name”;
gets(name);
cout<<cout”Enter class”;
cin>>Clas;
Now suppose that due to change in the design the student structure has to hold marks and
grade as well i.e. structure modifies to:
ctruct student
{
int rollno;
char name[25];
int clas;
float marks;
char grade;
};
Now all the functions working on structure must also be modified to cope with the change in
structure. Thus readstudent() needs to be rewritten. Similarly, if five other functions are using
or manipulating student in one or other way, they must also be modified. SO it become a time
consuming and difficult task.

Object Based Programming:- The Object based programming is subset of object oriented programming as it also implements some of the features of object oriented programming eg. IT reduces the complexity and created a number of well-defined. Information hiding. Ovens are used to make a lot of different dishes. but it does not implement inheritance and thereby polymorphism as polymorphism requires inheritance for its implementation. classes.Abstraction means representing the essential features without including the background details. C++ has its own library. Object oriented programming combine both data and the functions that operate on that data under a single unit. For eg On a Switch Board we only press the switch according to our requirement ignoring the internal detail about the structure of the switch board. So we have to write separate program of oven for each recipe. For reading the data we have to call the member functions using objects. documented boundaries within program. b)Data Encapsulation: Encapsulations means wrapping up of data and functions (that operate on the data) into a single unit through class. function overloading etc. biscuits. The data cannot be accessed directly. abstraction. we have to write program s for it. Whenever oven is required we can access through object. The data is accessed through functions. OOP provide us the facility of data abstraction. But in OOP provide us the facility of reusing the data through objects. Data and its functions are said to be encapsulated into a single entity called class. c) Modularity: The act of dividing a program into individual components is called modularity. In procedural programming we have to write separate program for each recipe. For oven we have to write the program only once. if we have to calculate the area of square if have to call the function related to area of square and pass the value of radius without going in detail.) OOP CONCEPTS:- Suppose we have to prepare lot of dishes eg cake.h . The data is hidden so it is safe from accidental alternation. (There are 3 programming paradigms: Procedural programming.) (Procedural programming paradigms separates the functions and the data manipulated by them. object based programming and object oriented programming. The OOP approach is based on certain concepts :- a)Data Abstraction:. The inbuilt functions can be called with file name and . dhokla etc. Eg. These functions are called member functions.

. advertisement deptt. horns etc. The message or data can be processed in more than one form using this concept. We can use an existing class and without changing it. The existing class is called the base class and the new class is called the derived class. Etc. . float rate=0. buses and scooters all having common properties i. These files can be accessed by using #include. e) Polymorphism: Polymorphism is derived from two words poly means many and morphos means forms. int time. d) Inheritance: It is the process of creating a new class/classes from the existing class/classes. int time=2. Automobiles is class having cars. This is achieved by deriving a new class from an existing class.. purchase deptt. can add extra features and capability to it. AN important feature of object oriented programming i. //prototype void amount(float princ. In addition to the features of the base class the subclasses having their own features i. inheritance provides reusability.8). The functions are used in different ways.suffix.e. float rate) { cout<<”\n Principal Amount :”<<princ. For eg. wheels. Suppose there is a large organization having different department.h> #include<stdlib. depending on what they are operating on. scooters use petrol and buses use diesel. sales deptt.e enginees. SHAPE area() circle Triangle area(circle) area(triangle) (polymorphism) Following program illustrates the concept of polymorphism using function overloading:- #include<iostream. Each department can be divided into different module like payroll.h> void amount(float princ.e.

3.3). amout(2500. 6.0.0. cout<<”Case 3”. ************************************************************************** . Amout(2500. cout<<”Case 4 :”. Data hiding saves the code from accidental alternation. 5. 3. 2.cout<<”\n Time :”<<time. } void main() { system(“cls”). Classes provides a great help to the user. cout<<”\n Rate of Interest “<<rate. Development time is saved and productivity is increased as we can code programs from standard working modules that communicate with each other. cout<<”case2”. amount(2000). cout<<”Case 1”. Redundancy can be removed by inheritance and the existing code can be used again. } Importance of OOPs:- 1. 4. amount(2300.11). Management of complex software is done with ease.12). Any problem based on objects can be easily divided and coded.

Constraints at table level:- 1) NOT NULL 2) UNIQUE 3) PRIMARY KEY 4) FOREIGN KEY 5) CHECK At column level:- Eg. PRIMARY KEY.2)). Hire-date Date. Name Varchar2(25). At Table level:- Eg.2) Create Table Student ( Rollno number(3).At Column Level SQL> Create Table Student (Rollno number(3) Primary Key. Name Varchar(25) Not Null. Salary Number(7.At Table Level . Create Table Employee ( Emp No Number (3). Class Number (2)). Class Number (2)). Eg.1) Create Table Student ( Name Varchar(25) Not Null. STRUCTURED QUERY LANGAUAGE (SQL) a) Create Table:- Syntax: Create Table <table name> (<column name>) <data type> [<size>]. PRIMARY KEY. Ename Varchar2(30). Class Number (2) Unique (rollno)).

SQL> Create Table Student (Rollno number(3). . SQL> Select * From Empview. Salary Number(7. FOREIGN KEY:- At column level:- SQL> Create Table Employee (Empno Number (3). Ename. Class Number (2) Primary Key (name. Create View:- Syntax: Create View <View Name> As Select <Column List> From <Table Name> [<Where Condition>]. Deptno Number(2) References Department (Deptno)). Deptno Number(2) Foreign Key (Deptno) References Department(Deptno)). Salary Number(7. Name Varchar2(25).2) Check(Salary>0)). Salary Number(8.class)). Eg. Job from Employee. At Table Level: Create Table Employee ( Empno Number(3). SQL> Create View Empview As Select Empno.2). Check Constraints:- Create Table Employee (Empno Number(3).2).

2). b) Changing Columns Definition:- Syntax: Alter Table<table name> Modify <Column name> <data type> [size]. Eg SQL> Drop table employee. View contains nodata of its own. Eg. c) Dropping a Column from a table:- Syntax: Alter Table<Table Name> Drop Column <column name>. Eg. SQL> Alter Table Student Add Grade char(1). Eg. Alter Table Student Drop Column Grade. Drop View:- Syntax: Drop view <view name>.Above command will retrieve data from employee table which is base table for empview. Eg Alter Table Student Modify salary number(8. Drop View Empview. OR Alter Table <Student> Add Percentage Number(3) Check Percentage<=100. (Data Manipulation Language (DML)) 1) Update:- . Alter Table:- a) Adding column:- Syntax: Alter Table <table name> Add <column name> <data type> [constraints]. Drop Table<table name>.Drop table not only delete the data but also removes the definition of its structure. Eg. Drop Table:.

5) Setting columns values to NULL:- To set the grade of all students to NULL.Char Type data value must be enclosed in single quote.though the column grade is of CHAR data type. the SQL command will be:- SQL> Update Sports Set class=8. Eg:- a) Update single row and single column:- SQL> Update Sports Set marks = 65 Where ROllno= 12. Marks=marks+10. 4) Updating Multiple columns and Multiple row:- Eg: TO increase marks by 10 and changing the grade to A of all the students who play Tennis SQL Command is:- SQL> Update Sports Set Grade = ‘A’. . Note: . NULL is not enclosed in single quotes. SQL>UPDATE SPORTS SET GRDAES = NULL. Above command will replace grade column by A Note:. b) Updating multiple rows and single column:- SQL> Update Sports Set Grade = ‘A’.<column name=value>[<where condition>]. Where Game= ‘Tennis’.Syntax: Update <Table name> set <Column Name=value>. Game = ‘Cricket’ Where Rollno=13. c) Updating Multiple Columns and Single row:- To change the game to cricket and class to 8 of students with roll no 13.