Public feed
#380629
#include <iostream>
using namespace std;
#include<cmath>
#include <cstring>
int main()
{
cout<<"enter length of the square base ";
double length; cin >> length;
cout<<"height of pyramid ";
double height; cin>>height;
cout<<"please enter units of the above measurements= ";
string str; cin>>str; getline (cin, str);
cout<<"inches";
double triangle_height = sqrt(pow(height, 2) + pow(length/2, 2));
double triangle_area = 0.5*length*triangle_height;
double pyramid_area = 4*triangle_area + length*length;
//area calculated, now output
cout<<"enter length of the base square= "<<length<<str<<'\n';
cout<<"height of pyramid = "<<height<<str<<'\n';
// calculation n display of results without using functions.
cout<<"surface area of the pyramid = "<<pyramid_area<<str<<"^2"<<'\n';
//functions are now used.
double Area (double, double);
cout<<"surface area of the pyramid = "<<Area(length,
height)<<str<<"^2"<<'\n';
return 0;
}
//definition of function
double Area (double Length, double Height)
{
double Triangle_height = sqrt(pow(Height, 2) + pow(Length/2, 2));
double result= 4*(0.5*Length*Triangle_height) + Length*Length;
return result;
}