Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question: In this assignment, you are asked to write the definition for a rectangle class and test it with the test program provided. The description

Question: In this assignment, you are asked to write the definition for a rectangle class and test it with the test program provided. The description of the rectangle class and the driver program are given on the attached file rectangle.cpp. Download the rectangle.cpp and without removing or changing any of the member functions or member variables of this class, complete 10 member functions bodies such that your program produces exact output as provided. You should keep the class definition and the main function in the same source file, and you are not allowed to use global variables. Your program should be well commented and in particular, begin with a series of comments specifying your name and lab number. (You should not change class definition or main function. Just complete the rest of the work.) rectangle.cpp below: #include using namespace std; class rectangle { public: rectangle(int len, int wid); //Parameterized Constructor rectangle(); //Default Constructor; Default lenght is 20 and default width is 10 void setWidth(int newWid); //Mutator function void setLength(int newLen);//Mutator function int getWidth() const;//Accessor function int getLength() const;//Accessor function void printRectangle(); //Print function int getArea();//Find Area; hint: Area is width * length int getPrimeter();//Find Perimeter; hint: Perimeter is (width + length)*2 bool equals(const rectangle& otherRectangle) const; //Comparison function private: int length; //variable to store length int width; //variable to store width }; //Start your class functions codes from here! // Driver program for the rectangle class int main() { rectangle s1; rectangle s2(5, 20); rectangle s3; //Display rectangles cout << "Rectangle s1 "; s1.printRectangle(); cout << "Rectangle s2 "; s2.printRectangle(); cout << "Rectangle s3 "; s3.printRectangle(); // Test Equality if (s1.equals(s2)) cout << "s1 and s2 are equal rectangle!" << endl; else cout << "s1 and s2 are unequal rectangle!" << endl; if (s1.equals(s3)) cout << "s1 and s3 are equal rectangle!" << endl; else cout << "s1 and s3 are unequal rectangle!" << endl; //Display area and perimeter cout << "Area of s1=" << s1.getArea() << endl; cout << "Area of s2=" << s2.getArea() << endl; cout << "Perimeter of s1=" << s1.getPrimeter() << endl; cout << "Perimeter of s2=" << s2.getPrimeter() << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Finance For Non Specialists

Authors: Dr Peter Atrill, Eddie McLaney

6th Edition

0273732757, 9780273732754

Students also viewed these Databases questions