I am having a couple of problems. I think I got the formatting down for the most part. I am having issues in a few calculations and how to iterate through them. Basically I need to take the radius and calculate the circumference and the volume. Once I have the calculation I need to print them Radius in Decimal and Binary, then circumference in Hex and finally volume in scientific notation.
Questions.
1.) where would be best to declare circumference and volume?
2.) once they are declared whats the best place to do the calculations?
3.) I can't see an array for this assignment so how would I do this for radius values of 20 - 30.
#ifndef CS215Lab2_sphere_h //Preprocessor directives to prevent duplicate
#define CS215Lab2_sphere_h // declarations. Use the file name of the identifier
//***********************************************************************
// Class declaration for sphere
//***********************************************************************
class sphere {
int radius();
public:
sphere();
sphere(int InRadius);
void(SetRadius(int NewRadius));
int GetRadius();
float CalcCircumference();
float CalcVolume();
};
#endif
#include "sphere.h"
#include <iostream>
usingnamespace std;
//=======================================================================
// CONSTANT DEFINITIONS
// <Constants which apply only to the file>
constdouble PI = 3.14159265;
//***********************************************************************
// Constructor For sphere
//***********************************************************************
sphere::sphere()
{
int radius=0;
}a
//***********************************************************************
// member function to set the radius
//***********************************************************************
void sphere::SetRadius(int newRadius)
{
radius = newRadius <= 0 ? 1 : newRadius;
} //to avoid the "0" issue and set a new radius
//***********************************************************************
// member function to get the radius
//***********************************************************************
int sphere::GetRadius()
{
for(int i = 20; i < 31; i++)
sphere::SetRadius(i);
}
//***********************************************************************
// member function to calculate circumference
//***********************************************************************
float sphere::CalcCircumference()
{
double circumference = 0;
circumference = PI * 2(radius)
};
//***********************************************************************
// member function to calculate volume
//***********************************************************************
float sphere::CalcVolume()
{
double volume = 0;
volume = radius*radius*radius*PI*4/3
};
spherefunctions.h
1 2 3 4 5 6 7 8 9 10 11 12 13
#ifndef CS215Lab2_spherefunctions_h //Preprocessor directives to prevent duplicate
#define CS215Lab2_spherefunctions_h // declarations. Use the file name of the identifier
externvoid printDecimal( long inNum );
externvoid printHex( long inNum );
externvoid printBinary( int inNum, int numDigits = 8 );
externvoid printScientific( float inNum );
externvoid centerLine( const std::string &text, unsignedint lineLength );
externvoid printDoubleHorizontalLine(unsignedint lineLength);
#endif