### help with C++ homework

Newbie here, just wanted to ask if some of you experts could help me out with my homework. We are given four ordered pairs for 5 shapes (20 ordered pairs). And we are supposed to print the output so that it comes out:

Order pairs
Shape 1: 0,0 0,5 14,5 14,0
Shape 2: 0,5 0,10 5,10 5,5
Shape 3: 5,5 5,10 10,10 10,5
Shape 4: 10,7 10,8 13,8 13,7
Shape 5: 10,5 10,7 15,7 15,5

Shape# Type Area(sq/unit)
1 Rectangle 70
2 Square 25
3 Square 25
4 Rectangle 3
5 Rectangle 10

The total area of the shape is: ### sq/units

I am then to find out what the smallest piece of material is which can cover the all the rectangles and squares.

Minimum material specifications:
Length: ## Width:## Area:## sq/units

Lastly, I am to find out if the layout uses at least 90% of the space.
Output:
The layout is efficient, it uses #% of the space.
or
The layout is inefficient, it uses #% of the space.

This is what I have so far(I haven't polished it yet)

 ```#include #include #include using namespace std; class Shape { public: Shape(); int getArea(); int getLength(); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); int newArea(); float totArea(); float eff(); string getType(); int getWidth(); void setData(); void print1(); void print2(); void print3(); void print4(); int length, width, a[4], b[4], area, totarea, newarea; string type; private: int maxX, maxY, minX, minY; }; Shape::Shape() { } void Shape::setData() { for (int i=0;i<=3;i++) cin>>a[i]>>b[i]; /*int i; cout<<"Shape 1: "; for (i=0;i<4;i++) cin>>a1[i]>>a2[i]; cin.ignore(25, '\n'); cout<<"Shape 2: "; for (i=0;i<4;i++) cin>>b1[i]>>b2[i]; cin.ignore(25, '\n'); cout<<"Shape 3: "; for (i=0;i<4;i++) cin>>c1[i]>>c2[i]; cin.ignore(25, '\n'); cout<<"Shape 4: "; for (i=0;i<4;i++) cin>>d1[i]>>d2[i]; cin.ignore(25, '\n'); cout<<"Shape 5: "; for (i=0;i<4;i++) cin>>e1[i]>>e2[i];*/ length=getLength(); width=getWidth(); maxX=getMaxX(); minX=getMinX(); maxY=getMaxY(); minY=getMinY(); area=getArea(); type=getType(); //totarea=totArea(); //newarea=newArea(); } void print1() { Shape Shapes[5]; //int i; //for(i=1;i<5;i++) /*cout<<"Shape 1: "; cout<=90) cout<<"The layout is efficient, it uses "<a[1] && a[2]>a[3] && a[2]>a[4]) maxX=a[2]; if(a[3]>a[1] && a[3]>a[2] && a[3]>a[4]) maxX=a[3]; if(a[4]>a[1] && a[4]>a[2] && a[4]>a[3]) maxX=a[4]; //if(a1[3]>a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return maxX; } int Shape::getMaxY() { int maxY=b[1]; if(b[2]>b[1] && b[2]>b[3] && b[2]>b[4]) maxY=b[2]; if(b[3]>b[1] && b[3]>b[2] && b[3]>b[4]) maxY=b[3]; if(b[4]>b[1] && b[4]>b[2] && b[4]>b[3]) maxY=b[4]; //if(a2[3]>a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return maxY; } int Shape::getMinX() { int minX=a[1]; if(a[2]a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return minX; } int Shape::getMinY() { int minY=b[1]; if(b[2]a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return minY; } int Shape::getArea() { return length*width; } string Shape::getType() { if(length==width) return "Square"; else return "Rectangle"; } float totArea() { int i; Shape Shapes[5]; float temparea=0; for (i=1;i<=5;i++) temparea=temparea+Shapes[i].area; return temparea; } int main() { int i,l,w,newarea; float area,totarea,eff; string type; Shape s; string Shapes; /*int a1[4], a2[4], b1[4], b2[4], c1[4], c2[4], d1[4], d2[4], e1[4], e2[4], Max; Shape myS1; myS1.setData(a1, a2, b1, b2, c1, c2, d1, d2, e1, e2); myS1.print(a1, a2, b1, b2, c1, c2, d1, d2, e1, e2); myS1.getMaxX(a1, a2); Max=myS1.getMaxX(a1, a2); return 0;*/ //declare an array of 5 objects of type Shape Shape myS1[5]; Shape myS2; //call a function to load the user input into each object for(i=1;i<6;i++) myS1[i].setData(); /*myS1[i].getType(); myS1[i].getArea(); myS1[i].getMaxX(); myS1[i].getMinX(); myS1[i].getMaxY(); myS1[i].getMinY();*/ //call a function to print results for part #1 and #2 print1(); print2(totarea); //call a function to print results for part #3 print3(l,w,newarea); //print the results for part #4 print4(eff); } ```

but after inputting the order pairs, it tells me that the program has encountered an unexpected error. It doesn't specify what the problem was so I can't figure out where my error is. I'm guessing it's in the print1 function that causes the problem. Any help is appreciated. Thank you.
Arrays are zero based. Starts at 0, ends at n-1
thank you, that helped! :)

