Oops Full Codes
Oops Full Codes
Oops Full Codes
}
cout<<"\n Reverse of a number is "<<rev;
cout<<"\n Sum of digits"<<sum;
}
void callfor( )
{
readno( );
cout<<"\n Table of"<<no<<endl;
for(int i=1; i<=10; i++)
{
cout<<no*i<<endl;
}
}
};
int main( ) {
control e;
char ans;
int n;
do
{
cout<<"Enter your choice;\n";
cout<<"1.if condition:\n";
cout<<"2.while loop:\n";
cout<<"3.for loop\n";
cin>>n;
switch(n)
{
case1:
cout<<"\n Even odd";
c.callif( );
break;
case2:
cout<<"\n Reverse of number";
c.callwhile( );
break;
case3:
cout<<"\n Table generator";
c.callfor( );
break;
default:
cout<<"\n Invalid choice";
}
cout<<"\n Do you want to continue press y for yes:";
cin>>ans;
} while(ans=='y');
return 0
}
2D array:
#include <iostream>
#include<conio.h>
using namespace std;
class Array_2D
{
public:
int b[5][5];
void acceptArray()
{
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<"\n Enter array element["<<i<<"]["<<j<<"]"<<endl;
cin>>b[i][j];
}
}
}
Array_2D addition(Array_2D o1,Array_2D o2)
{
int t;
Array_2D o3;
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
o3.b[i][j]=o1.b[i][j]+o2.b[i][j];
}
}
return o3;
}
void show()
{
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
cout<<b[i][j]<<"\t";
}
cout<<endl;
}
}
};
int main()
{
Array_2D o1,o2,o3;
cout<<"\n Array 1";
o1.acceptArray();
cout<<"\n Array? 2";
o2.acceptArray();
o3=o3.addition(o1,o2);
cout<<"\n Array 1"<<endl;
o1.show();
cout<<"\n Array 2"<<endl;
o2.show();
cout<<"\n Addition of Two arrays:"<<endl;
o3.show();
return 0;
}
return 1;
Destructor:
#include <iostream>
using namespace std;
class Employee
{
public:
Employee()
{
cout<<"Constructor Invoked"<<endl;
}
~Employee()
{
cout<<"Destructor Invoked"<<endl;
}
};
int main(void)
{
Employee e1;
Employee e2;
return 0;
}
Practical no.8
Multiple inheritance:
#include <iostream>
#include<conio.h>
using namespace std;
class mammal
{
public:
mammal()
{
cout<<"Mammals are a group of vertebrate animals"<<endl;
}
};
class wingedAnimal
{
public:
wingedAnimal()
{
cout<<"Winged animal can flap ."<<endl;
}
};
int main()
{
cout<<"multiple inheritance \n";
Bat b1;
return 0;
Heirarchical inheritance:
>
#include<conio.h>
using namespace std;
class A
{
public:
int x,y;
void getdata()
{
cout<<"Enter value x and y: \n ";
cin>>x>>y;
}
};
class B :public A
{
public:
void product()
{
cout<<"\n product="<<x*y<<endl;
}
};
class C :public A
{
public:
void sum()
{
cout<<"\n sum="<<x-y;
}
};
int main()
{
cout<<"Heirachical inheritance";
B obj1;
C obj2;
obj1.getdata();
obj1.product();
obj2.getdata();
obj2.sum();
return 0;
}
class A
{
public:
int a;
A(int x)
{
cout<<"Base class constructor calling";
a=x;
cout<<"\n a="<<a<<endl;
}
};
class B:public A
{
public:
int b;
B(int x,int y):A(y)
{
cout<<"Intermediate derived class constructor calling";
b=x;
cout<<"\n b="<<b<<endl;
}
};
class C: public B
{
public:
int c;
C(int x,int y, int z):B(x,y)
{
cout<<"Derived Class Constructor Calling";
c+z;
cout<<"\n c="<<c<<endl;
}
};
int main()
{
cout<<"\n Multilevel Inheritance with Constructors"<<endl;
C o(10,20,30);
return 0;
Practical no.10
1) Friend function:
#include <iostream>
#include<conio.h>
using namespace std;
class two;
class one
{
int d1;
public:
void setValue(int x)
{
d1=x;
}
friend void sum(one , two);
void show()
{
cout<<"You entered distance1="<<d1<<endl;
}
};
class two
{
int d2;
public:
void setValue(int x)
{
d2=x;
}
friend void sum(one,two);
void show()
{
cout<<"You entered distance2="<<d2<<endl;
}
};
int ans=o.d1+t.d2;
cout<<"Sum of two distances are :"<<ans;
}
int main()
{
//clscr();
one o;
o.setValue(120);
o.show();
two t;
t.setValue(150);
t.show();
sum(o,t);
return 0;
}
2) Inline function:
#include<iostream>
using namespace std;
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();
s.division();
return 0;
}
3) This pointer:
#include<iostream>
using namespace std;
class test
{
private:
int x;
public:
void setX (int x)
{
this->x=x;
}
void print) {cout<<"x="<<x<<endl;}
};
int main()
{
cout<<"Use of this pointer"<<endl;
test obj;
int x=20;
obj.setX(x);
obj.print();
return 0;
}
int mul(int,int);
float mul(float,int);
int mul(int a, int b)
{
return a*b;
}
float mul(double x, int y)
{
return x*y;
};
int main()
{
int r1= mul(6,7);
float r2= mul(0.2,3);
cout<<"r1 is :"<<r1<<endl;
cout<<"r2 is :"<<r2<<endl;
return 0;
2) Overriding:
#include<iostream>
using namespace std;
class animal{
public:
void eat(){
cout<<"Eating...";
}
};
class animal{
public:
void eat(){
cout<<"Eating...";
}
};