Question

In: Computer Science

double maxArea(Rectangle a, Rectangle b, Rectangle c) {     double width;     double length;     double...

double maxArea(Rectangle a, Rectangle b, Rectangle c) {

    double width;
    double length;
    double area = 0;

    area = width * length;

    cout << "\n***maxArea called" << endl;     
    cout << "***       rectangleCount = " << Rectangle::rectangleCount << endl << endl;

  
}

Compete this code to find the maximum area of rectangle between a,b,c

Solutions

Expert Solution

#include <iostream>
class Rectangle{
    public:
        double width=0;
        double length=0;
        Rectangle(double length, double width){
            this->width = length;
            this->length = width;
        }
        void print(){
            std::cout<<length;
            std::cout<<width;
        }
};

double maxArea(Rectangle a, Rectangle b, Rectangle c) {

    double area_a = 0, area_b = 0, area_c = 0;
    double max_Area = 0;

    area_a = a.length * a.width;
    area_b = b.length * b.width;
    area_c = c.length * c.width;

    max_Area = area_a;
    if (area_b > max_Area) {
        max_Area = area_b;
    }
    if (area_c > max_Area) {
        max_Area = area_c;
    }

    if(area_a == max_Area)
        std::cout<<"Rectangle a has maximum area ";
    if(area_b == max_Area)
        std::cout<<"Rectangle b has maximum area ";
    if(area_c == max_Area)
        std::cout<<"Rectangle c has maximum area ";
    return max_Area;
}

int main(){
    Rectangle a (9000,20);
    Rectangle b (500,30);
    Rectangle c (40,50);
    std::cout<<maxArea(a,b,c)<<" sq unit.";
    return 0;
}


Related Solutions

using java Create a class Rectangle with attributes length and width both are of type double....
using java Create a class Rectangle with attributes length and width both are of type double. In your class you should provide the following: Provide a constructor that defaults length and width to 1. Provide member functions that calculate the area, perimeter and diagonal of the rectangle. Provide set and get functions for the length and width attributes. The set functions should verify that the length and width are larger than 0.0 and less that 50.0. Provide a member function...
A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased
For the following exercises, use the written statements to construct a polynomial function that represents the required information.A rectangle has a length of 10 inches and a width of 6 inches. If the length is increased by x inches and the width increased by twice that amount, express the area of the rectangle as a function of x.  
4. Define the width of a rectangle as the longest length of its sides. Given a...
4. Define the width of a rectangle as the longest length of its sides. Given a closed rectangle A in Rn and a partition P of A, define the mesh of P as the maximum width of its subrectangles. Prove that a bounded function f : A → R is integrable on A if and only if, for every > 0, there is a δ > 0 such that U(f, P) − L(f, P) < for every partition P of...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults...
(Rectangle Class) Create class Rectangle. The class has attributes length and width, each of which defaults to 1. It has read-only properties that calculate the Perimeter and the Area of the rectangle. It has properties for both length and width. The set accessors should verify that length and width are each floating-point numbers greater than 0.0 and less than 20.0. Write an app to test class Rectangle. this is c sharp program please type the whole program.
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width;...
I want to indent this c++ program #include<iostream> using namespace std; class Rectangle{ private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; double getPerimeter() const; bool isSquare() const; }; void Rectangle::setWidth(double w){ width = w; } void Rectangle::setLength(double l){ length = l; } double Rectangle::getWidth() const{ return width; } double Rectangle::getLength() const{ return length; } // Added Method definitions double Rectangle::getArea() const{ return (width * length); } double Rectangle::getPerimeter() const{...
Find the length and width of a rectangle whose perimeter is 21 meters and whose area...
Find the length and width of a rectangle whose perimeter is 21 meters and whose area is 20 square meters. Assign variables to the unknown(s)... Form a system of equations... Solve the system and state your answer in the context of the problem, show all steps clearly, be sure to check your answers:
a function named area to calculate the area of a rectangle area = Length x width...
a function named area to calculate the area of a rectangle area = Length x width 2.a function named volume to calculate the volume of a sphere volume = 4/3 x 3.14 x radius x radius x radius 3.a function named volume to calculate the volume of a cuboid volume = Length x width x ht 4. Use a loop structure to calculate the sum of all odd numbers from 1 to 17 5) Use a loop structure to calculate...
1. Write a class called Rectangle that maintains two attributes to represent the length and width...
1. Write a class called Rectangle that maintains two attributes to represent the length and width of a rectangle. Provide suitable get and set methods plus two methods that return the perimeter and area of the rectangle. Include two constructors for this class. One a parameterless constructor that initializes both the length and width to 0, and the second one that takes two parameters to initialize the length and width. 2. Write a java program (a driver application) that tests...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
Write the definition for a generic class called Rectangle that has data members length and width....
Write the definition for a generic class called Rectangle that has data members length and width. The class has the following member functions: setlength to set the length data member setwidth to set the width data member perimeter to calculate and return the perimeter of the rectangle area to calculate and return the area of the rectangle show to return a text to display the length and width of the rectangle sameArea that has one parameter of type Rectangle. sameArea...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT