Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will design and implement 2 classes; a service program and a client program.

ID: 3767895 • Letter: Y

Question

You will design and implement 2 classes; a service program and a client program. The Rectangle program holds the attributes of a rectangle including its length, width, calculated area and color. The Box program will host the main method and instantiate a rectangle and adjust its length.

For Rectangle: 1-create the length, width, area, and color instance variables, (color can be the name of a String object)

2-create a constructor method to accept the length, width, color.

3-create a length setter method to allow the length to be set independently.

4-create a toString which first calculates the area (=LxW) and then returns a phrase that //includes the color and the area.

For Box: 1- Instantiate a new Rectangle called box1 by defining its length, width, color.

2- Print out its color and area by using the return from the toString.

3- Prompt the user for a new length.

4- Print out the color with the new area.

Your output of the Box program should look like: You had a blue box with an area of 300 Inches Enter the new length. You now have a blue box with an area of 240 Inches

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

class Rectangle{
   private:

   public:
       int len, breadth; string c;
       Rectangle(){

       }
       Rectangle(int l, int b, string color){
           len = l;
           breadth = b;
           c = color;
       }

       void toString(){
           string res;
           //cout << "The area of box is: " << len*breadth << " " << "of color: " << c<< endl;
           cout << "You now have a " << c << " box with area " << len*breadth << endl;
       }

       void setLen(int l){
       l = l;
       }

};

class Box{

   public:
       int l, b; string color;
       Box(){
           cout << "You had a blue box with an area of 300 " << endl;
           cout << "Input Enter new length: ";
           cin >> l;
           cout << "Enter new breadth: ";
           cin >> b;
           cout << "Enter new color: ";
           cin >> color;
           Rectangle* newObj = new Rectangle(l,b,color);
           newObj->toString();
       }
  
};

int main()
{
   Box();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote