Define a class named Rectangle with characteristics: Data members double field x and y that specifies the center of the rectangle. integer field...
View the step-by-step solution to:

Question

Define a class named Rectangle with characteristics:

 

  • Data

members

  • double field x and y that specifies the center of the rectangle.
  • integer field width and height of the rectangle.
  •  

    • Methods
    • The default constructor creates the default rectangle centered at (0,0) and width and height as 1.
    • Another parameterized constructor has 4 parameters representing x, y, height and width values.
    • getArea() - Returns area of rectangle.
    • getPerimeter() - Returns perimeter of rectangle.
    • contains(double x, double y) - returns true if the specified point (x,y) is inside the current rectangle.

     

    Input

       2.0

       2.0

       10

       16

       10.0

       7.0


       where,

    • First two lines represent value x and y respectively which is a center of the custom rectangle.
    • Third and fourth lines represent height and width of the custom rectangle respectively.
    • Fifth and sixth lines represent x and y coordinates of a point to be which is to be checked.

     

    Output

       4

       1

       true

       52

       160

       true


       where,

    • First three lines represent perimeter, area, and result of whether the point (0.5, 0.1) is inside the default rectangle. (this value will not change with change in test case)
    • Fourth and fifth lines represent perimeter and area, respectively, of the custom rectangle from user input.
    • Sixth line represents whether given point is inside the rectangle.





    #include <iostream>

    using namespace std;


    int main() 

    {

      

    }

    Top Answer

    Solution: #include&lt;iostream&gt; using namespace std; class Rectangle{ public: double x,y; int wid,ht;... View the full answer

    Sign up to view the full answer

    Why Join Course Hero?

    Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

    • -

      Study Documents

      Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

      Browse Documents
    • -

      Question & Answers

      Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

      Ask a Question