I've edited my program since then, now it seems like my getType() and getArea() doesn't grab the data.

 ```#include #include #include using namespace std; class Shape { public: Shape(); int getArea(); int getLength(); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); int newArea(); float totArea(); float eff(); string getType(); int getWidth(); void setData(); void print1(); void print2(); void print3(); void print4(); int length, width, a[4], b[4], area, totalArea, newarea; string type; private: int maxX, maxY, minX, minY; }; Shape::Shape() { } void Shape::setData() { cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2]>>a[3]>>b[3]; /*int i; cout<<"Shape 1: "; for (i=0;i<4;i++) cin>>a1[i]>>a2[i]; cin.ignore(25, '\n'); cout<<"Shape 2: "; for (i=0;i<4;i++) cin>>b1[i]>>b2[i]; cin.ignore(25, '\n'); cout<<"Shape 3: "; for (i=0;i<4;i++) cin>>c1[i]>>c2[i]; cin.ignore(25, '\n'); cout<<"Shape 4: "; for (i=0;i<4;i++) cin>>d1[i]>>d2[i]; cin.ignore(25, '\n'); cout<<"Shape 5: "; for (i=0;i<4;i++) cin>>e1[i]>>e2[i];*/ length=getLength(); width=getWidth(); maxX=getMaxX(); minX=getMinX(); maxY=getMaxY(); minY=getMinY(); area=getArea(); type=getType(); } void print1(Shape Shapes[]) { //int i; //for(i=1;i<5;i++) /*cout<<"Shape 1: "; cout<=90) cout<<"The layout is efficient, it uses "<a[1] && a[2]>a[3] && a[2]>a[4]) maxX=a[2]; if(a[3]>a[1] && a[3]>a[2] && a[3]>a[4]) maxX=a[3]; if(a[4]>a[1] && a[4]>a[2] && a[4]>a[3]) maxX=a[4]; //if(a1[3]>a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return maxX; } int Shape::getMaxY() { int maxY=b[1]; if(b[2]>b[1] && b[2]>b[3] && b[2]>b[4]) maxY=b[2]; if(b[3]>b[1] && b[3]>b[2] && b[3]>b[4]) maxY=b[3]; if(b[4]>b[1] && b[4]>b[2] && b[4]>b[3]) maxY=b[4]; //if(a2[3]>a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return maxY; } int Shape::getMinX() { int minX=a[1]; if(a[2]a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return minX; } int Shape::getMinY() { int minY=b[1]; if(b[2]a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return minY; } int Shape::getArea() { return length*width; } string Shape::getType() { if(length==width) return "Square"; else return "Rectangle"; } float totArea(Shape Shapes[]) { float totalArea=0; for (int i=0;i<5;i++) totalArea=totalArea+Shapes[i].area; return totalArea; } int main() { int i,newLength,newWidth; float eff, newArea, totalArea; string type; Shape Shapes[5]; //declare an array of 5 objects of type Shape Shape myS1[5]; Shape myS2; //call a function to load the user input into each object for(i=0;i<5;i++) Shapes[i].setData(); cout<

this is the output

 ```0 0 0 5 14 5 14 0 0 5 0 10 5 10 5 5 5 5 5 10 10 10 10 5 10 7 10 8 13 8 13 7 10 5 10 7 15 7 15 5 Shape#TypeArea(sq/units) 1 Square0 2 Square0 3 Square0 4 Square0 5 Square0 Press any key to continue . . .```

