0% found this document useful (0 votes)
47 views2 pages

Using Namespace Class

This C++ program defines classes for calculating the area and perimeter of a rectangle. The Rectangle class privately inherits from the Area and Perimeter classes to reuse their area and perimeter calculation methods. In main, a Rectangle object is created and user input is obtained for length and breadth. The area and perimeter are then calculated and output by calling the Rectangle object's methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Using Namespace Class

This C++ program defines classes for calculating the area and perimeter of a rectangle. The Rectangle class privately inherits from the Area and Perimeter classes to reuse their area and perimeter calculation methods. In main, a Rectangle object is created and user input is obtained for length and breadth. The area and perimeter are then calculated and output by calling the Rectangle object's methods.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include

#include <iostream>
using namespace std;
class Area
{
public:
float area_calc(float l,float b)
{
return l*b;
}
};
class Perimeter
{
public:
float peri_calc(float l,float b)
{
return 2*(l+b);
}
};
class Rectangle : private Area, private Perimeter
{
private:
float length, breadth;
public:
Rectangle() : length(0.0), breadth(0.0) { }
void get_data( )
{
cout<<"Enter length: ";
cin>>length;

cout<<"Enter breadth: ";


cin>>breadth;
}
float area_calc()
{
return Area::area_calc(length,breadth);
}
float peri_calc()
{
return Perimeter::peri_calc(length,breadth);
}
};
int main()
{
Rectangle r;
r.get_data();
cout<<"Area = "<<r.area_calc();
cout<<"\nPerimeter = "<<r.peri_calc();
return 0;
}

You might also like