Hi,
I m new to the C++ programming and needs some helps to revise my source to calculate sphere volume, area, and circumference.
I need to create header file, main cpp file, and test cpp file and please find my source code below;
#include "sphere.h"
#include <iostream> // needed for cin and cout
using namespace std;
const double pi = 3.1415927; // declare pi as a constant
void sphere(double, double&, double&, double&);
// Precondition - input parameters are non-negative double values
// Postcondition - returns the circumference, volume and surface area of the sphere through reference parameters
int main()
{
double radius, circumference, volume, surfaceArea; // declare variables
cout << " Sphere Program " << endl;
cout << "\n Enter radius ";
cin >> radius; // enter the radius
sphere(radius, circumference, volume, surfaceArea); // call the sphere function
cout.setf(ios::fixed);
cout.precision(2);
cout << "\n The circumference is " << circumference << endl; // display results
cout << " The volume is " << volume << endl;
cout << " The surface area is " << surfaceArea << endl;
system("Pause"); // pause in order to see output
return (0);
}
//test.cpp//
#include "sphere.h"
#include <cmath>
#include<iostream>
using namespace std;
int main()
{
cout << "Enter the Radius of the Circle = ";
cin >> CircleRadius;
// Circumference of a Circle
CircleCircumference = 2 * PI * CircleRadius;
cout << "Circumference of the Circle = " << CircleCircumference;
cout << NEWLINE;
// Area of a Circle
CircleArea = PI * pow(CircleRadius, 2);
cout << "Area of the Circle = " << CircleArea;
cout << NEWLINE;
// Volume of a Sphere
SphereVolume = 4 * PI / 3 * pow(CircleRadius, 3);
cout << "Volume of the Sphere = " << SphereVolume;
cout << NEWLINE;