No my professor said just to create the function in its own file, and not to make it a class. These are the instructions for it:
For reading shape data, create a getShape.cpp file containing a getShape() function that returns a base Shape * pointer. It should read a shape description from an input stream, create the correct type of derived shape with the new operator and parameters to the constructor, and return a base Shape * pointer to the new object. After reading a shape color and type (e.g. blue circle), it reads the additional information specific to that type of shape (e.g. for a circle, it reads the radius), and then uses the new operator to create the specific derived type of shape (e.g. new Circle(color, radius) )
Input can be from cin, or from a stream input file (use iostreams). When there is no more input data (or when 'done' is entered), return a NULL Shape pointer. All character data is kept in C++ strings (no char arrays).
When I first saw the problem, I thought that it would be an awesome idea to virtually define the input and output IO operators of the base and derived classes, that way input for any shape type would take the following form
Shape *shape = /* new shape type */;
This would allow you to wrapper up and be modular with your input scheme, getting rid of nested input cases for each shape type. But once I attempted to do that myself, I found it a little more drawn out that I imagined. I did come up with a solution, which I will post just for a reference but I don't recommend trying to implement it since it steers away from what you are learning. Maybe another expert/mentor knows an easier way to do this, but this is all I got.
Why doesn't this work for main? It keeps setting the return value of getShape to the array pointer "shape" and then sends shape to the toString function. Maybe my toString is not right? Here is the one for class circle, because that is what I have been testing with
using namespace std;
int _tmain(int argc, _TCHAR* argv)
cout << "Enter a list of shapes - 'done' to end" << endl;
Shape* shape = NULL;
while(getShape() != NULL)
shape = getShape();
cout << shape << endl;
oss << "" << getColor() << "circle with a radius" << ""<< area();
std::string s = oss.str();