Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication7.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h" // necessary for visual studio only
- #include<iostream> // includes library for code
- #include <cmath> // opens math function libraries for use in code
- using namespace std; // opens libraries for use in code instead of std:: throughout
- int main()
- {
- float cm = 0.0f, r = 0.0f, AreaOfSquare = 0.05f, AreaOfCircle = 0.0f, CubeVolume = 0.0f; // to initialize float variable using limited storage
- cout << "Geometry formulas by (Robert Burgess)\n" << endl;
- cout << "Please input one number in centimeters for length, "; //to display prompt for input
- cin >> cm; // allows user to input in centimeters
- cout << "\n\n The number you entered is: " << cm
- << " cm (" << cm / 100 << " Meters) \n\n"; // to ensure accurate input and to convert to meters
- AreaOfSquare = (cm*cm) / 100; //to initialize Area of square formula as constant variable simplifying code and to calculate area of square
- cout << "Area of a square: " << AreaOfSquare << " sq. Meters\n"; // setting Area of square to be output in square meter denotion
- r = cm / 2; // sets r to radius diameter/2 as directions suggest
- AreaOfCircle = (3.14159 * pow(r, 2)) / 100; // sets area of circle to constant, converts to meters, and makes use of power function
- cout << "Area of a circle: " << AreaOfCircle << " sq. Meters\n"; // sets output of circle and denotes output to sq. meters
- cout << "The difference is: " << AreaOfSquare - AreaOfCircle << " sq. Meters\n" << endl; // Uses area of circle and area of square constants to find difference
- cout << fixed; // sets notation of output for volume to numerical values instead of scientific notation
- CubeVolume = ceil(cm*cm*cm); // calculates output of volume constant to round down to nearest whole number (in our case all inputs round the same, tested with 10.5 input for accuracy)
- cout << "Cube volume rounded up: " << CubeVolume << " cu. Meters\n" << endl; // prompts output for rounded up in cubic meters
- CubeVolume = floor(cm*cm*cm); // calculates output of volume constant to round up to nearest whole number (in our case all inputs round the same, tested with 10.5 input for accuracy)
- cout << "Cube volume rounded down: " << CubeVolume << " cu. Meters\n" << endl; // prompts output for rounded up in cubic meters
- system("pause"); //allows for user input and observation of output (display would run and disapear without)
- return 0; // to ensure code is accurate for operating system
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement