Advertisement
bbg6

Untitled

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