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 130 131 132 133 134 135 136 137 138 139
|
#include <iostream>
#include <math.h>
#include <string>
//pyth.cpp
//a^2+b^2=c^2 -- The Pythagorean Theorem
//This C++ program takes information inputted about a triangle, and using the Pythagorean Theorem:
//Either solves for a, b, or c, and displays properties about a simulated triangle with those variables
//For example, we would find and output the area, perimeter, etc. of that triangle
//I would say to credit this if you used it in your schoolwork, but you probably won't anyway
//I do accept payment, donations, and gifts of appreciation in the form of money and women
//(c)2012 Ty K.
using namespace std;
string AskIfGoAgain(){
int loop = 1;
string answer = "y";
while (loop == 1){
answer = "y";
cout << "\nWould you like to calculate another triangle? [y]/[n]";
cin >> answer;
if (answer == "y"){return answer;}
else if (answer == "n"){return answer;}
else {
cout << "\n That wasn't even an option. Seriously?";
}
}
}
int SolveForA(){
float b, c, bSquared, cSquared, a;
//Initializes the variables
float area, perimeter;
//Initializes the other properties we are going to find when we simulate the triangle
cout << "What is b?";
cin >> b;
//Prompts user to input b
cout << "\nWhat is c?";
cin >> c;
//Promts user to input c
bSquared = b*b;
cSquared = c*c;
//Finds each variable's square.. if that makes grammatical/syntactical sense
a = cSquared - bSquared;
//Finds a
cout << "\na = ";
cout << a;
//Tells you what A is
area = (a + b) / 2;
perimeter = a + b + c;
cout << "\n Perimeter: ";
cout << perimeter;
cout << "\n Area: ";
cout << area;
//Simulates the triangle and outputs the area and the perimeter
cout << "\n\nThank you for using one of my programs! And remember, thanks can be expressed in money and women!";
return 0;
}
int SolveForB(){
float b, c, bSquared, cSquared, a;
//Initializes the variables
float area, perimeter;
//Initializes the other properties we are going to find when we simulate the triangle
cout << "What is a?";
cin >> a;
//Prompts user to input a
cout << "\nWhat is c?";
cin >> c;
//Promts user to input c
aSquared = a*a;
cSquared = c*c;
//Finds each variable's square.. if that makes grammatical/syntactical sense
b = cSquared - aSquared;
//Finds a
cout << "\nb = ";
cout << b;
//Tells you what A is
area = (a + b) / 2;
perimeter = a + b + c;
cout << "\n Perimeter: ";
cout << perimeter;
cout << "\n Area: ";
cout << area;
//Simulates the triangle and outputs the area and the perimeter
cout << "\n\nThank you for using one of my programs! And remember, thanks can be expressed in money and women!";
return 0;
}
int SolveForC(){
float a, b, c, aSquared, bSquared, cSquared;
//Initialize the variables we will be using in this function
float area, perimeter;
//Initialize the variables of the properties of the triangle we will simulate
cout >> "\nWhat is a?: ";
cin << a;
cout >> "\nWhat is b?: ";
cin << b;
//Prompts for and gets input for a and b
aSquared = a*a;
bSquared = b*b;
//Finds the squares of a and b
cSquared = aSquared + bSquared;
c = sqrt(cSquared);
//Finds c
cout << "\nc: ";
cout c;
//outputs c
area = (a*b)/2;
perimeter = a + b + c;
cout << "\nPerimeter: ";
cout perimeter;
cout << "\nArea: ";
cout area;
//Simulates the triangle and finds the value of those properties
}
int main(answer){
answer = "y"
while (answer == "y"){
float choice;
cout << "Would you like to solve for [a], [b], or [c]?: ";
cin >> choice;
if (choice == "a"){
SolveForA();
AskIfGoAgain();
}
else if (choice == "b"){
SolveForB();
AskIfGoAgain();
}
else if (choice == "c"){
SolveForC();
AskIfGoAgain();
else {
cout << "That wasn't even an option. Seriously?";
}
}
return 0;
}
|