summaryrefslogtreecommitdiffstats
path: root/C++/shapes
diff options
context:
space:
mode:
Diffstat (limited to 'C++/shapes')
-rw-r--r--C++/shapes/Ch 4 Shapes program and planning sheet(2).docxbin0 -> 34985 bytes
-rw-r--r--C++/shapes/shape.cpp102
2 files changed, 102 insertions, 0 deletions
diff --git a/C++/shapes/Ch 4 Shapes program and planning sheet(2).docx b/C++/shapes/Ch 4 Shapes program and planning sheet(2).docx
new file mode 100644
index 0000000..edcc249
--- /dev/null
+++ b/C++/shapes/Ch 4 Shapes program and planning sheet(2).docx
Binary files differ
diff --git a/C++/shapes/shape.cpp b/C++/shapes/shape.cpp
new file mode 100644
index 0000000..bcae77f
--- /dev/null
+++ b/C++/shapes/shape.cpp
@@ -0,0 +1,102 @@
+// Your Name : msglm
+// Date: Feb-17-2022
+// Program Title: MENU TEMPLATE with IF ELSE
+// Program Description: a program with a menu structure that will allow the user to choose an option to calculate area for a: Rectangle, Circle, and a Triangle
+
+#include <iostream>
+#include <string>
+#include <iomanip>
+#include <cmath>
+
+using namespace std;
+
+// Named constants
+
+int main()
+{
+
+ // Variable declaration
+
+ int choice;
+ double area;
+
+ //Program title and description for the user
+
+ cout << "MENU TEMPLATE with IF ELSE" << endl << endl;
+
+ // User input
+
+ cout << "Choose the corresponding number for what task you want to complete." << endl;
+ cout << "1 - Perform task #1 : Rectangle area" << endl;
+ cout << "2 - Perform task #2 : Circle area" << endl;
+ cout << "3 - Perform task #3 : Triangle area" << endl;
+ cout << "Enter selected number here: ";
+ cin >> choice;
+
+ // Calculations
+
+ // Output to the screen
+
+ //This if-else statement need not exist: a switch statement would be much more optimal
+ if (choice == 1)
+ {
+ double height;
+ double width;
+
+ //User Input
+ cout << "Perform task #1 : Rectangle area" << endl;
+ cout << "Input the height in cm: \n";
+ cin >> height;
+
+ cout << "Input the width in cm: \n";
+ cin >> width;
+
+ //Calculation
+ area = height * width;
+
+ //Output
+ cout << "Area of the rectangle is " << area << " cm^2 \n";
+ }
+ else if (choice == 2)
+ {
+ cout << "Perform task #2 : Circle area" << endl;
+ double inputRadius;
+ string measurement;
+ const double pi = 3.14159;
+
+ //User Input
+ cout << "Please Input the Desired Radius for your Circle in cm: ";
+ cin >> inputRadius;
+
+ //Output
+ cout << "Area of the circle is " << pi*pow(inputRadius, 2) << "cm^2 \n";
+
+ }
+ else if (choice == 3)
+ {
+ double height;
+ double base;
+
+ //User Input
+ cout << "Perform task #3 : Triangle area" << endl;
+ cout << "Input the height in cm: \n";
+ cin >> height;
+
+ cout << "Input the base in cm: \n";
+ cin >> base;
+
+ //Output
+ cout << "Area of the rectangle is " << (height*base)/2 << " cm^2 \n";
+ }
+ else
+ cout << "Input error; program terminating" << endl;
+
+ return 0;
+}
+/*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 3 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, see <https://www.gnu.org/licenses/>.
+ */
+
+