Write a Pyramid class. For this program challenge, the pyramid is a right square pyramid, it has a square base and its four sides are isosceles triangles of equal dimensions. The class has the following member variables:
base — a double for the sides of the pyramid's base in feet
slant— a double for the slant height of all sides from the base to the apex in feet
The class should have the following member functions:
Default Constructor—a default constructor that sets base and slant to 0.0
Constructor that accepts the base and slant of the pyramid as arguments
setBase—a mutator function for the base variable
getBase—an accessor function for the base variable
setSlant—a mutator function for the slant variable
getSlant—an accessor function for the slant variable
getBaseArea—returns the base area of the pyramid, which is calculated as
baseArea = base * base
getFaceArea—returns the area of a face of the pyramid, which is calculated as
faceArea = base * slant * 0.5
getTotalArea—returns the total area of the pyramid, which is calculated as
totalArea = faceArea * 4 + baseArea
Write a program that demonstrates the Pyramid class by asking the user for the pyramid's base and the slant of the pyramid's sides, creates a Pyramid object, and then reports the pyramid’s surface area.
Validation: Values must be entered in the set functions. All values entered must be greater than zero. If a zero or negative value is entered, the user must be given two more attempts to enter a valid value. If the base value is invalid after the total of three attempts, provide the user with a message and exit the program. If the slant value is invalid after the total of three
attempts, provide the user with a message and exit the program.
#include <iostream>
#include "Pyramid.h"
#include <cstdlib>
using namespace std;
void heading();
double validate();
int main()
{
double pyramidSide,
pyramidRamp;
heading();
cout << "Enter the side measurement of square base (feet): ";
pyramidSide = validate();
if (pyramidSide > 0 && pyramidRamp > 0)
{
cout << "The total surface area of the pyramid is " << pyra.getTotalArea() << "square feet.";
}
else
{
cout << "Incorrect Data. Calculation cannot be completed." << endl;
}
system("pause")
return 0;
}
void heading()
{
cout << "This program calculates the surface area of a right square pyramid.\n\n"
<< "You will input 2 values in feet: the base's side and the slant measurement.";