Вы находитесь на странице: 1из 9

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<<coutEnter 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. Information hiding, abstraction,
classes, function overloading etc. but it does not implement inheritance and thereby
polymorphism as polymorphism requires inheritance for its implementation.

(There are 3 programming paradigms: Procedural programming, object based programming


and object oriented programming.)

(Procedural programming paradigms separates the functions and the data manipulated by
them. Object oriented programming combine both data and the functions that operate on
that data under a single unit.)

OOP CONCEPTS:-
Suppose we have to prepare lot of dishes eg cake, biscuits, dhokla etc. we have to write
program s for it. In procedural programming we have to write separate program for each
recipe. Ovens are used to make a lot of different dishes. So we have to write separate program
of oven for each recipe. But in OOP provide us the facility of reusing the data through objects.
For oven we have to write the program only once. Whenever oven is required we can access
through object. The OOP approach is based on certain concepts :-

a)Data Abstraction:- Abstraction means representing the essential features without including
the background details. OOP provide us the facility of data abstraction. 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. Eg. 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.

b)Data Encapsulation: Encapsulations means wrapping up of data and functions (that operate
on the data) into a single unit through class. The data is accessed through functions. These
functions are called member functions. The data cannot be accessed directly. For reading the
data we have to call the member functions using objects. The data is hidden so it is safe from
accidental alternation. 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. IT
reduces the complexity and created a number of well-defined, documented boundaries within
program. C++ has its own library. The inbuilt functions can be called with file name and .h
suffix. These files can be accessed by using #include. Suppose there is a large organization
having different department. Each department can be divided into different module like
payroll, sales deptt., purchase deptt, advertisement deptt. Etc.

d) Inheritance: It is the process of creating a new class/classes from the existing class/classes.
The existing class is called the base class and the new class is called the derived class. For eg.
Automobiles is class having cars, buses and scooters all having common properties i.e
enginees, wheels, horns etc. In addition to the features of the base class the subclasses having
their own features i.e. scooters use petrol and buses use diesel. AN important feature of object
oriented programming i.e., inheritance provides reusability. We can use an existing class and
without changing it, can add extra features and capability to it. This is achieved by deriving a
new class from an existing class.

e) Polymorphism: Polymorphism is derived from two words poly means many and morphos
means forms. The message or data can be processed in more than one form using this
concept. The functions are used in different ways, depending on what they are operating on.

SHAPE
area()

circle Triangle
area(circle) area(triangle)

(polymorphism)
Following program illustrates the concept of polymorphism using function overloading:-

#include<iostream.h>
#include<stdlib.h>
void amount(float princ, int time=2, float rate=0.8); //prototype
void amount(float princ, int time, float rate)
{
cout<<\n Principal Amount :<<princ;
cout<<\n Time :<<time;
cout<<\n Rate of Interest <<rate;
}
void main()
{
system(cls);
cout<<Case 1;
amount(2000);
cout<<case2;
Amout(2500,3);
cout<<Case 3;
amount(2300,3,0.11);
cout<<Case 4 :;
amout(2500,0,12);
}

Importance of OOPs:-
1. Redundancy can be removed by inheritance and the existing code can be used again.
2. Classes provides a great help to the user.
3. Development time is saved and productivity is increased as we can code programs from
standard working modules that communicate with each other.
4. Data hiding saves the code from accidental alternation.
5. Any problem based on objects can be easily divided and coded.
6. Management of complex software is done with ease.

**************************************************************************
STRUCTURED QUERY LANGAUAGE (SQL)
a) Create Table:-
Syntax: Create Table <table name> (<column name>) <data type> [<size>];
Eg. Create Table Employee
( Emp No Number (3),
Ename Varchar2(30),
Hire-date Date,
Salary Number(7,2));

Constraints at table level:-


1) NOT NULL 2) UNIQUE 3) PRIMARY KEY 4) FOREIGN KEY 5) CHECK

At column level:-

Eg.1) Create Table Student


( Name Varchar(25) Not Null,
Class Number (2));

At Table level:-

Eg.2) Create Table Student


( Rollno number(3),
Name Varchar(25) Not Null,
Class Number (2)
Unique (rollno));

PRIMARY KEY- At Column Level

SQL> Create Table Student


(Rollno number(3) Primary Key,
Name Varchar2(25),
Class Number (2));

PRIMARY KEY- At Table Level


SQL> Create Table Student
(Rollno number(3),
Name Varchar2(25),
Class Number (2)
Primary Key (name,class));

FOREIGN KEY:-
At column level:-
SQL> Create Table Employee
(Empno Number (3),
Salary Number(7,2),
Deptno Number(2) References Department (Deptno));

At Table Level:

Create Table Employee


( Empno Number(3),
Salary Number(7,2),
Deptno Number(2)
Foreign Key (Deptno) References Department(Deptno));

Check Constraints:-

Create Table Employee


(Empno Number(3),
Salary Number(8,2) Check(Salary>0));

Create View:-
Syntax:
Create View <View Name>
As Select <Column List> From <Table Name> [<Where Condition>];

Eg. SQL> Create View Empview


As Select Empno, Ename, Job from Employee;

SQL> Select * From Empview;


Above command will retrieve data from employee table which is base table for empview.
View contains nodata of its own.

Drop Table:- Drop table not only delete the data but also removes the definition of its
structure.
Eg. Drop Table<table name>;
Eg SQL> Drop table employee;
Drop View:-
Syntax: Drop view <view name>;
Eg. Drop View Empview;

Alter Table:-
a) Adding column:-
Syntax: Alter Table <table name>
Add <column name> <data type> [constraints];
Eg. SQL> Alter Table Student
Add Grade char(1);
OR
Alter Table <Student>
Add Percentage Number(3) Check Percentage<=100;

b) Changing Columns Definition:-


Syntax: Alter Table<table name>
Modify <Column name> <data type> [size];
Eg Alter Table Student
Modify salary number(8,2);

c) Dropping a Column from a table:-

Syntax: Alter Table<Table Name>


Drop Column <column name>;
Eg. Alter Table Student
Drop Column Grade;

(Data Manipulation Language (DML))


1) Update:-
Syntax: Update <Table name> set <Column Name=value>,<column name=value>[<where
condition>];
Eg:-
a) Update single row and single column:-
SQL> Update Sports
Set marks = 65
Where ROllno= 12;

b) Updating multiple rows and single column:-


SQL> Update Sports
Set Grade = A;
Above command will replace grade column by A
Note:- Char Type data value must be enclosed in single quote.

c) Updating Multiple Columns and Single row:-


To change the game to cricket and class to 8 of students with roll no 13, the SQL command
will be:-
SQL> Update Sports
Set class=8, Game = Cricket
Where Rollno=13;
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, Marks=marks+10;
Where Game= Tennis;
5) Setting columns values to NULL:-
To set the grade of all students to NULL,
SQL>UPDATE SPORTS SET GRDAES = NULL;
Note: - though the column grade is of CHAR data type, NULL is not enclosed in single quotes.

Вам также может понравиться