Design a class named Rectangle to represent a rectangle. The class contains: we
ID: 3550083 • Letter: D
Question
Design a class named Rectangle to represent a rectangle. The class contains:
we have to make 3 files header file , one .cpp file for function and one more main cpp file
Design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. A constructor that creates a rectangle with the specified width and height. The accessor and mutator functions for all data fields. They are: A function named setWidth that sets the value of the data field width. A function named setHeight that sets the value of the data field height. A function named getWidth that returns the value of the data field width. A function named getHeight that returns the value of the data field height. A function named getArea that returns the area of this rectangle. A function named getPerimeter that returns the perimeter of this rectangle. Write a header file containing the class definition and a C++ program containing the functions for the class. Write a test program testing the class. This test program will create a Rectangle object, assign width 4 and height 40 to the object, and display the properties of the object (its width, height, area, and perimeter).Explanation / Answer
#include<iostream.h>
class rectangle
{
float width, height;
public:
rectangle()
{width=0;
breadth=0;
}
void setWidth(float a)
{width=a;
}
void setwHeight(float b)
{width=b;
}
float getWidth()
{return width;}
float getHeight()
{return height;}
float getArea()
{return width*height;}
float getPerimeter()
{return 2*(width+height);}
};
void main()
{rectangle a;
a.setWidth(4);
a.setHeight(40);
cout?
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.