Suppose we have a class Rectangle which has two data members, length and width. In addition, there should be a static variable, namely allRectanglesTotalArea which stores the area of all the Rectangles created. Furthermore, there should be a function named calcRectangleArea() which calculates the area of rectangle and adds it to the allRectanglesTotalArea. Write a static function nameddisplayAllRectanglesTotalArea()which displays the value of allRectanglesTotalArea.
Language : C++
Subject : OOP
Suppose we have a class Rectangle which has two data members, length and width. In addition, there should be a static variable, namely allRectanglesTotalArea which stores the area of all the Rectangles created. Furthermore, there should be a function named calcRectangleArea() which calculates the area of rectangle and adds it to the allRectanglesTotalArea. Write a static function nameddisplayAllRectanglesTotalArea()which displays the value of allRectanglesTotalArea.
The main function of the program should look like the following.
intmain()
{
Rectangle r1(5.0,4.0);
r1.calcRectangleArea();
Rectangle r2(2.5,4.0);
r2.calcRectangleArea();
Rectangle::displayAllRectanglesTotalArea();
return 0;
}
Step by step
Solved in 3 steps with 1 images