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 140 141 142 143 144 145 146 147 148 149 150
|
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
*/
/*
Shapedesc, by Some Dude
Version 0.25
Supports Rectangular Prisms, Cylinders, Paralellograms, and Circles
*/
#include <iostream>
using namespace std;
//Variable table
int option;
int loop = 42; //Change and DIE.
float base;
float height;
float depth;
float volume;
float surfaceArea;
float circumference;
int descCylinder(void) //The function for describing Cylinders
{
//Prompt to get info
cout << "Radius: ";
cin >> base; //Didn't wanna make another variable.
cout << "Height: ";
cin >> height;
//The part with math in it
volume = (base * base * 3.14) /*Or "PiR2*/ * height;
cout << "Volume: " << volume << "\n";
circumference = base * 2 /*Radius X 2 is diameter, right?*/ * 3.14;
surfaceArea = (circumference * height) /*Find the area of the Cylinder body*/ + (base * base * 3.14 * 2) /*End caps*/;
cout << "Surface Area: " << surfaceArea << "\n";
return 0;
}
int descRectPrism(void) //The function for describing Rectangular prisms
{
//Prompt to get info
cout << "Base: ";
cin >> base;
cout << "Height: ";
cin >> height;
cout << "Depth: ";
cin >> depth;
//The part with math in it
volume = base * height * depth; //B X H X D, or L X W X H
cout << "Volume: " << volume << "\n";
surfaceArea = (base * height * 2) /*The ends*/ + (base * depth * 2) /*Top and bottom*/ + (height * depth * 2) /*Sides*/;
cout << "Surface Area: " << surfaceArea << "\n";
return 0;
}
int descParalellogram(void)//The function for describing paralellograms, squares, rectangles, etc.
{
//Prompt to get info
cout << "Base: ";
cin >> base;
cout << "Height: ";
cin >> height;
//The part with math in it
volume = base * height; //B X H = Area. I stored it in volume because I didn't wanna make another variable.
cout << "Area: " << volume << "\n";
surfaceArea = (base * 2) + (height * 2); //The two paralell sides are equal. Also, didn't want another var.
cout << "Perimiter: " << surfaceArea << "\n";
return 0;
}
int descCircle(void) //The function for describing Circles
{
//Prompt to get info
cout << "Radius: ";
cin >> base; //We have enough damn variables!
//The part with math in it
volume = base * base * 3.14; //Area is PiR2. Also... Well, you know.
cout << "Area: " << volume << "\n";
surfaceArea = (base * 2) /*Diameter*/ * 3.14; //C = PiD
cout << "Circumference: " << surfaceArea << "\n";
return 0;
}
int main(void)
{
//Main loop
jumpPoint: //Yeah, yeah, yeah, gotos are bad practice... But they kick @$$.
while (loop == 42)
{
cout << "1: Cylinder, 2: Rectangular prism, 3: Paralellograms, 4: Circles, E: Exit> ";
cin >> option;
if (option == 1) //Cylinders
{
descCylinder();
goto jumpPoint;
}
else if (option == 2) //Rectangular Prisms
{
descRectPrism();
goto jumpPoint;
}
else if (option == 3) //Paralellograms
{
descParalellogram();
goto jumpPoint;
}
else if (option == 4) //Circles
{
descCircle();
goto jumpPoint;
}
else //Exit
{
break;
}
}
return 0;
}
|