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
|
#include<iostream>
using namespace std;
//Enumerated datatype
enum typeOfTriangle {scalene,isosoceles,equilateral,noTriangle};
//Enumerated variable
typeOfTriangle typeTriangle;
//Function Prototypes
void getLengths(int& side1,int& side2,int& side3);
void determineShape(int side1,int side2,int side3,typeOfTriangle& typeTriangle);
void displayShape(typeOfTriangle typeTriangle);
int main()
{
do{
//variables
int side1,side2,side3;
//Function Calls
getLengths(side1,side2,side3);
determineShape(side1,side2,side3,typeTriangle);
displayShape(typeTriangle);
cout << "Do you wish to quit?(Y or N): ";
cin >> response;
response = toupper(response);
while } (response == 'N');
system("PAUSE");
return 0;
}
//Get Length function
void getLengths(int& side1,int& side2,int& side3)
{
cout << "Enter side 1: ";
cin >> side1;
cout << "Enter side 2: ";
cin >> side2;
cout << "Enter side 3: ";
cin >> side3;
}
//Determine Triangle shape function
void determineShape(int side1,int side2,int side3,typeOfTriangle& typeTriangle)
{
if (side1 + side2 < side3 || side2+side3<side1 || side1 + side3 < side2)
typeTriangle = noTriangle;
else if (side1 == side2 && side2 == side3)
typeTriangle = equilateral;
else if (side1 == side2 || side2 == side3 || side1 == side3)
typeTriangle = isosoceles;
else if (side1 != side2 && side2 != side3)
typeTriangle = scalene;
}
//Display shape function
void displayShape(typeOfTriangle typeTriangle)
{
switch(typeTriangle)
{
case noTriangle:
cout << "Not a valid triangle" << endl;
break;
case equilateral:
cout << "equilateral" << endl;
break;
case scalene:
cout << "scalene" << endl;
break;
case isosoceles:
cout << "isosoceles" << endl;
break;
}
}
|