Help would definitely be appreciated! The problem is:
Three numbers are sides of a triangle if all numbers are positive and the sum of any two sides is longer than the remaining side. A triangle could be:
1 equilateral (if all three sides are equal)
2 isosceles (if any two sides are equal)
3 scalene (if none of the three sides are equal)
Write a program that inputs 5 sets of three potential sides (double data type). For each set of data, the main function calls the following three functions having the prototypes:
bool isTriangle (double, double, double);
void getType (double, double, double);
double getArea (double, double, double);
The isTriangle function returns true if the corresponding set of three numbers could be sides of a triangle or false if they do not make a triangle. If the three sides do not make a triangle, the main function must display “Not a triangle” and get the next set of data.
If they form a triangle, then the main function calls the getType function. The getType function has to determine the type of the triangle and prints one of the following messages:
• This is a scalene triangle!
• This is an isosceles triangle!
• This is an equilateral triangle!
In the end the main function calls the area function to calculate and print the area of the triangle.
Hint: To calculates the area s of a triangle use the following formula:
s = (p x(p-a) x (p-b) x (p-c))1/2, where p = (a + b + c)/2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// It uses three value returning functions
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototypes
// function that will check if values are a triangle.
bool isTriangle (double, double, double);
// function that will specify what the triangle is.
void getType (double, double, double);
// function will get area of the triangle.
double getArea (double, double, double);
double piece (double, double, double);
int main()
{
double a, b, c, s;
double tR;
double piece;
cout << "Enter three sides of a triangle." << endl;
cin >> a >> b >> c;
tR = isTriangle (a, b, c);
cout << "These sides represent your triangle." << endl;
}
bool isTriangle (double a, double b, double c)
{
if ( a < 0 && b < 0 && c < 0)
return false;
else
return true;
}
void getType (double a, double b, double c)
{
if (a == b && b == c)
cout << "This is an equilateral triangle!" << endl;
else if (a == b || b == c || a == c)
cout << "This is an isosceles triangle!" << endl;
else
cout <<"This is a scalene triangle!" << endl;
}
double piece (double a, double b, double c)
{
return (a + b + c)/2;
}
double getArea (double a, double b, double c)
{
return (piece(a,b,c)*(piece(a,b,c) - a)*(piece(a,b,c) - b)*(piece(a,b,c)-c))* 1.5;
}
|
I know I'm way off. I just wanted to see if I could get one set of numbers in there. The problem I'm having is making sets of numbers. He saying that there should be 5 sets of 3 numbers. Should I make them strings? Or should it be a switch? I'm lost when it comes to that point. Any input?