From 9d53d8857eaa1c9405894a88ca75bc4657e42f35 Mon Sep 17 00:00:00 2001 From: msglm Date: Sat, 14 Jan 2023 05:31:48 -0600 Subject: Inital Commit --- C++/shapes/shape.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 C++/shapes/shape.cpp (limited to 'C++/shapes/shape.cpp') 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 +#include +#include +#include + +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 . + */ + + -- cgit v1.2.3