multiple inheritance
Title
Question
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 12.6px; white-space-collapse: preserve; background-color: rgb(249, 249, 249);">Create a class area and perimeter Find the area and perimeter of a rectangle</span>
Advanced-Cpp More-On-Inheritance 07-08 min 10-20 sec
Answers:
Here, Rectangle should be a class, and member functions should be area and perimeter.
#include <iostream>
using namespace std;
class Rectangle {
double length, width;
public:
void setData(double l, double w) {
length = l;
width = w;
}
void Area() {
cout << "Area: " << length * width << endl;
}
void Perimeter() {
cout << "Perimeter: " << 2 * (length + width) << endl;
}
};
int main() {
Rectangle r;
r.setData(5, 3);
r.Area();
r.Perimeter();
return 0;
}
This will print the area and perimeter of the rectangle.
Login to add comment