and it tells me the variable totalArea is being used without being initialized. I don't understand why I have to initialize the totalArea??
quick update, i've done an ugly workaround. now my only problem is that the compiler doesn't record my values for the area (even the ordered pairs???) cause it's giving me 0s and squares for all the return types of getType() and getArea().

 ```#include #include #include using namespace std; class Shape { public: Shape(); int getArea(); int getLength(); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); int newArea(); float totArea(); float eff(); string getType(); int getWidth(); void setData(); void print1(); void print2(); void print3(); void print4(); int length, width, a[4], b[4], area, totalArea, newarea; string type; private: int maxX, maxY, minX, minY; }; Shape::Shape() { } void Shape::setData() { cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2]>>a[3]>>b[3]; /*int i; cout<<"Shape 1: "; for (i=0;i<4;i++) cin>>a1[i]>>a2[i]; cin.ignore(25, '\n'); cout<<"Shape 2: "; for (i=0;i<4;i++) cin>>b1[i]>>b2[i]; cin.ignore(25, '\n'); cout<<"Shape 3: "; for (i=0;i<4;i++) cin>>c1[i]>>c2[i]; cin.ignore(25, '\n'); cout<<"Shape 4: "; for (i=0;i<4;i++) cin>>d1[i]>>d2[i]; cin.ignore(25, '\n'); cout<<"Shape 5: "; for (i=0;i<4;i++) cin>>e1[i]>>e2[i];*/ length=getLength(); width=getWidth(); maxX=getMaxX(); minX=getMinX(); maxY=getMaxY(); minY=getMinY(); area=getArea(); type=getType(); } void print1(Shape Shapes[], float totalarea) { cout<<"Shape#"<<"Type"<<"Area(sq/units)"<=90) cout<<"The layout is efficient, it uses "<a[1] && a[2]>a[3] && a[2]>a[4]) maxX=a[2]; if(a[3]>a[1] && a[3]>a[2] && a[3]>a[4]) maxX=a[3]; if(a[4]>a[1] && a[4]>a[2] && a[4]>a[3]) maxX=a[4]; //if(a1[3]>a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return maxX; } int Shape::getMaxY() { int maxY=b[1]; if(b[2]>b[1] && b[2]>b[3] && b[2]>b[4]) maxY=b[2]; if(b[3]>b[1] && b[3]>b[2] && b[3]>b[4]) maxY=b[3]; if(b[4]>b[1] && b[4]>b[2] && b[4]>b[3]) maxY=b[4]; //if(a2[3]>a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return maxY; } int Shape::getMinX() { int minX=a[1]; if(a[2]a1[1] && a1[3]>a1[2] && a1[3]>a1[0]) //MaxX=a1[3]; return minX; } int Shape::getMinY() { int minY=b[1]; if(b[2]a2[1] && a2[3]>a2[2] && a2[3]>a2[0]) //MaxY=a2[3]; return minY; } int Shape::getArea() { return length*width; } string Shape::getType() { if(length == width) return "Square"; else return "Rectangle"; } float totArea(Shape Shapes[]) { float totalArea; totalArea = 0; for (int i=0;i<5;i++) { totalArea += Shapes[i].area; } return totalArea; } int main() { int i,newlength,newwidth, newMinX = 0, newMaxX = 15, newMaxY = 10, newMinY = 0; float effic, newarea, totalarea; string type; Shape Shapes[5]; //declare an array of 5 objects of t\ype Shape Shape myS1[5]; Shape myS2; //call a function to load the user input into each object for(i=0;i<5;i++) Shapes[i].setData(); cout<

here's the output

 ```0 0 0 5 14 5 14 0 0 5 0 10 5 10 5 5 5 5 5 10 10 10 10 5 10 7 10 8 13 8 13 7 10 5 10 7 15 7 15 5 Shape#TypeArea(sq/units) 1 Square0 2 Square0 3 Square0 4 Square0 5 Square0 The total area of the shapes is: 0sq/units Minimum material specifications: Length: 15Width: 10Area: 150 The layout is inefficient, it uses 0of the space Press any key to continue . . .```

so close
another update, got everything to work. I believe my problem was that I was using length=getLength() and width=getWidth() first before using MaxX, MinX, MaxY, MinY which causes my numbers to not work out well because I need MaxX, MinX, MaxY, and MinY first before being able to set values for Length and Width.

Anyway, here's my updated code (just need to make it more efficient)

 ```#include #include #include using namespace std; class Shape { public: Shape(); int getArea(); int getWidth(int, int); int getLength(int, int); int getMaxX(); int getMaxY(); int getMinX(); int getMinY(); int newArea(); float totArea(); float eff(); string getType(); void setData(); void print1(); void print3(); void print4(); int length, width, a[4], b[4], area, totalArea, newarea; string type; private: int maxx, maxy, minx, miny; }; Shape::Shape() { } void Shape::setData() { int MaX, mix, MaY, miy; cin>>a[0]>>b[0]>>a[1]>>b[1]>>a[2]>>b[2]>>a[3]>>b[3]; MaX=getMaxX(); mix=getMinX(); MaY=getMaxY(); miy=getMinY(); length=getLength(MaX, mix); width=getWidth(MaY, miy); area=getArea(); type=getType(); } void print1(Shape Shapes[], float totalarea) { cout<=90) cout<<"The layout is efficient, it uses "<a[0]) MaX=a[1]; if(a[2]>a[0]) MaX=a[2]; if(a[3]>a[0]) MaX=a[3]; return MaX; } int Shape::getMaxY() { int MaY=b[0]; if(b[1]>b[0]) MaY=b[1]; if(b[2]>b[0]) MaY=b[2]; if(b[3]>b[0]) MaY=b[3]; return MaY; } int Shape::getMinX() { int mix=a[0]; if(a[1]

and output is:
 ```0 0 0 5 14 5 14 0 0 5 0 10 5 10 5 5 5 5 5 10 10 10 10 5 10 7 10 8 13 8 13 7 10 5 10 7 15 7 15 5 Shape# Type Area(sq/units) 1 Rectangle 70 2 Square 25 3 Square 25 4 Rectangle 3 5 Rectangle 10 The total area of the shapes is: 133 sq/units Minimum material specifications: Length: 15 Width: 10 Area: 150 sq/units The layout is inefficient, it uses 89% of the space Press any key to continue . . .```

thanks for the help guys!
Topic archived. No new replies allowed.