Professional Documents
Culture Documents
1. Code :
#include<iostream>
using namespace std;
class variable
{
public:
static int value;
void decrease()
{
cout<<"The decremented value is : "<<--value<<endl;
}
};
object1.decrease();
object2.decrease();
object3.decrease();
return 0;
}
Output :
2. Code :
#include<iostream>
class shape
{
public:
int l,b,h,s;
int arear()
{
l = 5;
b = 6;
cout<<"The area of the rectangle is : "<<l*b<<endl;
}
int areas()
{
s = 15;
cout<<"The area of the square is : "<<s*s<<endl;
}
int areac()
{
l = 4;
b = 6;
h = 9;
cout<<"The area of the cuboid is : "<<2*(l*b+b*h+h*l)<<endl;
}
};
int main()
{
shape rectangle;
shape square;
shape cuboid;
rectangle.arear();
square.areas();
cuboid.areac();
}
Output :
3. Code :
#include<iostream>
class parent
{
public:
int m,n;
int add()
{
m = 6;
n = 9;
int s = m+n;
cout<<"The two numbers are "<<m<<" and "<<n<<endl;
}
};
int s;
int sum()
{
cout<<"The sum of the two numbers is : "<<6+9<<endl;
}
};
int show()
{
cout<<"This is an example of Multilevel Inheritance"<<endl;
}
};
int main()
{
parent obj1;
child obj2;
grandchild obj3;
obj1.add();
obj2.sum();
obj3.show();
}
Output :
4. Code :
Output :
5. Code :
Output :