COMPUTER SCIENCE ENGINEERING
LAB MANUAL
IV SEM
OBJECT ORIENTED TECHNOLOGY (IT 303)
)
INDEX
1. Syllabus
2. Rational behind the OOPS Lab
3. Hardware/Software Requirement
4. Practical List
5. Practical conducted in the lab
6. References
7. Viva Question
SYLLABUS
Unit I
Introduction, Object Oriented Programming Concepts, Flow chart, Objects,
Objects as software modules, Objects interaction, Classes, Method lookup,
Hierarchies of classes, Inheritance, Polymorphism, Abstract classes.
Unit II
Identifying objects and classes, Representation of objects, Modeling, objects
and classes, Relationships. Association between objects, aggregate components
of objects. Storage Management :Memory allocation, Dynamic allocation.
Unit III
Object oriented programming languages, Class declarations, Object
declarations, Mandatory profiles, Message sending, Association, Recursive
association, Many to many association, Argument passing.
Unit IV
Inherited methods, Redefined methods, The protected interface, Abstract base
classes, Public and protected properties, Private operations, Disinheritance,
Multiple inheritance.
Unit V
Study of C++ as object oriented programming language.
Rational Behind Object-Oriented Programming
Object-oriented programming (OOP) is a programming paradigm that uses
abstraction to create models based on the real world. It utilizes several
techniques from previously established paradigms, including modularity,
polymorphism, and encapsulation. Even though it originated in the 1960s, OOP
was not commonly used in mainstream software application development until
the 1990s. Today, many popular programming languages (such as Java,
JavaScript, C#, C++, Python) support OOP.
Object-oriented programming's roots reach all the way back to the
creation of the Simula programming language in the 1960s, when the
nascent field of software engineering had begun to discuss the idea of a
software crisis. As hardware and software became increasingly complex, how
could software quality is being maintained? Object- oriented programming in
part addresses this problem by strongly emphasizing modularity in software.
Object-oriented programming may be seen as a collection of cooperating
objects, as opposed to a traditional view in which a program may be seen
as a collection of functions, or simply as a list of instructions to the
computer. In OOP, each object is capable of receiving messages, processing
data, and sending messages to other objects. Each object can be viewed as an
independent little machine with a distinct role or responsibility.
Object-oriented programming is intended to promote greater flexibility and
maintainability in programming, and is widely popular in large-scale
software engineering. By virtue of its strong emphasis on modularity, object
oriented code is intended to be simpler to develop and easier to understand later
on, lending itself to more direct analysis, coding, and understanding of complex
situations and procedures than less modular programming methods.
HARDWARE & SOFTWARE
REQUIREMENT:
HARDWARE REQUIREMENT
• PENTIUM I (200 GHZ)
• 128 MB RAM
• 20 GB HDD
SOFTWARE REQUIREMENT
• WINDOWS 9x or above
• Language C ++
SNO. Practical List
1 Write a program to add, subtracts, multiply and divide two numbers using concepts
of C++.
2 Write a program to showswapping oftwo numbers using C++.
3 Write a program to swapping oftwo number without including third variable
4 Write a program to calculate volume ofcube, cylinder, rectangular box using three
times function overloading in C++.
5 Write a program using virtual function.
6 Write a program to describe constructor.
7 Write a program to describe destructor.
8 Write a program using copy constructor.
9 Write a program PAYROLL SYSTEM USING SINGLE INHERITANCE
10 Write a program o showmultiple inheritances.
11 Write a program to find mean value oftwo numbers using friend function.
12 Write a program using inline function.
13 Write a program to demonstrate the use ofLocal Object,Static Object & Global
Object using C ++.
14 Write a program in C++ to demonstrate the creation and the use ofdynamic object.
15 Write a program to Create two classesDM and DB which store the value of
distances
16 Write a program to Derive the two classes son and daughter and, demonstrate
polymorphism in action.
17 Write a program to Create a base class called shape. Use this class to store two
double t type value that could be used to compute the area offigures.
EXPERIMENT:1
Write a program to add, subtract, multiply and divide two numbers using concepts of
C++.
#include<iostream.h>
#include<conio.h>
class math
{
float a,b;
public:
void getval()
{
cout<<"nnEnter two values ";
cin>>a>>b;
cout<<"nyou enter a="<<a;
cout<<"nyou enter b="<<b;
}
void add()
{
cout<<"nnADDITION is "<<a+b;
}
void sub()
{
cout<<"nn SUBSTRACTION is "<<a-b;
}
void mult()
{
cout<<"nn MULTIPLICATION is "<<a*b;
}
void div()
{
cout<<"nn DIVISION is "<<a/b;
}
};
void main()
{
int i,t;
clrscr();
class math obj;
obj.getval();
cout<<"nn************************************************";
cout<<"nnFor Addtion press --> 1";
cout<<"nnFor Substration press --> 2";
cout<<"nnFor Multiplication press --> 3";
cout<<"nnFor Division press --> 4";
cout<<"nn************************************************";
cout<<"nnnplesae enter value ";
while(t==0){
cin>>i;
cout<<"nn-----------------------------------------------";
switch(i)
{
case 1:
obj.add();
break;
case 2:
obj.sub();
break;
case 3:
obj.mult();
break;
case 4:
obj.div();
break;
default:
cout<<"nnWrong choise";
}
cout<<"nnfor Exit press any key or want more operation press 0 --> ";
cin >>t;
if(t==0)
cout<<"nSelect new operarion ";
}
getch();
}
OUTPUT:
Enter two values 3 5
you enter a 3
you enter a 5
************************************************
For Addtion press --> 1
For Substration press --> 2
For Multiplication press --> 3
For Division press --> 4
************************************************";
plesae enter value 1
QUESTIONS PROGRAM ONE
1) What is C++?
2) What is the difference between declaration and definition?
3) Write a program that ask for user input from 5 to 9 then calculate the average?
EXPERIMENT :2
Write a program to show swapping of two numbers using C++.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a: ";
cin>>a;
cout<<"Enter b: ";
cin>>b;
cout<<"Before swapping:"<<endl;
cout<<"a: "<<a<<" b: "<<b<<endl;
c=a;
a=b;
b=c;
cout<<"After swapping:"<<endl;
cout<<"a: "<<a<<" b: "<<b;
getch();
}
OUTPUT:
Enter a: 3
Enter b: 5
Before swapping a:3 b:5
after swapping a:5 b:3
QUESTIONS PROGRAM TWO
1. Code for swapping of two numbers without using temporary variable using C
2. What is the difference between Swapping and Paging?
3. What are the criteria for choosing a process for swapping into memory from the swap
device
EXPERIMENT 3
write a program to swapping of two numbers without including third variable.
#include<conio.h>
#include <iostream.h>
class swapping
{
int a,b;
public :
void swap()
{
cout<<"enter any two value for swapping";
cin>>a>>b;
cout<<"n Befroe swapping values of a:"<<a<<" and b:"<<b;
a=a+b;
b=a-b;
a=a-b;
cout<<"n After swapping values of a:"<<a<<" and b:"<<b;
}
};
void main()
{
clrscr();
swapping s1;//object declared
s1.swap();
getch();
}
OUTPUT:
Enter a: 3
Enter b: 5
Before swapping a: 3 b: 5
after swapping a: 5 b: 3
QUESTIONS PROGRAM THREE
1. What is the difference between Swapping and Paging?
2. Write a function to swap any two numbers?
3. Works best with many small partitions
4. Allows many programs to use memory simultaneously
EXPERIMENT:4
Write a program to calculate volume of cube, cylinder, rectangular box using three
times function overloading in C++.
#include<iostream.h>
#include<conio.h>
void main()
{
int volume(int);
long volume(double,int);
long volume(long,int,int);
int main()
{
cout<<volume(10)<<"n";
cout<<volume(2.5,8)<<'n";
cout<<volume(100,75,15)<<"n";
return 0;
}
int volume(int s)
{
return(s*s*s);
}
double volume(double r,int h)
{
return(3.14519*r*r*h);
}
long volume(long l, int b, int h)
{
return(i*b*h);
}
OUTPUT:
1000
157
112500
QUESTIONS PROGRAM FOUR
1. What is function overloading?
2. What are the need /use offunction overloading?
3. What restrictions are placed on method overloading?
EXPERIMENT :5
Write a program using virtual function.
#include<iostream.h>
#include<conio.h>
class Base
{
public:
void display() {cout<<"n Display base";}
virtual void show() {cout<<"n show base";}
};
class Derived : public Base
{
public:
void display() {cout<<"n Display derived";}
void show() {cout<<"n show derived";}
};
int main()
{
Base B;
Derived D;
Base *bptr;
cout<<"n bptr points to base |n";
bptr= &B;
bptr->display();
bptr->show();
cout<<"nn bptr points to derivedn";
bptr=&D;
bptr->display();
bptr->show();
return 0;
}
OUTPUT:
bptr points to base
Display base
show base
bptr points to derived
Display base
show derived
QUESTIONS: PROGRAM FIVE
1. What is virtual function? Explain with an example.
2. What is a virtual base class?
3. What are pure virtual functions?
EXPERIMENT:6
Write a program to describe constructor.
#include<conio.h>
#include<iostream.h>
class greatest
{ int a,b;
public :
greatest(int x,int y)
{
a=x;
b=y;
}
void show()
{
if(a>b)
cout<<"a is greatest number";
else
cout<<"b is greatest number";
}
};
void main()
{
clrscr();
greatest s1(10,20);
s1.show();
getch();
}
OUTPUT:
b is greatest number
QUESTIONS: PROGRAM SIX
1. In C++, what is a constructor?
2. What is the difference between constructor and method?
3. Why Call by reference technique is used in case of Copy constructor & not call by
value?
EXPERIMENT:7
write a program to describe destructor.
#include<conio.h>
#include<iostream.h>
class integer
{
int a,b;
public :
integer(int x,int y)
{
a=x;
b=y;
}
void add()
{
a=a+b;
}
~integer()
{
cout<<"a="<<a;
}
};
void main()
{
clrscr();
int i,j;
cout<<"enter the value i and j=";
cin>>i>>j;
integer l(i,j);
l.add();
getch();
}
OUTPUT:
enter the value i and j= 10 20
a= 30
QUESTIONS PROGRAM SEVEN
1. In C++, what is a destructor?
2. Can destructor be private?
3. What is the use ofvirtual destructor?
EXPERIMENT:8
Write a program using copy constructor.
#include<iostream.h>
#include<conio.h>
class code
{
int id;
public:
code() { }
code(int a) {id=a;}
code(code &x)
{
id=x.id;
}
void display(void)
{
cout<<id;
}
};
int main()
{
code A(100);
code B(A);
code C=A;
cout<<"n id of A:"; A.display();
cout<<"n id of B:"; B.display();
cout<<"n id of C:"; C.display();
return 0;
}
OUTPUT:
id of id of A: 100
id of id of B: 100
id of id of C: 100
QUESTIONS PROGRAM EIGHT
1. What is a COPYCONSTRUCTORand when is it called?
2. What are the differences between member function and constructor?
3. Why the constructor can’t be virtual?
EXPERIMENT:9
Write a program Payroll System Using Single Inheritance
#include<iostream.h>
#include<conio.h>
class emp
{
public:
int eno;
char name[20],des[20];
void get()
{
cout<<"Enter the employee number:";
cin>>eno;
cout<<"Enter the employee name:";
cin>>name;
cout<<"Enter the designation:";
cin>>des;
}
};
class salary:public emp
{
float bp,hra,da,pf,np;
public:
void get1()
{
cout<<"Enter the basic pay:";
cin>>bp;
cout<<"Enter the Humen Resource Allowance:";
cin>>hra;
cout<<"Enter the Dearness Allowance :";
cin>>da;
cout<<"Enter the Profitablity Fund:";
cin>>pf;
}
void calculate()
{
np=bp+hra+da-pf;
}
void display()
{
cout<<eno<<"t"<<name<<"t"<<des<<"t"<<bp<<"t"<<hra<<"t"<<da<<"t"<<pf<<"t"<<
}};
void main()
{
int i,n;
char ch;
salary s[10];
clrscr();
cout<<"Enter the number of employee:";
cin>>n;
for(i=0;i<n;i++)
{
s[i].get();
s[i].get1();
s[i].calculate();
}
cout<<"ne_no t e_namet des t bp t hra t da t pf t np n";
for(i=0;i<n;i++)
{
s[i].display();
}
getch();
}
OUTPUT:
Enter the Number of employee:1
Enter the employee No: 150
Enter the employee Name: ram
Enter the designation: Manager
Enter the basic pay: 5000
Enter the HR allowance: 1000
Enter the Dearness allowance: 500
Enter the profitability Fund: 300
E.No E.name des BP HRA DA PF NP
150 ram Manager 5000 1000 500 300 6200
QUESTIONS PROGRAM NINE
1. What do you mean by inheritance?
2. What does inheritance means in C++?
3. What are the different forms of inheritance? Give an example for each.
EXPERIMENT:10
Write a program to show multiple inheritances.
#include<iostream.h>
#include<conio.h>
class M
{
protected:
int m;
public:
void get_m(int);
};
class N
{
protected:
int n;
public:
void get_n(int);
};
class P: public M, public N
{
public:
void display(void);
};
void M::get_m(int x)
{
m=x;
}
void N::get_n(int y)
{
n=y;
}
void P::display(void)
{
cout<<"m="<<m<<"n";
cout<<"n="<<n<<"n";
cout<<"m*n="<<m*n<<"n";
}
int main()
{
P p;
p.get_m(10);
p.get_n(20);
p.display();
return 0;
}
OUTPUT:
m=10
n=20
m*n=200
QUESTIONS: PROGRAM TEN
1. Is it possible to inherit the private member in derived class?
2. Can you prevent your class from being inherited and becoming a base class for some other
classes?
3. Can you allow class to be inherited, but prevent the method from being over-ridden?
PROGRAM 11: Write a program to find mean value of two numbers using friend function.
#include<iostream.h>
#include<conio.h>
class sample
{
int a;
int b;
public:
void setvalue() {a=25; b=40;}
friend float mean(sample s);
};
float mean(sample s)
{
return float(s.a+s.b)/2.0;
}
int main()
{
sample X;
X.setvalue();
cout<<"Mean value="<<mean(X)<<"n";
return 0;
}
OUTPUT: Mean value= 32.5
QUESTIONS: PROGRAM ELEVEN
1. What is Friend Function?
2. What is a friend function & its advantage?
3. What is the draw back in using friend function in c++?
PROGRAM 12: Write a program using inline function.
#include<iostream.h>
#include<conio.h>
inline float mul(float x,float y)
{
return(x*y);
}
inline double div(double p,double q)
{
return(p/q);
};
int main()
{
float a=12.345;
float b=9.82;
cout<<mul(a,b)<<"n";
cout<<div(a,b)<<"n";
return 0;
}
OUTPUT: 121.22
1.25
QUESTIONS: PROGRAM TWELVE
1. Will the inline function be compiled as the inline function always? Justify.
2. What do you mean by inline function?
3. What is the difference between macro and inline()?
PROGRAM 13: Write a program to demonstrate the use of local object.
#include<iostream.h>
#include<conio.h>
class sample
{
public:
int x;
sample()
{
x=0;
}
sample(int y)
{
x=x+y;
}
};
sample global_object;
void main()
{
sample local_object;
cout<<"local object value="<<local_object.x<<endl;
sample local_object1(5);
cout<<"local object1 value="<<local_object1.x<<endl;
sample global_object1(10);
cout<<"Global object1 value="<<global_object1.x<<endl;
static sample static_object;
cout<<"Static object value="<<static_object.x<<endl;
static sample static_object1(20);
cout<<"static object1 value="<<static_object1.x<<endl;
getch();
}
OUTPUT:
local object1 value=0
local object value=5
Global object1 value=10
Static object value=0
static object1 value=20
QUESTIONS PROGRAM THIRTEEN
1. What is OOP?
2. What are the various elements of OOP?
3. What are the characteristics of Object Oriented programming language?
PROGRAM 14: Write a program n C++ to demonstrate the creation and the use of dynamic
object.
#include<iostream.h>
#include<conio.h>
class sample
{
public:
int x;
sample()
{
x=0;
}
sample(int y)
{
x=x+y;
}
};
void main()
{
sample local_object;
cout<<"local object value="<<local_object.x<<endl;
sample *dynamic_object,*dynamic_object1;
dynamic_object=&local_object;
cout<<"Dynamic object value="<<dynamic_object->x<<endl;
sample local_object1(4);
cout<<"local object1 value="<<local_object1.x<<endl;
dynamic_object1=&local_object1;
cout<<"Dynamic object1 value="<<dynamic_object->x<<endl;
getch();
}
OUTPUT:
local object1 value=0
dynamic object value=0
local object1 value=4
dynamic object value=4
QUESTIONS PROGRAM FOURTEEN
1. What is Dynamic object?
2. How to create dynamic object?
3.How to handle dynamic objects in QTP?
PROGRAM 15: Write a program to create two classes DM and DB which store the value of
distances.
#include<iostream.h>
#include<conio.h>
class DB;
class DM
{int metres;
float centimetres;
public:
DM()
{
metres=0;centimetres=0.00;
}
DM(int m,float cm)
{ metres=m;
centimetres=cm;
}
int get_m()
{
return metres;
}
float get_cm()
{
return centimetres;
}
void getdata()
{
cout<<"enter metres:";
cin>>metres;
cout<<"enter centimetres:";
cin>>centimetres;
}
void display()
{
cout<<metres<<"m-"<<centimetres<<"cm";
}
friend DM add(DM,DB);
};
class DB
{
int feet;
float inches;
public:
DB()
{
feet=0;
inches=0.00;
}
DB(int f,float i)
{ feet=f;
inches=i;
}
DB(DM dm)
{
int m;
float cm,t_cm,t_in;
m=dm.get_m();
cm=dm.get_cm();
t_cm=m*100+cm;
t_in=t_cm/2.54;
feet=int(t_in)/12;
inches=t_in-feet*12;
}
operator DM()
{
float in=feet*12+inches;
float cm=in*2.54;
int mtr=int(cm)/100; float
cmtr=cm-mtr*100; return
DM(mtr,cmtr);
}
void getdata()
{
cout<<"enter feet:";
cin>>feet; cout<<"enter
inches:"; cin>>inches;
}
void display()
{
cout<<feet<<"'-"<<inches<<""";
}
friend DM add(DM,DB);
};
DM add(DM dm,DB db)
{
DM a=db;
int m=dm.metres+a.metres;
float cm=dm.centimetres+a.centimetres;
if(int(cm)>=100)
{
cm-=100.00;
m++;
}
return DM(m,cm);
}
int main()
{
DB db,db1; DM
dm,dm1;
clrscr();
cout<<"enter distance d1(in metres & centimetres):n";
dm.getdata();
cout<<"enter distance d2(in feet & inches):n";
db.getdata();
dm1=add(dm,db);
db1=add(dm,db);
dm.display();cout<<" + ";db.display();cout<<" = ";dm1.display();
cout<<" = ";
db1.display();
getch();
return 0;}
OUTPUT:
enter distance d1(in metres & centimetres):
enter metres:2
enter centimetres:22
enter distance d2(in feet & inches):
enter feet:12 enter
inches:12
2m-22cm + 12'-12" = 6m-18.23999cm = 20'-3.401566"
QUESTION: PROGRAM FIFTEEN
1. What is public, protected, private
2. What is virtual constructors/destructors?
3. What is the difference between declaration and definition?
PROGRAM 16: Write a program to Derive the two classes son and daughter and,
demonstrate polymorphism in action.
#include<iostream.h>
#include<conio.h>
class father
{
protected:unsigned int age;
public:
father()
{
age=60;
}
father(int x)
{
age=x;
}
virtual void iam()
{
cout<<"I AM THE FATHER,my age is:"<<age<<endl;
}
};
class son:public father
{ public:
son()
{
age=30;
}
son(int x)
{
age=x;
}
void iam()
{
cout<<"I AM THE SON,my age is:"<<age<<endl;
}
};
class daughter:public father
{ public:
daughter()
{
age=24;
}
daughter(int x)
{
age=x;
}
void iam()
{
cout<<"I AM THE DAUGHTER,my age is:"<<age<<endl;
}
};
int main()
{
father f(50),*ptrf;
son s(23); daughter
d(16); clrscr();
cout<<"nn******************************CALL BY FATHER
OBJECT*************nn";
f.iam();
cout<<"nn*******************************CALL BY SON
OBJECT***************nn";
s.iam();
cout<<"nn*****************************CALL BY DAUGHTER
OBJECT************nn";
d.iam();
ptrf=&s;
cout<<"nn***************CALL BY POINTER TO FATHER WITH ADDRESS OF
SON OBJECTnn";
ptrf->iam();//(*ptrf).iam();
cout<<"nn************CALL BY POINTER TO FATHER WITH ADDRESS OF
DAUGHTER OBJECTnn";
ptrf=&d;
ptrf->iam();//(*ptrf).iam();
cout<<"nn==================================================";
getch();
return 0;}
OUTPUT:
******************************CALL BY FATHER
OBJECT*****************************
I AM THE FATHER,my age is:50
*******************************CALL BY SON
OBJECT******************************
I AM THE SON,my age is:23
*****************************CALL BY DAUGHTER
OBJECT****************************
I AM THE DAUGHTER,my age is:16
***************CALL BY POINTER TO FATHER WITH ADDRESS OF SON
OBJECT*************
I AM THE SON,my age is:23
************CALL BY POINTER TO FATHER WITH ADDRESS OF DAUGHTER
OBJECT***********
I AM THE DAUGHTER,my age is:16
QUESTION: PROGRAM SIXTEEN
1. What is Polymorphism? Explain it with an example.
2. What are the types of Polymorphism?
3. Advantages of Polymorphism
PROGRAM 17: Write a program to Create a base class called shape. Use this class to
store two double type values that could be used to compute the area of figures.
#include<iostream.h>
#include<conio.h>
class shape
{ protected: double x; double y; public: shape()
{ x=0.0; y=0.0;
}
shape(double a,double b)
{ x=a; y=b;
}
void get_data()
{
cout<<"enter x:"; cin>>x; cout<<"enter y:"; cin>>y;
}
virtual void display_area()=0;
};
class triangle:public shape
{ public: triangle()
{}
triangle(double a,double b):shape(a,b)
{}
void display_area()
{
cout<<"Area of triangle:"<<(x*y)/2;
}
};
class rectangle:public shape
{
public:
rectangle()
{}
rectangle(double a,double b):shape(a,b)
{}
void display_area()
{
cout<<"Area of rectangle:"<<x*y;
}
};
int main()
{
int c; clrscr(); while(1)
{
cout<<"n1.area of triangle"; cout<<"n2.area of rectangle"; cout<<"n3.exit"; cout<<"nenter
your choice:"; cin>>c;
switch(c)
{
case 1:triangle t; t.get_data(); t.display_area(); break;
case 2:rectangle r; r.get_data(); r.display_area(); break;
case 3:return 0;
default:cout<<"invalid choice";
}
}
}
_________________________________________________________________________
OUTPUT:
1.area of triangle
2.area of rectangle
3.exit
enter your choice:2
enter x:2
enter y:5
Area of rectangle:10
1.area of triangle
2.area of rectangle
3.exit
enter your choice:3
QUESTION: PROGRAM SEVENTEEN
1. What is the difference between an ARRAY and a LIST?
2. Define a constructor - What it is and how it might be called (2 methods).
3. What is the difference between class and structure
Viva Question
1) What Is an Object?
2) What Is Object Encapsulation (Or Protection)?
3 What Is A Class?
4) What Is a Meta-Class?
5) What Is the Infinite Regress Of Objects And Classes?
6) What Are MOPs and Reflection?
7) What Is Inheritance?
8) What Is Multiple Inheritance?
9) Does Multiple Inheritance Pose Any Additional Difficulties?
10) What Is Dynamic Inheritance?
11) What Is Shared (Repeated) Inheritance?
12) Why Use Inheritance?
13) Why Don't Some People Like Inheritance?
14) What Is Specialization/Generalization/Overriding?
15) What Is the Difference between Object-Based and Object-Oriented?
16) Is A Class An Object?
17) Is an Object A Class?
18) What Is a Method? (And Receiver And Message)
19) What Are Multi-Methods and Multiple-Polymorphism?
20) What Is OOP?
21) What Is OOA/OOD (And Where Can I Get What I Need On It)?
22) Where Did Object-Orientation Come From?
23) What Are the Benefits of Object-Orientation?
24) What Is Polymorphism?
25) How does Polymorphism Boil Down In OO Programming
Languages?
26) What Is Dynamic Binding?
27) Is There A Difference Between Being A Member Or Instance Of A
Class?
28) What Is The Difference Between Static And Dynamic Typing?
29) What Is A difference Between Type And Class (Representation)?
30) What Are Generics and Templates?
31) What Is the "Classical" Object-Oriented Paradigm?
32) What Is the "Delegation/Prototyping" Object-Oriented Paradigm?
33) Are There Any Other Object-Oriented Paradigms?
34) What Are the Major Object-Oriented Programming Languages
Today?
35) What Are Object-Oriented Databases and Persistence?
36) What Are Object-Oriented Operating Systems?
37) What Are the Current Object-Oriented Methodologies?
38) What Is the OMG/OMA/ORB/CORBA?

Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (useful search)

  • 1.
    COMPUTER SCIENCE ENGINEERING LABMANUAL IV SEM OBJECT ORIENTED TECHNOLOGY (IT 303) ) INDEX 1. Syllabus 2. Rational behind the OOPS Lab 3. Hardware/Software Requirement 4. Practical List 5. Practical conducted in the lab 6. References 7. Viva Question SYLLABUS Unit I Introduction, Object Oriented Programming Concepts, Flow chart, Objects, Objects as software modules, Objects interaction, Classes, Method lookup, Hierarchies of classes, Inheritance, Polymorphism, Abstract classes. Unit II Identifying objects and classes, Representation of objects, Modeling, objects and classes, Relationships. Association between objects, aggregate components of objects. Storage Management :Memory allocation, Dynamic allocation. Unit III Object oriented programming languages, Class declarations, Object declarations, Mandatory profiles, Message sending, Association, Recursive association, Many to many association, Argument passing. Unit IV Inherited methods, Redefined methods, The protected interface, Abstract base classes, Public and protected properties, Private operations, Disinheritance, Multiple inheritance. Unit V Study of C++ as object oriented programming language. Rational Behind Object-Oriented Programming Object-oriented programming (OOP) is a programming paradigm that uses abstraction to create models based on the real world. It utilizes several
  • 2.
    techniques from previouslyestablished paradigms, including modularity, polymorphism, and encapsulation. Even though it originated in the 1960s, OOP was not commonly used in mainstream software application development until the 1990s. Today, many popular programming languages (such as Java, JavaScript, C#, C++, Python) support OOP. Object-oriented programming's roots reach all the way back to the creation of the Simula programming language in the 1960s, when the nascent field of software engineering had begun to discuss the idea of a software crisis. As hardware and software became increasingly complex, how could software quality is being maintained? Object- oriented programming in part addresses this problem by strongly emphasizing modularity in software. Object-oriented programming may be seen as a collection of cooperating objects, as opposed to a traditional view in which a program may be seen as a collection of functions, or simply as a list of instructions to the computer. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent little machine with a distinct role or responsibility. Object-oriented programming is intended to promote greater flexibility and maintainability in programming, and is widely popular in large-scale software engineering. By virtue of its strong emphasis on modularity, object oriented code is intended to be simpler to develop and easier to understand later on, lending itself to more direct analysis, coding, and understanding of complex situations and procedures than less modular programming methods. HARDWARE & SOFTWARE REQUIREMENT: HARDWARE REQUIREMENT • PENTIUM I (200 GHZ) • 128 MB RAM • 20 GB HDD SOFTWARE REQUIREMENT • WINDOWS 9x or above • Language C ++ SNO. Practical List 1 Write a program to add, subtracts, multiply and divide two numbers using concepts of C++. 2 Write a program to showswapping oftwo numbers using C++.
  • 3.
    3 Write aprogram to swapping oftwo number without including third variable 4 Write a program to calculate volume ofcube, cylinder, rectangular box using three times function overloading in C++. 5 Write a program using virtual function. 6 Write a program to describe constructor. 7 Write a program to describe destructor. 8 Write a program using copy constructor. 9 Write a program PAYROLL SYSTEM USING SINGLE INHERITANCE 10 Write a program o showmultiple inheritances. 11 Write a program to find mean value oftwo numbers using friend function. 12 Write a program using inline function. 13 Write a program to demonstrate the use ofLocal Object,Static Object & Global Object using C ++. 14 Write a program in C++ to demonstrate the creation and the use ofdynamic object. 15 Write a program to Create two classesDM and DB which store the value of distances 16 Write a program to Derive the two classes son and daughter and, demonstrate polymorphism in action. 17 Write a program to Create a base class called shape. Use this class to store two double t type value that could be used to compute the area offigures.
  • 4.
    EXPERIMENT:1 Write a programto add, subtract, multiply and divide two numbers using concepts of C++. #include<iostream.h> #include<conio.h> class math { float a,b; public: void getval() { cout<<"nnEnter two values "; cin>>a>>b; cout<<"nyou enter a="<<a; cout<<"nyou enter b="<<b; } void add() { cout<<"nnADDITION is "<<a+b; } void sub() { cout<<"nn SUBSTRACTION is "<<a-b; } void mult() { cout<<"nn MULTIPLICATION is "<<a*b; } void div() { cout<<"nn DIVISION is "<<a/b; } }; void main() { int i,t; clrscr(); class math obj; obj.getval(); cout<<"nn************************************************"; cout<<"nnFor Addtion press --> 1"; cout<<"nnFor Substration press --> 2"; cout<<"nnFor Multiplication press --> 3"; cout<<"nnFor Division press --> 4"; cout<<"nn************************************************"; cout<<"nnnplesae enter value ";
  • 5.
    while(t==0){ cin>>i; cout<<"nn-----------------------------------------------"; switch(i) { case 1: obj.add(); break; case 2: obj.sub(); break; case3: obj.mult(); break; case 4: obj.div(); break; default: cout<<"nnWrong choise"; } cout<<"nnfor Exit press any key or want more operation press 0 --> "; cin >>t; if(t==0) cout<<"nSelect new operarion "; } getch(); } OUTPUT: Enter two values 3 5 you enter a 3 you enter a 5 ************************************************ For Addtion press --> 1 For Substration press --> 2 For Multiplication press --> 3 For Division press --> 4 ************************************************"; plesae enter value 1 QUESTIONS PROGRAM ONE 1) What is C++? 2) What is the difference between declaration and definition? 3) Write a program that ask for user input from 5 to 9 then calculate the average?
  • 6.
    EXPERIMENT :2 Write aprogram to show swapping of two numbers using C++. #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,b,c; cout<<"Enter a: "; cin>>a; cout<<"Enter b: "; cin>>b; cout<<"Before swapping:"<<endl; cout<<"a: "<<a<<" b: "<<b<<endl; c=a; a=b; b=c; cout<<"After swapping:"<<endl; cout<<"a: "<<a<<" b: "<<b; getch(); } OUTPUT: Enter a: 3 Enter b: 5 Before swapping a:3 b:5 after swapping a:5 b:3 QUESTIONS PROGRAM TWO 1. Code for swapping of two numbers without using temporary variable using C 2. What is the difference between Swapping and Paging? 3. What are the criteria for choosing a process for swapping into memory from the swap device EXPERIMENT 3 write a program to swapping of two numbers without including third variable. #include<conio.h> #include <iostream.h> class swapping { int a,b; public : void swap() { cout<<"enter any two value for swapping"; cin>>a>>b; cout<<"n Befroe swapping values of a:"<<a<<" and b:"<<b; a=a+b;
  • 7.
    b=a-b; a=a-b; cout<<"n After swappingvalues of a:"<<a<<" and b:"<<b; } }; void main() { clrscr(); swapping s1;//object declared s1.swap(); getch(); } OUTPUT: Enter a: 3 Enter b: 5 Before swapping a: 3 b: 5 after swapping a: 5 b: 3 QUESTIONS PROGRAM THREE 1. What is the difference between Swapping and Paging? 2. Write a function to swap any two numbers? 3. Works best with many small partitions 4. Allows many programs to use memory simultaneously EXPERIMENT:4 Write a program to calculate volume of cube, cylinder, rectangular box using three times function overloading in C++. #include<iostream.h> #include<conio.h> void main() { int volume(int); long volume(double,int); long volume(long,int,int); int main() { cout<<volume(10)<<"n"; cout<<volume(2.5,8)<<'n"; cout<<volume(100,75,15)<<"n"; return 0; } int volume(int s) { return(s*s*s); } double volume(double r,int h) { return(3.14519*r*r*h);
  • 8.
    } long volume(long l,int b, int h) { return(i*b*h); } OUTPUT: 1000 157 112500 QUESTIONS PROGRAM FOUR 1. What is function overloading? 2. What are the need /use offunction overloading? 3. What restrictions are placed on method overloading? EXPERIMENT :5 Write a program using virtual function.
  • 9.
    #include<iostream.h> #include<conio.h> class Base { public: void display(){cout<<"n Display base";} virtual void show() {cout<<"n show base";} }; class Derived : public Base { public: void display() {cout<<"n Display derived";} void show() {cout<<"n show derived";} }; int main() { Base B; Derived D; Base *bptr; cout<<"n bptr points to base |n"; bptr= &B; bptr->display(); bptr->show(); cout<<"nn bptr points to derivedn"; bptr=&D; bptr->display(); bptr->show(); return 0; } OUTPUT: bptr points to base Display base show base bptr points to derived Display base show derived QUESTIONS: PROGRAM FIVE 1. What is virtual function? Explain with an example. 2. What is a virtual base class? 3. What are pure virtual functions?
  • 10.
    EXPERIMENT:6 Write a programto describe constructor. #include<conio.h> #include<iostream.h> class greatest { int a,b; public : greatest(int x,int y) { a=x; b=y; } void show() { if(a>b) cout<<"a is greatest number"; else cout<<"b is greatest number"; } }; void main() { clrscr(); greatest s1(10,20); s1.show(); getch(); } OUTPUT: b is greatest number QUESTIONS: PROGRAM SIX 1. In C++, what is a constructor? 2. What is the difference between constructor and method? 3. Why Call by reference technique is used in case of Copy constructor & not call by value?
  • 11.
    EXPERIMENT:7 write a programto describe destructor. #include<conio.h> #include<iostream.h> class integer { int a,b; public : integer(int x,int y) { a=x; b=y; } void add() { a=a+b; } ~integer() { cout<<"a="<<a; } }; void main() { clrscr(); int i,j; cout<<"enter the value i and j="; cin>>i>>j; integer l(i,j); l.add(); getch(); } OUTPUT: enter the value i and j= 10 20 a= 30 QUESTIONS PROGRAM SEVEN 1. In C++, what is a destructor? 2. Can destructor be private? 3. What is the use ofvirtual destructor?
  • 12.
    EXPERIMENT:8 Write a programusing copy constructor. #include<iostream.h> #include<conio.h> class code { int id; public: code() { } code(int a) {id=a;} code(code &x) { id=x.id; } void display(void) { cout<<id; } }; int main() { code A(100); code B(A); code C=A;
  • 13.
    cout<<"n id ofA:"; A.display(); cout<<"n id of B:"; B.display(); cout<<"n id of C:"; C.display(); return 0; } OUTPUT: id of id of A: 100 id of id of B: 100 id of id of C: 100 QUESTIONS PROGRAM EIGHT 1. What is a COPYCONSTRUCTORand when is it called? 2. What are the differences between member function and constructor? 3. Why the constructor can’t be virtual? EXPERIMENT:9 Write a program Payroll System Using Single Inheritance #include<iostream.h> #include<conio.h> class emp {
  • 14.
    public: int eno; char name[20],des[20]; voidget() { cout<<"Enter the employee number:"; cin>>eno; cout<<"Enter the employee name:"; cin>>name; cout<<"Enter the designation:"; cin>>des; } }; class salary:public emp { float bp,hra,da,pf,np; public: void get1() { cout<<"Enter the basic pay:"; cin>>bp; cout<<"Enter the Humen Resource Allowance:"; cin>>hra; cout<<"Enter the Dearness Allowance :"; cin>>da; cout<<"Enter the Profitablity Fund:"; cin>>pf; } void calculate() { np=bp+hra+da-pf; } void display() { cout<<eno<<"t"<<name<<"t"<<des<<"t"<<bp<<"t"<<hra<<"t"<<da<<"t"<<pf<<"t"<< }}; void main() { int i,n; char ch; salary s[10]; clrscr(); cout<<"Enter the number of employee:"; cin>>n; for(i=0;i<n;i++) { s[i].get(); s[i].get1(); s[i].calculate();
  • 15.
    } cout<<"ne_no t e_nametdes t bp t hra t da t pf t np n"; for(i=0;i<n;i++) { s[i].display(); } getch(); } OUTPUT: Enter the Number of employee:1 Enter the employee No: 150 Enter the employee Name: ram Enter the designation: Manager Enter the basic pay: 5000 Enter the HR allowance: 1000 Enter the Dearness allowance: 500 Enter the profitability Fund: 300 E.No E.name des BP HRA DA PF NP 150 ram Manager 5000 1000 500 300 6200 QUESTIONS PROGRAM NINE 1. What do you mean by inheritance? 2. What does inheritance means in C++? 3. What are the different forms of inheritance? Give an example for each. EXPERIMENT:10 Write a program to show multiple inheritances. #include<iostream.h> #include<conio.h> class M { protected: int m; public: void get_m(int); }; class N { protected: int n; public: void get_n(int); };
  • 16.
    class P: publicM, public N { public: void display(void); }; void M::get_m(int x) { m=x; } void N::get_n(int y) { n=y; } void P::display(void) { cout<<"m="<<m<<"n"; cout<<"n="<<n<<"n"; cout<<"m*n="<<m*n<<"n"; } int main() { P p; p.get_m(10); p.get_n(20); p.display(); return 0; } OUTPUT: m=10 n=20 m*n=200 QUESTIONS: PROGRAM TEN 1. Is it possible to inherit the private member in derived class? 2. Can you prevent your class from being inherited and becoming a base class for some other classes? 3. Can you allow class to be inherited, but prevent the method from being over-ridden? PROGRAM 11: Write a program to find mean value of two numbers using friend function. #include<iostream.h> #include<conio.h> class sample { int a; int b; public: void setvalue() {a=25; b=40;}
  • 17.
    friend float mean(samples); }; float mean(sample s) { return float(s.a+s.b)/2.0; } int main() { sample X; X.setvalue(); cout<<"Mean value="<<mean(X)<<"n"; return 0; } OUTPUT: Mean value= 32.5 QUESTIONS: PROGRAM ELEVEN 1. What is Friend Function? 2. What is a friend function & its advantage? 3. What is the draw back in using friend function in c++? PROGRAM 12: Write a program using inline function. #include<iostream.h> #include<conio.h> inline float mul(float x,float y) { return(x*y); } inline double div(double p,double q) { return(p/q); }; int main() { float a=12.345; float b=9.82; cout<<mul(a,b)<<"n"; cout<<div(a,b)<<"n"; return 0; } OUTPUT: 121.22 1.25 QUESTIONS: PROGRAM TWELVE 1. Will the inline function be compiled as the inline function always? Justify. 2. What do you mean by inline function? 3. What is the difference between macro and inline()?
  • 18.
    PROGRAM 13: Writea program to demonstrate the use of local object. #include<iostream.h> #include<conio.h> class sample { public: int x; sample() { x=0; } sample(int y) { x=x+y; } }; sample global_object; void main() { sample local_object; cout<<"local object value="<<local_object.x<<endl; sample local_object1(5); cout<<"local object1 value="<<local_object1.x<<endl; sample global_object1(10); cout<<"Global object1 value="<<global_object1.x<<endl; static sample static_object; cout<<"Static object value="<<static_object.x<<endl; static sample static_object1(20); cout<<"static object1 value="<<static_object1.x<<endl; getch(); } OUTPUT: local object1 value=0 local object value=5 Global object1 value=10 Static object value=0 static object1 value=20 QUESTIONS PROGRAM THIRTEEN 1. What is OOP? 2. What are the various elements of OOP? 3. What are the characteristics of Object Oriented programming language?
  • 19.
    PROGRAM 14: Writea program n C++ to demonstrate the creation and the use of dynamic object. #include<iostream.h> #include<conio.h> class sample { public: int x; sample() { x=0; } sample(int y) { x=x+y; } }; void main() { sample local_object; cout<<"local object value="<<local_object.x<<endl; sample *dynamic_object,*dynamic_object1; dynamic_object=&local_object; cout<<"Dynamic object value="<<dynamic_object->x<<endl; sample local_object1(4); cout<<"local object1 value="<<local_object1.x<<endl; dynamic_object1=&local_object1; cout<<"Dynamic object1 value="<<dynamic_object->x<<endl; getch(); } OUTPUT: local object1 value=0 dynamic object value=0 local object1 value=4 dynamic object value=4
  • 20.
    QUESTIONS PROGRAM FOURTEEN 1.What is Dynamic object? 2. How to create dynamic object? 3.How to handle dynamic objects in QTP? PROGRAM 15: Write a program to create two classes DM and DB which store the value of distances. #include<iostream.h> #include<conio.h> class DB; class DM {int metres; float centimetres; public: DM() { metres=0;centimetres=0.00; } DM(int m,float cm) { metres=m; centimetres=cm; } int get_m() { return metres; } float get_cm() { return centimetres; }
  • 21.
    void getdata() { cout<<"enter metres:"; cin>>metres; cout<<"entercentimetres:"; cin>>centimetres; } void display() { cout<<metres<<"m-"<<centimetres<<"cm"; } friend DM add(DM,DB); }; class DB { int feet; float inches; public: DB() { feet=0; inches=0.00; } DB(int f,float i) { feet=f; inches=i; } DB(DM dm) { int m; float cm,t_cm,t_in; m=dm.get_m(); cm=dm.get_cm(); t_cm=m*100+cm; t_in=t_cm/2.54; feet=int(t_in)/12; inches=t_in-feet*12; } operator DM() { float in=feet*12+inches; float cm=in*2.54; int mtr=int(cm)/100; float cmtr=cm-mtr*100; return DM(mtr,cmtr); } void getdata() {
  • 22.
    cout<<"enter feet:"; cin>>feet; cout<<"enter inches:";cin>>inches; } void display() { cout<<feet<<"'-"<<inches<<"""; } friend DM add(DM,DB); }; DM add(DM dm,DB db) { DM a=db; int m=dm.metres+a.metres; float cm=dm.centimetres+a.centimetres; if(int(cm)>=100) { cm-=100.00; m++; } return DM(m,cm); } int main() { DB db,db1; DM dm,dm1; clrscr(); cout<<"enter distance d1(in metres & centimetres):n"; dm.getdata(); cout<<"enter distance d2(in feet & inches):n"; db.getdata(); dm1=add(dm,db); db1=add(dm,db); dm.display();cout<<" + ";db.display();cout<<" = ";dm1.display(); cout<<" = "; db1.display(); getch(); return 0;} OUTPUT: enter distance d1(in metres & centimetres): enter metres:2 enter centimetres:22 enter distance d2(in feet & inches): enter feet:12 enter inches:12 2m-22cm + 12'-12" = 6m-18.23999cm = 20'-3.401566" QUESTION: PROGRAM FIFTEEN 1. What is public, protected, private
  • 23.
    2. What isvirtual constructors/destructors? 3. What is the difference between declaration and definition? PROGRAM 16: Write a program to Derive the two classes son and daughter and, demonstrate polymorphism in action. #include<iostream.h> #include<conio.h> class father { protected:unsigned int age; public: father() { age=60; } father(int x) { age=x; } virtual void iam() { cout<<"I AM THE FATHER,my age is:"<<age<<endl; } }; class son:public father { public: son() { age=30; } son(int x) { age=x; } void iam() { cout<<"I AM THE SON,my age is:"<<age<<endl; } }; class daughter:public father { public: daughter() { age=24; } daughter(int x) { age=x; } void iam()
  • 24.
    { cout<<"I AM THEDAUGHTER,my age is:"<<age<<endl; } }; int main() { father f(50),*ptrf; son s(23); daughter d(16); clrscr(); cout<<"nn******************************CALL BY FATHER OBJECT*************nn"; f.iam(); cout<<"nn*******************************CALL BY SON OBJECT***************nn"; s.iam(); cout<<"nn*****************************CALL BY DAUGHTER OBJECT************nn"; d.iam(); ptrf=&s; cout<<"nn***************CALL BY POINTER TO FATHER WITH ADDRESS OF SON OBJECTnn"; ptrf->iam();//(*ptrf).iam(); cout<<"nn************CALL BY POINTER TO FATHER WITH ADDRESS OF DAUGHTER OBJECTnn"; ptrf=&d; ptrf->iam();//(*ptrf).iam(); cout<<"nn=================================================="; getch(); return 0;} OUTPUT: ******************************CALL BY FATHER OBJECT***************************** I AM THE FATHER,my age is:50 *******************************CALL BY SON OBJECT****************************** I AM THE SON,my age is:23 *****************************CALL BY DAUGHTER OBJECT**************************** I AM THE DAUGHTER,my age is:16 ***************CALL BY POINTER TO FATHER WITH ADDRESS OF SON OBJECT************* I AM THE SON,my age is:23 ************CALL BY POINTER TO FATHER WITH ADDRESS OF DAUGHTER OBJECT*********** I AM THE DAUGHTER,my age is:16 QUESTION: PROGRAM SIXTEEN 1. What is Polymorphism? Explain it with an example. 2. What are the types of Polymorphism?
  • 25.
    3. Advantages ofPolymorphism PROGRAM 17: Write a program to Create a base class called shape. Use this class to store two double type values that could be used to compute the area of figures. #include<iostream.h> #include<conio.h> class shape { protected: double x; double y; public: shape() { x=0.0; y=0.0; } shape(double a,double b) { x=a; y=b; } void get_data() { cout<<"enter x:"; cin>>x; cout<<"enter y:"; cin>>y; } virtual void display_area()=0; }; class triangle:public shape { public: triangle() {} triangle(double a,double b):shape(a,b) {} void display_area() { cout<<"Area of triangle:"<<(x*y)/2; } }; class rectangle:public shape { public: rectangle() {} rectangle(double a,double b):shape(a,b) {} void display_area() { cout<<"Area of rectangle:"<<x*y; } }; int main()
  • 26.
    { int c; clrscr();while(1) { cout<<"n1.area of triangle"; cout<<"n2.area of rectangle"; cout<<"n3.exit"; cout<<"nenter your choice:"; cin>>c; switch(c) { case 1:triangle t; t.get_data(); t.display_area(); break; case 2:rectangle r; r.get_data(); r.display_area(); break; case 3:return 0; default:cout<<"invalid choice"; } } } _________________________________________________________________________ OUTPUT: 1.area of triangle 2.area of rectangle 3.exit enter your choice:2 enter x:2 enter y:5 Area of rectangle:10 1.area of triangle 2.area of rectangle 3.exit enter your choice:3 QUESTION: PROGRAM SEVENTEEN 1. What is the difference between an ARRAY and a LIST? 2. Define a constructor - What it is and how it might be called (2 methods). 3. What is the difference between class and structure
  • 27.
    Viva Question 1) WhatIs an Object? 2) What Is Object Encapsulation (Or Protection)? 3 What Is A Class? 4) What Is a Meta-Class? 5) What Is the Infinite Regress Of Objects And Classes? 6) What Are MOPs and Reflection? 7) What Is Inheritance? 8) What Is Multiple Inheritance? 9) Does Multiple Inheritance Pose Any Additional Difficulties? 10) What Is Dynamic Inheritance? 11) What Is Shared (Repeated) Inheritance? 12) Why Use Inheritance? 13) Why Don't Some People Like Inheritance? 14) What Is Specialization/Generalization/Overriding? 15) What Is the Difference between Object-Based and Object-Oriented? 16) Is A Class An Object? 17) Is an Object A Class? 18) What Is a Method? (And Receiver And Message) 19) What Are Multi-Methods and Multiple-Polymorphism? 20) What Is OOP? 21) What Is OOA/OOD (And Where Can I Get What I Need On It)? 22) Where Did Object-Orientation Come From? 23) What Are the Benefits of Object-Orientation? 24) What Is Polymorphism? 25) How does Polymorphism Boil Down In OO Programming Languages? 26) What Is Dynamic Binding? 27) Is There A Difference Between Being A Member Or Instance Of A Class? 28) What Is The Difference Between Static And Dynamic Typing? 29) What Is A difference Between Type And Class (Representation)? 30) What Are Generics and Templates? 31) What Is the "Classical" Object-Oriented Paradigm? 32) What Is the "Delegation/Prototyping" Object-Oriented Paradigm? 33) Are There Any Other Object-Oriented Paradigms? 34) What Are the Major Object-Oriented Programming Languages Today? 35) What Are Object-Oriented Databases and Persistence? 36) What Are Object-Oriented Operating Systems? 37) What Are the Current Object-Oriented Methodologies? 38) What Is the OMG/OMA/ORB/CORBA?