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

Complete a program that uses the Square class shown in Figure 15-6 in the chapte

ID: 3580061 • Letter: C

Question

Complete a program that uses the Square class shown in Figure 15-6 in the chapter. Follow the instructions for starting C++ and viewing the Introductory 13.cpp file, which is contained in either the Cpp8Chap15Introductory13 Project folder or the Cpp8Chap15 folder. (Depending on your C++ development tool, you may need to open this exercise's project/solution file first.) Enter the Square class definition from Figure 15-6 in the Introductory 13 Square.h file. Next, complete the Introductory 13.cpp file by entering the appropriate instructions. Use the comments as a guide. Test the program appropriately.//Introductory13.cpp - displays the area of a square//Created/revised by on #include using namespace std; int main() {//instantiate a Squarer object//declare variable//get the measurement of one side of the squarer//assign the side measurement to the squarer object//display the area of the square return 0;}//end of main function

Explanation / Answer

#include <iostream>

using namespace std;
class Square{
private:
double side;
public:
Square(){
  
}
double getSide(){
return side;
}
void setSide(double s){
side = s;
}
double getArea(){
return side * side;
}
};
int main()
{
Square s;
double side;
cout << "Enter the side: ";
cin >> side;
s.setSide(side);
cout<<"Area is "<<s.getArea()<<endl;

return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                           

Enter the side: 4                                                                                                                                                                                                                                      

Area is 16

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