Advertisement
bbg6

Untitled

Mar 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. using namespace std;
  2. // Prototypes
  3. double square(double side);
  4. double square2(double radius);
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13.     // Variables
  14.     ofstream outFile;
  15.     double PI = 3.14;
  16.     double side;
  17.     double radius;
  18.     double s_cube;
  19.     double s_sphere;
  20.    
  21.     // Prompting user
  22.     outFile.open("output.txt");
  23.     cout << " Enter side of cube. " << endl;
  24.     cin >> side;
  25.     cout << " Now enter radius of the sphere. " << endl;
  26.     cin >> radius;
  27.     // Calling functions
  28.     s_cube = 6.0 * square(side);
  29.     s_sphere = 4.0 * square2(radius) * PI;
  30.     // Printing message to file open
  31.     outFile << " The surface of the cube with sides " << side << " is " << s_cube << endl;
  32.     cout << " The surface of the cube with sides " << side << " is " << s_cube << endl;
  33.     cout << endl;
  34.     outFile << " The surface of a sphere of radius " << radius << " is " << s_sphere << endl;
  35.     cout << " The surface of a sphere of radius " << radius << " is " << s_sphere << endl;
  36.     // Close file
  37.     outFile.close();
  38.  
  39.     system("pause");
  40.     return 0;
  41.  
  42. }
  43. // Functions
  44.  
  45. double square(double side)
  46. {
  47.     return side * side;
  48. }
  49. double square2(double radius)
  50. {
  51.     return radius * radius;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement