Originally Posted by
laserlight
You are contradicting yourself. In the first sentence, you say that the source file should not contain the implementation of getShape(), then in the second second you say that the source file should contain the implementation of getShape().
Good. What about getShape.cpp? If it compiles, show your current Main.cpp. If not, show your current getShape.cpp.
I'm not talking about the getShape.cpp, i'm talking about shape and other derived classes, they shouldn't include getShape.cpp. ON the other hand, getShape.cpp is supposed to include circle.h, rectangle.h and square.h. and Main.cpp is only supposed to include shape.h.
Code:
#include <string>
using std::string;
#include <sstream>
#include <iostream>
using namespace std;
#include <iomanip>
#include "circle.h"
#include "square.h"
#include "rectangle.h"
using std::string;
using namespace std;
shape* getShape()
{
do {
string color;
double length, width, rad, side;
string shapetype;
shape *myshape;
cout << "Enter the shape's color (or 'done')..." << endl;
cin >> color;
cout << "Enter shape type..." << endl;
cin >> shapetype;
if (shapetype == "done")
{
return NULL;
}
if (shapetype == "circle")
{
cout << "Enter the radius..." << endl;
cin >> rad;
myshape = new circle(color, rad);
return myshape;
}
if (shapetype == "square")
{
cout << "Enter the side length..." << endl;
cin >> side;
myshape = new square(color, side);
return myshape;
}
if (shapetype == "rectangle")
{
cout << "Enter the length..." << endl;
cin >> length;
cout << "Enter the width..." << endl;
cin >> width;
myshape = new rectangle(color, width, length);
return myshape;
}
else{
cout << "Invalid input" << endl;
continue;
}
}while (true);
}