Triangle.h: //File Triangle.h -- Triangle functions //if header file not defined
ID: 3633575 • Letter: T
Question
Triangle.h://File Triangle.h -- Triangle functions
//if header file not defined then define
#ifndef TRIANGLE_H
//define TRIANGLE_H
#define TRIANGLE_H
//header file to do I/O operations
#include
using namespace std;
/* Returns 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 the triangle. */
double area(double side1, double side2, double side3);
#endif
Triangle.cpp:
#include "stdafx.h"
#include
bool 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;
}
Explanation / Answer
Dear, In the question you have not given the main function. In the pseudo code I included the main function also. You can ignore the pseudo code of main function if you don’t need it. The pseudo code for functions remains same. Pseudo code: begin: Declaration num s1,s2,s3 //read input output "Enter the value of Side 1 of the triangle : " input s1 output "Enter the value of Side 2 of the triangle : " input s2 output "Enter the value of Side 3 of the triangle : " input s3 //calling function to validate the input if (isvalid(s1,s2,s3)) //calling function area output "Area of the triangle : ", area(s1,s2,s3) else output "Invalid input. " stop //function isvalid takes three arguments isvalid(num a, num b, num c) Declaration boolean flag if(side1+side2 > side3) flag = true; else if(side2+side3 > side1) flag = true; else if(side1+side3 > side2) flag = true else flag = false //return input is valid or not return flag //function area takes three arguments and returns its area area(num a, num b, num c) Declaration num s num area //compute value of ‘s’ s = a + b + c /2 //compute the area of triangle area = sqrt(s*(s – a)*(s - b)*(s - c)); //return area return area Hope this would help you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.