Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class/FileName requirements: makefile main.cpp Shape.h ShapeTest.cpp Required: P

ID: 3822793 • Letter: C

Question

Class/FileName requirements: makefile main.cpp Shape.h ShapeTest.cpp Required: Put your name in the comments at the top of the files Shape will have the following member variables and methods Private members: double* sideLengths and int size An array representing the lengths of each side of this shape Keep track of the array's size! Public members: public Shape(int numSides) defines how many sides this Shape will have o creates the array to hold the lengths of that many sides initializes each length to -1.0 public void setLength(int index, double value) sets the length at the given index to the given value public double perimeter() returns the length of the perimeter of the shape recall the perimeter is the sum of all sides In main you declare an instance of Shape and the following ask the user how many sides the shape will have get the lengths for each side display the perimeter assume good input numeric output does not need to be formatted exactly as below How many sides?: 3 Length 1: 5.5 Length 2: 10.0 Length 3: 7.5 Perimeter: 23.0

Explanation / Answer

Hi,

I have completed the code but it gives some error. Time is up so I cannot re-post it after fixing the errors. Please use this code as your base and try to fix errors-

#include <iostream>

using namespace std;

class Shape {
private:
double* sideLengths;
int size;
public:
public Shape(int numSides);
public void setLength( int index,double value );
public double perimeter();

};

// Member functions definitions
Shape::Shape(int numSides) {
double arr[numSides];
*sideLengths=arr;
for(int i=0;i<numSides1;i++)
{
arr[i]=-1.0;
}
}

void Shape::setLength( int index,double value ) {
arr[index]=value;
}

double Shape::perimeter() {
double peri=0.0;
for(int i=0;i<numSides;i++){
peri=peri+*sideLengths[i];
}
return peri;
}


// Main function for the program
int main( ) {
Shape s1;
double perimeter1 = 0.0;
s1.setLength(5,2);
perimeter1=s1.perimeter();


}