Skip to content

Instantly share code, notes, and snippets.

@aeshthetic
Created July 28, 2017 23:59
Show Gist options
  • Save aeshthetic/045340fab0d85dbfa202fd546dd5317f to your computer and use it in GitHub Desktop.
Save aeshthetic/045340fab0d85dbfa202fd546dd5317f to your computer and use it in GitHub Desktop.
One of the first (and ugliest) pieces of code i've ever written (not really something I'm proud of), whether it runs is beyond me.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//Functions
//GeoCalc Functions
float cylinderVolume(float rad, float hei){
float cylVol;
float radSqr;
radSqr = rad * rad;
cylVol = 3.14159265359 * radSqr * hei;
cout << cylVol << "\n";
return cylVol;
}
float cylinderSurfaceArea(float rad, float hei){
float cylSA;
float radSqr = rad * rad;
cylSA = (2 * 3.14159265359 * rad * hei ) + (2 * 3.14159265359 * radSqr);
cout << cylSA << "\n";
return cylSA;
}
float sphereVolume(float rad){
float spherVol;
float radCb = rad*rad*rad;
spherVol = 1.33333333333 * 3.14159265359 * radCb;
cout << spherVol << "\n";
return spherVol;
}
float sphereSurfaceArea(float rad){
float spherSA;
spherSA = 4 * 3.14159265359 * rad * rad;
cout << spherSA << "\n";
return spherSA;
}
float coneVolume(float rad, float hei){
float coneVol;
coneVol = (3.14159265359 * rad * rad * hei)/3;
cout << coneVol << "\n";
return coneVol;
}
float coneSurfaceArea(float rad, float len){
float coneSA;
coneSA = (3.14159265359 * rad * len) + (3.14159265359 * rad * rad);
cout << coneSA << "\n";
return coneSA;
}
float circumference(float radC){
float circ;
float pi = 3.14;
circ = 2*pi*radC;
cout << circ << "\n";
return circ;
}
bool isRight(float lenAsqr, float lenBsqr, float lenCsqr){
bool isRightTriangle;
if (lenAsqr + lenBsqr == lenCsqr){
isRightTriangle = true;
cout << "This is a right triangle\n";
}
else{
isRightTriangle = false;
cout << "This is not a right triangle\n";
}
return isRightTriangle;
}
float pythagoreB(float lengthA, float lengthC){
float lengthASqr;
float lengthBSqr;
float lengthCSqr;
float lengthB;
lengthCSqr = lengthC*lengthC;
lengthASqr = lengthA*lengthA;
lengthBSqr = lengthCSqr-lengthASqr;
lengthB = sqrt(lengthBSqr);
cout << lengthB << "\n";
return lengthB;
}
float pythagoreA(float lengthB, float lengthC){
float lengthASqr;
float lengthBSqr;
float lengthCSqr;
float lengthA;
lengthCSqr = lengthC*lengthC;
lengthBSqr = lengthB*lengthB;
lengthASqr = lengthCSqr-lengthBSqr;
lengthA = sqrt(lengthASqr);
cout << lengthA << "\n";
return lengthA;
}
float pythagore(float legA, float legB){
float csqr;
float asqr;
float bsqr;
asqr = pow(legA, 2);
bsqr = pow(legB, 2);
float hyp;
csqr = asqr + bsqr;
hyp = sqrt(csqr);
cout << hyp << "\n";
return hyp;
}
float volume(float L, float W, float H){
float vol = L*W*H;
cout << vol << "\n";
return vol;
}
float rectArea(float Len, float Wid){
float recAr = Len*Wid;
cout << recAr << "\n";
return recAr;
}
float triArea(float triLen, float triHei){
float triAr;
triAr = triLen*triHei*0.5;
cout << triAr << "\n";
return triAr;
}
float triAreaBas(float triLen, float triHei){
float triArBas;
triArBas = triLen*triHei*0.5;
return triArBas;
}
float circleArea(float circRad){
float circAr;
circAr = (circRad*circRad)*3.14;
cout << circAr << "\n";
return circAr;
}
float trapArea(float bas1, float bas2, float basHei){
float trapAr;
trapAr = basHei*(bas1+bas2)/2;
cout << trapAr << "\n";
return trapAr;
}
float triPrism(float triPrisHei, float triArBas){
float triPrisVol;
triPrisVol = triArBas*triPrisHei;
cout << triPrisVol << "\n";
return triPrisVol;
}
float pyramidVolume(float pyraBasAr, float pyraHei){
float pyraVol;
pyraVol = (pyraBasAr*pyraHei)*0.33;
cout << pyraVol << "\n";
return pyraVol;
}
//Conversion Functions
//Program
int main(){
cout << "What would you like to calculate? Be sure to be exact with spelling and capitalization!" << endl;
cout << "Rectangular Prism Volume, Rectangle Area, Triangle Area, Circle Area, Trapezoid Area, Triangular Prism Volume, Pyramid Volume, Circumference,\n Pythagorean Theorem, Cylinder Volume, Cylinder Surface Area, Cone Volume, Cone Surface Area, Sphere Volume, Sphere Surface Area" << endl;
string Choice;
int x = 5;
while (x = 5){
getline(cin, Choice);
if (Choice == "Rectangular Prism Volume"){
float l;
float w;
float h;
cout << "Enter the Length" << endl;
cin >> l;
cout << "Enter the Width" << endl;
cin >> w;
cout << "Enter the Height" << endl;
cin >> h;
volume(l, w, h);
}
else if (Choice == "Rectangle Area"){
float recLen;
float recWid;
cout << "Enter Length" << endl;
cin >> recLen;
cout << "Enter Width" << endl;
cin >> recWid;
rectArea(recLen, recWid);
}
else if (Choice == "Triangle Area"){
float triLen;
float triHei;
cout << "Enter Base" << endl;
cin >> triLen;
cout << "Enter Height" << endl;
cin >> triHei;
triArea(triLen, triHei);
}
else if (Choice == "Circle Area"){
float circRadius;
cout << "Enter Radius";
cin >> circRadius;
circleArea(circRadius);
}
else if (Choice == "Trapezoid Area"){
float base1;
float base2;
float trapHeight;
cout << "Enter Base 1" << endl;
cin >> base1;
cout << "Enter Base 2" << endl;
cin >> base2;
cout << "Enter Height" << endl;
cin >> trapHeight;
trapArea(base1, base2, trapHeight);
}
else if (Choice == "Triangular Prism Volume"){
cout << "Enter Base width" << endl;
float triPrismBasLength;
cin >> triPrismBasLength;
cout << "Enter Base Length" << endl;
float triPrismBasHeight;
cin >> triPrismBasHeight;
triArea(triPrismBasLength, triPrismBasHeight);
cout << "Enter Base Area (Above Value)" << endl;
float triArBas;
cin >> triArBas;
cout << "Enter Prism Height" << endl;
float triPrismHeight;
cin >> triPrismHeight;
triPrism(triPrismHeight, triArBas);
}
else if (Choice == "Pyramid Volume"){
cout << "Enter Pyramid Base Width" << endl;
float pyraBasWid;
cin >> pyraBasWid;
cout << "Enter Pyramid Base Height" << endl;
float pyraBaseHei;
cin >> pyraBaseHei;
triArea(pyraBasWid, pyraBaseHei);
cout << "Enter Above Value" << endl;
float pyraBaseAr;
cin >> pyraBaseAr;
cout << "Enter Pyramid Height" << endl;
float pyraHeight;
cin >> pyraHeight;
pyramidVolume(pyraBaseAr, pyraHeight);
}
else if (Choice == "Pythagorean Theorem"){
cout << "What would you like to solve for?\n";
cout << "Leg A, Leg B, Hypotenuse, Check for right triangle\n";
string pythChoice;
getline(cin, pythChoice);
if (pythChoice == "Hypotenuse"){
cout << "Enter the value for leg a" << endl;
float a;
cin >> a;
cout << "Enter the value for leg b" << endl;
float b;
cin >> b;
pythagore(a, b);
}
else if (pythChoice == "Leg A"){
cout << "Enter the value for hypotenuse" << endl;
float hypA;
cin >> hypA;
cout << "Enter the value for leg b" << endl;
float bA;
cin >> bA;
pythagoreA(bA, hypA);
}
else if (pythChoice == "Leg B"){
cout << "Enter the value for hypotenuse" << endl;
float hypB;
cin >> hypB;
cout << "Enter the value for leg A" << endl;
float aB;
cin >> aB;
pythagoreA(aB, hypB);
}
else if (pythChoice == "Check for right triangle"){
float checkA;
cout << "Enter Leg A (squared)\n";
cin >> checkA;
float checkB;
cout << "Enter Leg B (squared)\n";
cin >> checkB;
float checkC;
cout << "Enter Hypotenuse (squared)\n";
cin >> checkC;
isRight(checkA, checkB, checkC);
}
}
else if (Choice == "Cylinder Volume"){
cout << "Enter radius\n";
float radius;
cin >> radius;
cout << "Enter height;\n";
float height;
cin >> height;
cylinderVolume(radius, height);
}
else if (Choice == "Circumference"){
cout << "Enter radius\n";
float radCirc;
cin >> radCirc;
circumference(radCirc);
}
else if (Choice == "Cylinder Surface Area"){
cout << "Enter radius\n";
float rad;
cin >> rad;
cout << "Enter height\n";
float hei;
cin >> hei;
cylinderSurfaceArea(rad, hei);
}
else if (Choice == "Cone Volume"){
cout << "Enter radius\n";
float rad;
cin >> rad;
cout << "Enter height\n";
float hei;
cin >> hei;
coneVolume(rad, hei);
}
system ("CLS");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment