LESSON 13A Lab 131 Squares as a Class Retrieve program squar

LESSON 13A Lab 13.1 Squares as a Class Retrieve program square.epp from the Lab 13 folder The code is as follows: This program declares the square class and uses member tunctions to find the perimeter and area of the square include ciostrean> using namespace stdi PILL IN THE coDE TO DECLARE A CLASS CALLED Square To DO THIS SEE THE IMPLEMENTATION SECTION. int nain square boxr box is defined as an object of the square class float sizer size contains the length of a side of the square FILL THE CLIENT coDE TRAT wILL ASK THE USER FOR THE LENGTH OF THE IN SIDE OF THE souARE. (This is stored in size FILL IN THE CoDE THAT CALLs sotside. FILL IN THE THAT WILL RETURN THE AREA FROM A CALL To A FUNCTION coDE AND PRINT OUT THE AREA To THE scREEN. FILL IN THE CoDE THAT WILL RETURN THE PERIMETER FROM A CALL TO A FUNCTION AND PRINT OUT THAT vALUE TO THE scREEN. return 0; Implementation section Member function implementation 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; continues

Solution

#include<iostream>
using namespace std;

class Square
{int side;
public:
   Square();
   Square(float);
   ~Square();
   float findArea();
   float findPerimeter();
   void setSide(float);
  

};
Square::Square()
{
   side=1;
}
Square::~Square()
{
  
}
Square::Square(float length)
{
   side=length;
}
void Square::setSide(float length)
{
   side=length;
}
float Square::findPerimeter()
{
   return 4*side;
}

float Square::findArea()
{
   return side*side;
  
}
int main(int argc, char const *argv[])
{
   Square box;
   float size;
  
   cout<<\"Please input the side of square\ \";
   cin>>size;

   box.setSide(size);
   cout<<\"The area of square is \"<<box.findArea()<<endl;
   cout<<\"The perimeter of square is \"<<box.findPerimeter()<<endl;

   Square box1;

   box1.setSide(size);
   cout<<\"The area of box1 is \"<<box1.findArea()<<endl;
   cout<<\"The perimeter of box1 is \"<<box1.findPerimeter()<<endl;
   /* code */
   return 0;
}

============================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ square.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
Please input the side of square
8
The area of square is 64
The perimeter of square is 32
The area of box1 is 64
The perimeter of box1 is 32

 LESSON 13A Lab 13.1 Squares as a Class Retrieve program square.epp from the Lab 13 folder The code is as follows: This program declares the square class and us
 LESSON 13A Lab 13.1 Squares as a Class Retrieve program square.epp from the Lab 13 folder The code is as follows: This program declares the square class and us

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site