Advertisement
Guest User

CPS 171 MP 1 Robert Burgess

a guest
Feb 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.48 KB | None | 0 0
  1. // ConsoleApplication7.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h" // necessary for visual studio only
  4. #include<iostream> // includes library for code
  5.  
  6. #include <cmath> // opens math function libraries for use in code
  7. using namespace std; // opens libraries for use in code instead of std:: throughout
  8.  
  9. int main()
  10. {
  11.     float cm = 0.0f, r = 0.0f, AreaOfSquare = 0.05f, AreaOfCircle = 0.0f, CubeVolume = 0.0f; // to initialize float variable using limited storage
  12.     cout << "Geometry formulas by (Robert Burgess)\n" << endl;
  13.     cout << "Please input one number in centimeters for length, ";  //to display prompt for input
  14.     cin >> cm; // allows user to input in centimeters
  15.     cout << "\n\n The number you entered is: " << cm
  16.         << " cm (" << cm / 100 << " Meters) \n\n"; // to ensure accurate input and to convert to meters
  17.     AreaOfSquare = (cm*cm) / 100; //to initialize Area of square formula as constant variable simplifying code and to calculate area of square
  18.     cout << "Area of a square: " << AreaOfSquare << " sq. Meters\n"; // setting Area of square to be output in square meter denotion
  19.     r = cm / 2; // sets r to radius diameter/2 as directions suggest
  20.     AreaOfCircle = (3.14159 * pow(r, 2)) / 100; // sets area of circle to constant, converts to meters, and makes use of power function
  21.     cout << "Area of a circle: " << AreaOfCircle << " sq. Meters\n"; // sets output of circle and denotes output to sq. meters
  22.     cout << "The difference is: " << AreaOfSquare - AreaOfCircle << " sq. Meters\n" << endl; // Uses area of circle and area of square constants to find difference
  23.  
  24.     cout << fixed; // sets notation of output for volume to numerical values instead of scientific notation
  25.     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)
  26.     cout << "Cube volume rounded up: " << CubeVolume << " cu. Meters\n" << endl; // prompts output for rounded up in cubic meters
  27.     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)
  28.     cout << "Cube volume rounded down: " << CubeVolume << " cu. Meters\n" << endl; // prompts output for rounded up in cubic meters
  29.     system("pause"); //allows for user input and observation of output (display would run and disapear without)
  30.     return 0; // to ensure code is accurate for operating system
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement