Maybe my other thread was too wordy for everyone, cuz I usually receive help right away, and I see that it was viewed 20+ times and yet no responses...so basically I need help with my homework...We were given a main.cpp file, and PART of a header file. He also gave us what our final output should look like. We must generate the implementation file and finish the header to work appropriately. Here's what's given and what I've attempted so far:

Please help if you can!

main:

// The following is the main.cpp file
// which executes your solution and generates the output
// shown below

#include <iostream>
#include "shapes.h"
using namespace std;

 int main()
 {
     
    ShapeArr  arr(3);

    cout << "Rectangles *******"<<endl;
    arr.addRectangle(1.0, 2.0);
    arr.addRectangle(3.0, 2.0);
    arr.addRectangle(2.0, 2.0);
    arr.publishStats();

    cout << "Circles *******"<<endl;
    ShapeArr arr2(3);
    arr2.addCircle(1.0);
    arr2.addCircle(2.0);
    arr2.addCircle(3.0);
    arr2.publishStats();

    cout << "Triangles *******"<<endl;
    ShapeArr arr3(3);
// Note that angles are in Radians (NOT degrees)
    arr3.addTriangle(1.0, 4.0, 1.0);
    arr3.addTriangle(1.0, 30., 2.);
    arr3.addTriangle(1.0, 0.8, 1.0);
    arr3.publishStats();
    
    cout << "Regular Polygon *******"<<endl;
    ShapeArr arr4(3);
    arr4.addRegularPoly(1.0, 3);
    arr4.addRegularPoly(1.0, 10);
    arr4.addRegularPoly(1.0, 50);
    arr4.publishStats();

  
    cout << "Mixture *******"<<endl;
    ShapeArr arr5(4);
    arr5.addRegularPoly(1.0, 3);
    arr5.addCircle(3.0);
    arr5.addTriangle(1.0, 0.8, 1.0);
    arr5.addRegularPoly(1.0, 50);
    arr5.publishStats();
 
 }

header:

// shapes.h file with a few holes to fill in

#include <iostream>
using namespace std;
#include <cmath>

const double PI = 3.14159265359;
const double PI2 = 2*PI;


class Shape
{   
public:
   Shape()
   {
   }   
   virtual double getPerimeter()=0;
   virtual double getArea()=0;
   
   double getAPRatio()
   {
       double p = getPerimeter();
       if (p == 0.0) return 0.0; // indeterminant
       return getArea()/p;
   }
   virtual ~Shape()
   { // When everything is freed up properly,

    cout << "Shape Destructor"<<endl;
   };
};


class Circle : public Shape
{
    // Fill in details
private:
	double radius;
public:
	double getPerimeter();
	double getArea();
};


class Rectangle : public Shape
{
   // Fill in details
private:
	double height;
	double width;
public:
	double getPerimeter();
	double getArea();
};

class Triangle : public Shape
{
    // Fill in details
private:
	double sideA;
	double sideB;
	double includedAngle;
public:
	double getPerimeter();
	double getArea();
};

class RegularPoly : public Shape
{
   // Fill in details
private:
	int numSides;
	double side;
public:
	double getPerimeter();
	double getArea();
};

class ShapeArr
{
// The following is what you need to have an 
// array of pointers to the Shape class

    Shape ** arr;
    int arrSize;

// To allocate this array, you will need something like:
//    arr = new Shape* [arrSize];
// Note that you are responsible for freeing up all of 
// the memory when your ShapeArr class is destructed.
// If you do it correctly, you should see the Shape Destructor
// generate it's cout statement for every Shape class created. 

// It's useful to keep track of the number of Shapes added to 
// the array. 

    int currCount;
public:
    ShapeArr(int arrSize);
    ~ShapeArr();
    void addRectangle(double height, double width);
    void addCircle(double radius);      
    void addTriangle(double sideA, double includedAngle, double sideB);
    void addRegularPoly(double side, int numSides);

   // This routine prints out the Max getAPRatio and the average 
   // getAPRatio for all of the Shapes in this class.

    void publishStats();
};

My implementation file attempt so far:

#include <iostream>
#include "shapes.h"
using namespace std;
  
double Rectangle::getPerimeter()
{
	double p;
	p = height + width;
	return p;
}

double Circle::getPerimeter()
{
	double p;
	p = PI2 * radius;
	return p;
}

double Triangle::getPerimeter()
{
	double p;
	p = sideA + sideB + sqrt(sideA*sideA + sideB*sideB - 2.0*sideA*sideB*cos(includedAngle));
	return p;
}

double RegularPoly::getPerimeter()
{
	double p;
	p = height + width;
	return p;
}


ShapeArr::ShapeArr(int arrSize)
{
	this -> arrSize = arrSize;
	currCount = 0;
	arr = new Shape* [arrSize];
}


ShapeArr::~ShapeArr()
{
	delete [] arr;
}



void ShapeArr::addRectangle(double height, double width)
{
	//Shape * s;
	currCount++;
	//s->getPerimeter();
}

void ShapeArr::addCircle(double radius)
{
	currCount++;
}

void ShapeArr::addTriangle(double sideA, double includedAngle, double sideB)
{
	currCount++;
}

void ShapeArr::addRegularPoly(double side, int numSides)
{
	currCount++;
}


   // This routine prints out the Max getAPRatio and the average 
   // getAPRatio for all of the Shapes in this class.

void ShapeArr::publishStats()
{
}

And what the final output should look like:

Rectangles *******
Max APRatio = 0.6 Average APRatio=0.477778
Circles *******
Max APRatio = 1.5 Average APRatio=1
Triangles *******
Max APRatio = 0.193977 Average APRatio=0.140715
Regular Polygon *******
Max APRatio = 3.97364 Average APRatio=1.62913
Mixture *******
Max APRatio = 3.97364 Average APRatio=1.43676
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor
Shape Destructor

I mainly am lost on the addRectangle/addCircle/add... functions. I don't understand what i'm supposed to put in there in order to adequately calculate the perimeters and areas and ultimately the apratios. PLEASE HELP ME!!

Thanks in advance!

Oh, and moderators, feel free to delete my other thread or whatever since it is pretty similar to this one, yet more confusing...Hopefully this one is easier for someone to help me with. Sorry bout the confusion!!

>I mainly am lost on the addRectangle/addCircle/add... functions

I would ask your tutors, that's what they're there for!

Understood, but considering I'm at home right now, I was hoping someone on here could help me....?

I assume it needs to begin like this:
What else do I need though??
How do I incorporate the height and width into it? Do I need to call getPerimeter from here, or do i wait until i get to the publishStats func.??

void ShapeArr::addRectangle(double height, double width)
{
	if (currCount < arrSize)
		arr[currCount++] = new Rectangle;
}
This article has been dead for over six months. Start a new discussion instead.