Write a C++ program to calculate the area and perimeters of rectangles using the concept of Inheritance Create a 3 classes Rectangle, Area and Perimeter. Here, classes Area and Perimeter are derived from the class Rectangle. Thus, the object of a derived class can access the public members of the Rectangle. When objects of class Area and Perimeter are created, the constructor in the base class is automatically called. If there was public member function in base class then, those functions also would have been accessible for objects a and p. Sample Input and Output: Enter length of the rectangle: 10 Enter breadth of the rectangle: 5 Area of rectangle: 50 Enter length of the rectangle: 6 Enter breadth of the rectangle: 2 Perimeter of rectangle: 16
Write a C++
Create a 3 classes Rectangle, Area and Perimeter. Here, classes Area and Perimeter are derived from the class Rectangle. Thus, the object of a derived class can access the public members of the Rectangle. When objects of class Area and Perimeter are created, the constructor in the base class is automatically called. If there was public member function in base class then, those functions also would have been accessible for objects a and p.
Sample Input and Output:
Enter length of the rectangle: 10
Enter breadth of the rectangle: 5
Area of rectangle: 50
Enter length of the rectangle: 6
Enter breadth of the rectangle: 2
Perimeter of rectangle: 16
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images