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

C++ programming - Area of Triangle Write a c++ program that computes the area of

ID: 657003 • Letter: C

Question

C++ programming - Area of Triangle
Write a c++ program that computes the area of a triangle using appropriate formula depending on the various inputs:
1. Base and height
2. Three sides
3. Two sides and included angle
Use user-defined functions for each case. These functions will have different numbers or types of input parameters.
double Area1(double, double);
double Area2(double, double, double);
double Area3(double, double, int);
Remember to validate user inputs for each case. For instance, length of any side must not be negative. For three sides given, one side must not be greater than or equal to the sum of the other two sides. For two sides and included angle, angle must be smaller than 180 degree. Note that C++ math library sine function, sin() takes radian as input rather than degree. User will enter it as degree (integer), but your program converts it to radian.
Allow user to repeat the calculation as many times as they wish.

Explanation / Answer

#include <cmath>
#include <iostream>
using namespace std;

int main()
{
   int area, perimeter, s;

   //This block must go after all definitions and cin but before the cout for area.
   perimeter=A+B+C; //I dropped the quotes here
   s= perimeter/2;
   area= sqrt(s*(s-A)*(s-B)*(s-C)); // I dropped the quotes here

   //Move this block to the start of main. The variables must be defined before they are set or used.
   double s;
   double A, B, C; //I dropped the quotes here
   double area;

   //Move this section to a spot in the function after you've declared A,B,C but before you calculate perimeter, s and area.
   cout << "This program calculates the area of a triangle";
   cout << "What is the length of side A, B, and C, respectively?";
   cin >> A >> B >> C; // Use the >> operator to get several values in a row.

   //This part is correct.
   cout << "The area of the triangle is " << area << ". ";
   return 0;
}

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