Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// This program declares the Square class and uses member functions to find // the perimeter and area of the square // PLACE YOUR NAME

image text in transcribed
// This program declares the Square class and uses member functions to find
// the perimeter and area of the square
// PLACE YOUR NAME HERE
#include
using namespace std;
// FILL IN THE CODE TO DECLARE A CLASS CALLED Square. TO DO THIS SEE
// THE IMPLEMENTATION SECTION.
int main()
{
Square box; // box is defined as an object of the Square class
float size; // size contains the length of a side of the square
// FILL IN THE CLIENT CODE THAT WILL ASK THE USER FOR THE LENGTH OF THE
// SIDE OF THE SQUARE. (This is stored in size)
// FILL IN THE CODE THAT CALLS SetSide.
// FILL IN THE CODE THAT WILL RETURN THE AREA FROM A CALL TO A FUNCTION
// 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;
}
//**************************************************
// 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;
}
image text in transcribed
Exercise 1: This program asks you tofl in the class declaration and client code based on the implementation of the member functions. Fill in the code so that the following input and outputl be generated: Please input the length of the side of the square The area of the square is 64 The perimeter of the square is 32 Exercise 2: 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 The area of box1 is 81 The perimeter of box1 is 36

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions