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

Just started this class and new to C++ using bew editor called CodeLite Write a

ID: 3781594 • Letter: J

Question

Just started this class and new to C++

using bew editor called CodeLite

Write a C++ program that will calculate and display the areas or some standard geometric figures. Specifically, the program needs to display the areas of the following geometric figures for length of side 1, 2, 3, 4, 5, and 6 (36 total results). You need to have a separate area function for each geometric figure. Each function needs to "protect itself" from a violation of its precondition. equilateral triangle square regular pentagon regular hexagon regular heptagon regular octagon

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;


double equi_triangle(double side)
{
   return 0.433*side*side; //sqrt(3)/4 = 0.433
}

double square(double side)
{
   return side*side;
}

double pentagon(double side)
{
   return 1.720*side*side; // sqrt(5(5+2*sqrt(5)))/4 = 1.720
}

double hexagon(double side)
{
   return 2.6*side*side;
}

double heptagon(double side)
{
   return 3.634*side*side; // (cot(180/7)*7)/4 = 3.634
}

double octagon(double side)
{
   return 4.828*side*side; // 2*(1+sqrt(2))/4 = 4.828
}

int main() {
   for(int i=1; i<=6; i++)
   {
       cout<<"SIDE : "<<i<<endl;
       cout<<"Area of equilateral traingle: "<<equi_triangle(i)<<endl;
       cout<<"Area of Square: "<<square(i)<<endl;
       cout<<"Area of regular pentagon: "<<pentagon(i)<<endl;
       cout<<"Area of regular hexagon: "<<hexagon(i)<<endl;
       cout<<"Area of regular heptagon: "<<heptagon(i)<<endl;
       cout<<"Area of regular octagon: "<<octagon(i)<<endl<<endl;
   }
   return 0;
}

OUTPUT: