63 132
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #19289 in C++ for vicky

Question #19289
Create a header file named MyTriangle.h that contains the following two functions:

// return true if the sum of any two sides is greater than the third side//
bool isValid( double side1, double side2, double side3)
//Return the area of a triangle//
double area (double side1, double side2, double side3)

Implement the header file and write a test program that reads three sides of a triangle and compute the area if the input is valid. Otherwise display the input is invalid.
The formula is as follows:
s = (side1 + side2 + side3) / 2;
area = √(s (s-side1)(s-side2)(s-side3))

Expert's answer
#include <stdio.h>
#include <iostream.h>
#include <math.h>

bool isValid( double side1, double side2, double side3){
if (side3<side1+side2) return 1;
else return 0;
}

double area (double side1, double side2, double side3){
double s = (side1 + side2 + side3) / 2;
return sqrt((s*(s-side1)*(s-side2)*(s-side3)));
}

void main(){
double s1, s2, s3;
cout<<"enter the first side: ";
cin>>s1;
cout<<"enter the second side: ";
cin>>s2;
cout<<"enter the third side: ";
cin>>s3;
if (isValid(s1,s2,s3))
& cout<<area(s1,s2,s3)<<"\n";
else cout<<"input is invalid\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions