LESSON 13A Lab 131 Squares as a Class Retrieve program squar
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


