Page 1 :
Object Oriented Programming (22316) Practical’s, By Ms. Kambale K.S, , Practical No. 1: Develop minimum 2 program using constant, variable, arithmetic, expression, operators, exhibiting data type conversion, 1) #include<iostream.h>, using namespace std;, int main(){, int a=12;, int b=12;, int c=a+b;, cout<<c;, return 0;, }, Output:, 24, 2) #include<iostream.h>, #include<conio.h>, void main(), {, int a,b,c,d,e,f,g;, clrscr();, cout<<"\n Enter First Number a : ";, cin>>a;, cout<<"\n Enter Second Number b : ";, cin>>b;, c=a+b;, d=a-b;, e=a*b;, f=a/b;, g=a%b;, cout<<" Addition = "<<c<<"\n";, cout<<" Subtraction = "<<d<<"\n";, cout<<" Multiplication = "<<e<<"\n";, cout<<" Division = "<<f<<"\n";, cout<<" Modulus = "<<g<<"\n";, getch();
Page 2 :
}, Output:, Enter First Number a 20, Enter Second Number b 10, Addition = 30, Subtraction = 10, Multiplication = 200, Division = 2, Modulus = 0, Conclusion: We have developed program using constant, variable, arithmetic expression., Practical No. 2: Develop a program to implement 1- dimension array., #include<iostream.h>, using namespace std;, int main(), {, int arr[50], tot, i;, cout<<"Enter the Size: ";, cin>>tot;, cout<<"Enter "<<tot<<" Numbers: ";, for(i=0; i<tot; i++), cin>>arr[i];, cout<<"\nArray with Index\tIts Value\n";, for(i=0; i<tot; i++), cout<<"arr["<<i<<"]"<<"\t\t\t"<<arr[i]<<endl;, cout<<endl;, return 0;, }, Output:
Page 3 :
Conclusion: Hence, We have developed program for 1- dimension array., Practical No. 3: Develop a program that implements a class & use it with objects., #include<iostream.h>, using namespace std;, class circle, {, float Area, radius;, public:, void read(), {, cout<< “Enter Radius of Circle”;, cin>>radius;, }, void compute(), {, Area= 3.14* radius* radius;, }, void display(), {, cout<<”Area of circle=”<<Area;, }, };
Page 4 :
void main(), {, circle obj;, obj.read();, obj.compute();, obj.display();, getch();, }, Output:, Enter Radius of Circle 5, Area of circle= 78.5, Conclusion: Hence, We have developed a program that implements a class & use it with objects., Practical No. 4: Develop a program that implements a class & create array of objects., #include<iostream.h>, using namespace std;, class staff, {, private:, char name[20], dept[20];, public: void accept(), {, cout<<”Enter Name & Department”;, cin>>name>>dept;, }, void display(), {, cout<< name<<”\t”<<dept<<”\n”;, }, };, void main(), {
Page 5 :
int i;, clrscr();, staff s[05];, for(i=0;i<=4;i++), {, s[i].accept();, }, cout<<”Name\t Department\n”;, for(i=0;i<=4;i++), {, s[i].display();, }, getch();, }, Output:, Enter Name & Department: Komal Finance, Enter Name & Department: Shital HR, Enter Name & Department: Sagar Salse, Enter Name & Department: Swapnil HR, Enter Name & Department: Manoj Salse, Name Department, Komal Finance, Shital HR, Sagar Salse, Swapnil HR, Manoj Salse, Conclusion: Hence, We have developed a program that implements a class & create array of, objects., Practical No. 5: Write a program to implement friend function.
Page 6 :
#include<iostream.h>, using namespace std;, class B; //forward declaration., class A, {, int x;, public:, void setdata (int i), {, x=i;, }, friend void max (A, B); //friend function., };, class B, {, int y;, public:, void setdata (int i), {, y=i;, }, friend void max (A, B);, };, void max (A a, B b), {, if (a.x >= b.y), {, cout<<” Value=”<< a.x << endl;, }, else, {, cout<<” Value=”<< b.y << endl;, }, }, int main (), {, A a;, B b;, a.setdata (10);, b.setdata (20);, max (a, b);, return 0;, }, , Output:, Value=20, Conclusion: Hence, We have developed program to implement friend function., Practical No. 6: Write a program to implement inline function., #include <iostream.h>, using namespace std;
Page 7 :
class operation, {, int a,b,add,sub,mul;, float div;, public:, void get();, void sum();, void difference();, void product();, void division();, };, inline void operation :: get(), {, cout << "Enter first value:";, cin >> a;, cout << "Enter second value:";, cin >> b;, }, inline void operation :: sum(), {, add = a+b;, cout << "Addition of two numbers: " << a+b << "\n";, }, inline void operation :: difference(), {, sub = a-b;, cout << "Difference of two numbers: " << a-b << "\n";, }, inline void operation :: product(), {, mul = a*b;, cout << "Product of two numbers: " << a*b << "\n";, }, inline void operation ::division(), {, div=a/b;, cout<<"Division of two numbers: "<<a/b<<"\n" ;, }, int main(), {, cout << "Program using inline function\n";, operation s;, s.get();, s.sum();, s.difference();, s.product();
Page 8 :
s.division();, return 0;, }, , Output:, Enter first value: 10, Enter second value: 2, Addition of two numbers: 12, Difference of two numbers: 08, Product of two numbers: 20, Division of two numbers: 5, , Conclusion: Hence, We have developed program to implement inline function., Practical No. 7: Write a program to implement all types of constructor (constructor, overloading) with destructor., #include <iostream.h>, using namespace std;, class construct, {, public:, float area;, // Constructor with no parameters, construct(), {, area = 0;, }, // Constructor with two parameters, construct(int a, int b), {, area = a * b;, }, void display(), {, cout<<”Area=”<<area<< endl;, }, ~ construct(), {, delete area;, cout<<”Destroyed”;, }, };
Page 9 :
int main(), {, // Constructor Overloading, // with two different constructors, // of class name, construct obj1;, construct obj2( 10, 20);, obj1.display();, obj2.display();, return 1;, }, , Output:, Area=0, Area=200, Destroyed, , Conclusion: Hence, We have developed program to implement all types of constructor, (constructor overloading) with destructor., Practical No. 8: Write a program to implementing single inheritance., #include<iostream.h>, #include<conio.h>, class Data, {, protected:, int a, b;, public:, void read(), {, cout<<”Enter Two Numbers”<<endl;, cin<<a<<b;, }, };, class Sum: public Data, {, private: int add;
Page 10 :
public: void calculate(), {, add= a + b;, }, public: void display(), {, cout<<”Addtion of Two Numbers=”<<add<<endl;, }, };, void main(), {, sum obj;, obj.read();, obj.calculate();, obj.display();, getch();, }, , Output:, Enter Two Numbers 40 60, Addtion of Two Numbers= 100, Conclusion: Hence, We have developed program to implement single inheritance., Practical No. 9: Write a program to implementing multi level inheritance., #include<iostream.h>, #include<conio.h>, class Data, {, protected:, int p, c, m;
Page 11 :
public:, void read(), {, cout<<”Enter The Marks Obtained in Physics, Chemistry & Maths”<<endl;, cin<<p<<c<<m;, }, };, class Sum: public Data, {, protected: int total;, public: void tot(), {, total= p + c + m;, }, };, class percent: public Sum, {, private: float per;, public: void calculate(), {, per = total/300;, }, public: void display(), {, cout<<”The percentage is =”<<per<<endl;, }, };, void main()
Page 12 :
{, percent obj;, obj.read();, obj.tot();, obj.calculate();, obj.display();, getch();, }, Output:, Enter The Marks Obtained in Physics, Chemistry & Maths 90, 98, 99, The percentage is =95.6666664, Conclusion: Hence, We have developed program to implement multi level inheritance., Practical No. 10: Write a program to implementing multiple inheritance., #include <iostream.h>, using namespace std;, // Base class, class Parent1 {, public:, void Function1() {, cout << "Some content in parent1 class.\n" ;, }, };, // Another base class, class Parent2 {, public:, void Function2() {, cout << "Some content in Parent2 class.\n" ;, }
Page 13 :
};, // Derived class, class Child: public Parent1, public Parent2 {, void Function3() {, cout << "Some content in Child class.\n" ;, }, };, int main() {, Child Obj;, Obj.Function1();, Obj.Function2();, Obj.Function3();, return 0;, }, Output:, Some content in parent1 class, Some content in parent2 class, Some content in Child class, Conclusion: Hence, We have developed program to implement multiple inheritance., Practical No. 11: Develop minimum 1 program to demonstrate Pointer to Object., #include<iostream.h>, #include<conio.h>, class Box, {, protected:, int l, b, h;, public:, void setDimension(int x, int y, int z), {, l=x;
Page 14 :
b=y;, h=z;, }, void showDimension(), {, cout<<”l=”<<l<<”b=”<<b<<”h=”<<h;, }, };, void main(), {, clrscr();, Box S, *P;, P= &S;, S.setDimension(10, 15, 20);, S.showDimension();, P setDimension(10, 15, 20);, P showDimension();, getch();, }, Output:, l=10 b=15 h=20, l=10 b=15 h=20, Conclusion: Hence, We have developed program to demonstrate Pointer to Object., Practical No. 12: Write a program to demonstrate function overloading., #include <iostream.h>, using namespace std;, class Cal {, public:, int add(int a,int b){, return a + b;
Page 15 :
}, int add(int a, int b, int c), {, return a + b + c;, }, };, int main() {, Cal C;, , //, , class object declaration., , cout<<C.add(10, 20)<<endl;, cout<<C.add(12, 20, 23);, return 0;, }, Output:, 30, 55, Conclusion: Hence, We have developed program function overloading.