I am writing this program to draw a sphere, I am having problems with the draw function which is giving me an error(bold). Can anyone help me to write the draw function for this program.
also, I want to have the user input the values for x,y, z, and radius. I now that I have to put a cout asking for the values and cin to get the values in main or maybe I can use get. Can anyone give me an idea how to work this out.
here is the code
Code:
#include <iostream>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#define PI 3.1415927
using namespace std;
class point
{
public:
point(const float xx, const float yy, const float zz) { x=xx; y=yy; z=zz; }
point(const point &p) { x = p.getX(); y = p.getY(); z = p.getZ(); }
point() { x = y = z = 0.0; }
float getX() const { return x; }
float getY() const { return y; }
float getZ() const { return z; }
private:
float x,y,z;
};
class shape3d
{
public:
shape3d(const point &pp) { p = pp; }
shape3d(const float x, const float y, const float z) { p = point(x,y,z); }
point getPoint() const { return p; }
virtual float getVolume() const = 0;
//virtual void draw( shape3d *todraw) const { todraw->draw(); }
private:
point p;
};
class sphere: public shape3d
{
public:
sphere(const point &p, const float r):shape3d(p) { radius = r; }
float getRadius() const { return radius; }
float getVolume() const { return 3.0*(PI*radius*radius*radius)/4.0; }
//error: draw function doesn't take 0 parameters
virtual void draw( sphere *todraw) const { todraw->draw(); }
private:
float radius;
};
main()
{
point p = point (0,0,0);
sphere s = sphere (p,50);
//error: draw function doesn't take 0 parameters
s.draw();
return 0;
}