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

Please help me with the last step of this code, i cant quite get it! Add two con

ID: 3547277 • Letter: P

Question

Please help me with the last step of this code, i cant quite get it!


Add two constructors and a destructor to the class and create the implementation of each. One constructor is the default constructor that sets the side to 1. The other constructor will allow the user to initialize the side at the definition of the object. The destructor does not have to do anything but reclaim memory space. Create an object called box1 that gives the value of 9 to the constructor at the definition. Add output statements so that the following is printed in addition to what is printed in Exercise 1.


Here's what i have...


#include <iostream>
using namespace std;

// FILL IN THE CODE TO DECLARE A CLASS CALLED Square.  TO DO THIS SEE
// THE IMPLEMENTATION SECTION.

class Square
{

private:

    float length;
     float side;

public:

    Square(float side);
    Square();
    ~Square();
    
    void  SetSide(float);
     float findArea();
     float findPerimeter();
};

int main()
{

    

    Square  box1(9);
    Square  box;          // box is defined as an object of the Square class
    float   size;         // size contains the length of a side of the square  

   //cout << "Please input the length of the side of the square ";    // FILL IN THE CLIENT CODE THAT WILL ASK THE USER FOR THE LENGTH OF THE SIDE
   //cin >> size;                                // OF THE SQUARE.  (This is stored in size)
    
   box1.SetSide(size);    // FILL IN THE CODE THAT CALLS SetSide.

   float Area = box1.findArea();    // FILL IN THE CODE THAT WILL RETURN THE AREA FROM A CALL TO A FUNCTION
   cout << "The area of the square is " << Area << endl;                    // AND PRINT OUT THE AREA TO THE SCREEN

   float peri = box.findPerimeter();    // FILL IN THE CODE THAT WILL RETURN THE PERIMETER FROM A CALL TO A
   cout << "The perimeter of the square is " << peri << endl;                // FUNCTION AND PRINT OUT THAT VALUE TO THE SCREEN

   char ch;        // Used for output
   std::cin >> ch;

    return 0;
}




//     Implementation section     Member function implementation    
//__________________________________________________________________



//*************************************************************
//            Square Constructor
//
// task:   This member function of the class Square creates a constructor that sets the length equal to side_1.
// data in: None (uses default value of 1)
// data out: Declaration of length set to 9
//
//*******************************************************************
Square::Square(float side)
  {
    side = length;
  }


//*******************************************************************
//            Square Default Constructor
//
// task: This function of the class Square is the default constructor that sets the of Square to 1
//
// data in: None
// data out: Length is declared as side and set to default value of 1.
//*******************************************************************
Square::Square()
  
  {
    length = 1;
  }



//*************************************************************
//            Square Destructor
//
// task: Reclaim memory space
// data in: Data for Square in the Square class
// data out: none, object destroyed
//**************************************************************8
Square::~Square()
{
}




//**************************************************
//                  setSide
//
// task:    This procedure takes the length of a side and
//          places it in the appropriate member data
// data in: length of a side
//***************************************************

void Square::SetSide(float length)

{
   side = length;    
}
//**************************************************
//                 findArea
//
// task:    This finds the area of a square
// data in: none (uses value of data member side)
// data returned:  area of square
//***************************************************

float Square::findArea()
{
   return side * side;
}
//**************************************************
//                 findPerimeter
//
// task:    This finds the perimeter of a square
// data in: none (uses value of data member side)
// data returned:  perimeter of square
//***************************************************    
float Square::findPerimeter()
{
   return 4 * side;
}






Explanation / Answer

#include <iostream>
using namespace std;
// FILL IN THE CODE TO DECLARE A CLASS CALLED Square. TO DO THIS SEE
// THE IMPLEMENTATION SECTION.
class Square
{
private:
//float length;
float side;
public:
Square(float side);
Square();
~Square();
void SetSide(float);
float findArea();
float findPerimeter();
};
int main()
{
Square box1(9);
Square box; // box is defined as an object of the Square class
float size; // size contains the length of a side of the square
//cout << "Please input the length of the side of the square "; // FILL IN THE CLIENT CODE THAT WILL ASK THE USER FOR THE LENGTH OF THE SIDE
//cin >> size; // OF THE SQUARE. (This is stored in size)
//box1.SetSide(size); // FILL IN THE CODE THAT CALLS SetSide.
float Area = box1.findArea(); // FILL IN THE CODE THAT WILL RETURN THE AREA FROM A CALL TO A FUNCTION
cout << " The area of the square is " << Area << endl; // AND PRINT OUT THE AREA TO THE SCREEN
float peri = box1.findPerimeter(); // FILL IN THE CODE THAT WILL RETURN THE PERIMETER FROM A CALL TO A
cout << "The perimeter of the square is " << peri << endl; // FUNCTION AND PRINT OUT THAT VALUE TO THE SCREEN
char ch; // Used for output
std::cin >> ch;
return 0;
}
// Implementation section Member function implementation
//__________________________________________________________________
//*************************************************************
// Square Constructor
//
// task: This member function of the class Square creates a constructor that sets the length equal to side_1.
// data in: None (uses default value of 1)
// data out: Declaration of length set to 9
//
//*******************************************************************
Square::Square(float side)
{
this->side = side;
}
//*******************************************************************
// Square Default Constructor
//
// task: This function of the class Square is the default constructor that sets the of Square to 1
//
// data in: None
// data out: Length is declared as side and set to default value of 1.
//*******************************************************************
Square::Square()
{
side = 1;
}
//*************************************************************
// Square Destructor
//
// task: Reclaim memory space
// data in: Data for Square in the Square class
// data out: none, object destroyed
//**************************************************************8
Square::~Square()
{
}
//**************************************************
// setSide
//
// task: This procedure takes the length of a side and
// places it in the appropriate member data
// data in: length of a side
//***************************************************
void Square::SetSide(float length)
{
side = length;
}
//**************************************************
// findArea
//
// task: This finds the area of a square
// data in: none (uses value of data member side)
// data returned: area of square
//***************************************************
float Square::findArea()
{
return side * side;
}
//**************************************************
// findPerimeter
//
// task: This finds the perimeter of a square
// data in: none (uses value of data member side)
// data returned: perimeter of square
//***************************************************
float Square::findPerimeter()
{
return 4 * side;
}


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