My project is to create shapes, and place Shape * pointers to each new Shape object into an array.
This is something that I came up with, and it doesn't work at all.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include "shape.h"
#include "circle.h"
#include "rectangle.h"
#include "square.h"
#include "triangle.h"
void virtualViaPointer( const Shape * );
int main()
{
bool exit = false;
for (;
{
int choice;
Shape *arrayOfShapes[ 4 ];
cout << "( 1 ) Circle" << endl;
cout << "( 2 ) Rectangle\n";
cout << "( 3 ) Square\n";
cout << "( 4 ) Triangle\n";
cout << "( 5 ) Quit\n";
cout << "Choose shape to create: ";
cin >> choice;
for ( int i = 0; i < 4; i++ )
{
switch( choice )
{
case ( 1 ):
virtualViaPointer( arrayOfShapes[ i ] );
break;
case ( 2 ):
virtualViaPointer( arrayOfShapes[ i ] );
break;
case ( 3 ):
virtualViaPointer( arrayOfShapes[ i ] );
break;
case ( 4 ):
virtualViaPointer( arrayOfShapes[ i ] );
break;
case ( 5 ):
exit = true;
break;
default:
cout << "Please select again!\n";
break;
}
if ( exit )
break;
}
}
return 0;
}
void virtualViaPointer( const Shape *baseClassPtr )
{
baseClassPtr->printShapeName();
baseClassPtr->print();
cout <<"\nArea = " << baseClassPtr->area() << "\n\n";
}
Please help!