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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
// enumerations need values set for return pointers
// from triangle identifier function, default would
// be 0-3, set different values?
// We need enumerations to prevent users from
// inputting stupid things like operations? Why would
// you do that?
// use 'if' function with specific return values for
// each type?
// Program could be easily expanded to include
// identifiers for special types of triangles
// and also ambigious cases
// angles can also be easily identified and could
// also be used as inputs for solving triangles
// Get a single function working first then expand
// May need to have a function to order inputs from
// smallest to largest
// Scalene parameters must be x < y < z, no value
// can be the same P.S. mindtap does not re-order
// its' inputs everytime so order does not matter for
// any situation
// Isosceles must have 2 equal sides, or x = y
// Equilaterals must have all 3 sides equal, x = y
// = z this function should be the easiest to code,
// start here, isosceles next probably but it really
// does not matter much once a triangle is identified
// No triangle would mean the sum of 2 sides is
// smaller than or equal to the length of the
// longest side,
// you cannot have the sums of the lengths of the
// two smaller sides equal to the longer because it
// creates a line and not a triangle
//
//
// It appears MindTap is inputting it's values in
// ascending order, program can be simpler that
// previously assumed, no ordering necessary
// order just because?
using namespace std;
// enum declarations?
enum triangleType {scalene, isosceles, equilateral, noTriangle};
// double or float? How accurate do I want it?
// Mintap does not care.
triangleType triangleShape(double x, double y, double z);
void printTriangleShape(triangleType shape);
int main()
{
double
x,y,z;
cout << "Enter first side: "<< endl;
cin >> x;
cout << "Enter second side: "<< endl;
cin >> y;
cout << "Enter third side: "<< endl;
cin >> z;
//Compiler refuses to recognize greek characters
triangleType O = triangleShape(x,y,z);
printTriangleShape(O);
return 0;
}
// function must return a triangle enum? WHY?
triangleType triangleShape(double x, double y, double z)
{
triangleType scalene, isosceles, equilateral, noTriangle;
// "if" statement probably needs to check if a triangle
// exists, if not, return noTriangle? Should this
// parameter be inside the triangle check or an "else if"
// statement outside of it if it fails triangle returns?
if (((x+y) > z) && ((x+z) > y) && ((y+z) > x))
{
if (x == y && y == z)
return equilateral;
else if (x == y || x == z || y == z)
return isosceles;
else if (x<y && y<z)
return scalene;
}
else if ((x+y) <= z || ((x+z) <= y) || ((y+z) <= x))
return noTriangle;
}
// print function of some sort, no return type
// needed, use void or something
void printTriangleShape(triangleType shape)
{
//Switch function to allow a cascade of conditions
//Consider a function work without a switch
//Smaller file size?
switch (shape)
{
case scalene: cout << "scalene" << endl;
break;
case isosceles: cout << "isosceles" << endl;
break;
case equilateral: cout << "equilateral!" << endl;
break;
case noTriangle: cout << "noTriangle"<< endl;
break;
}}
|