# Answer to Question #19207 in C++ for Shaza

Question #19207
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;
1
2012-11-21T09:44:47-0500
#pragma once
class MyTriangle
{
public:
MyTriangle(void);
~MyTriangle(void);
// 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);
};

#include "StdAfx.h"
#include "MyTriangle.h"
#include <math.h>

MyTriangle::MyTriangle(void)
{
}

MyTriangle::~MyTriangle(void)
{
}
bool MyTriangle::isValid(double side1, double side2, double side3){
bool flag=false;
if((side1+side2)>side3)
flag = true;
else if((side2+side3)>side1)
flag = true;
else if((side1+side3)>side2)
flag = true;
else
flag = false;
return flag;
}

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

// MyTriangleApplication.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include "MyTriangle.h"

int main()
{
MyTriangle myTriangle;
if(myTriangle.isValid(5,3,4)){
printf("Area= %f",myTriangle.area(5,3,4));
}
int k;
scanf("%d",&k);

return 0;
}

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!