Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Referring to struct Square that you wrote for Shapes v . 2 in the last module, rewrite the struct definition and supporting function prototype so
Referring to struct Square that you wrote for Shapes v in the last module, rewrite the struct definition and supporting function prototype so that the supporting function becomes a member function instead.
Just write the struct definition...
#include
#include
#include
#include
using namespace std;
Structs for shapes
struct Square
double side;
;
struct Rectangle
double length;
double width;
;
struct Circle
double radius;
;
struct Triangle
double base;
double height;
;
struct Cube
double side;
;
struct Box
double length;
double width;
double height;
;
struct Cylinder
double radius;
double height;
;
struct Prism
double baseSide;
double height;
;
Function to output each shape to console
void outputSquareostream &out, const Square &square
out "Square: Side square.side endl;
void outputRectangleostream &out, const Rectangle &rectangle
out "Rectangle: Length rectangle.length
Width rectangle.width endl;
void outputCircleostream &out, const Circle &circle
out "Circle: Radius circle.radius endl;
void outputTriangleostream &out, const Triangle &triangle
out "Triangle: Base triangle.base
Height triangle.height endl;
void outputCubeostream &out, const Cube &cube
out "Cube: Side cube.side endl;
void outputBoxostream &out, const Box &box
out "Box: Length box.length Width box.width
Height box.height endl;
void outputCylinderostream &out, const Cylinder &cylinder
out "Cylinder: Radius cylinder.radius
Height cylinder.height endl;
void outputPrismostream &out, const Prism &prism
out "Prism: Base Side prism.baseSide
Height prism.height endl;
int main
vector shapes; Using vector to store shapes
ifstream finshapestxt; Input file
ofstream foutoutputtxt; Output file
char shapeType;
while fin shapeType
void shapePtr nullptr;
switch shapeType
case S:
Square square new Square;
fin squareside;
shapePtr square;
break;
case R:
Rectangle rectangle new Rectangle;
fin rectanglelength rectanglewidth;
shapePtr rectangle;
break;
case C:
Circle circle new Circle;
fin circleradius;
shapePtr circle;
break;
case T:
Triangle triangle new Triangle;
fin trianglebase triangleheight;
shapePtr triangle;
break;
case B:
Box box new Box;
fin boxlength boxwidth boxheight;
shapePtr box;
break;
case Y:
Cylinder cylinder new Cylinder;
fin cylinderradius cylinderheight;
shapePtr cylinder;
break;
case P:
Prism prism new Prism;
fin prismbaseSide prismheight;
shapePtr prism;
break;
default:
break;
shapes.pushbackshapePtr;
Output to console
for const auto &shape : shapes
switch shapeType
case S:
outputSquarecoutstaticcastshape;
break;
case R:
outputRectanglecoutstaticcastshape;
break;
case C:
outputCirclecoutstaticcastshape;
break;
case T:
outputTrianglecoutstaticcastshape;
break;
case B:
outputBoxcoutstaticcastshape;
break;
case Y:
outputCylindercoutstaticcastshape;
break;
case P:
outputPrismcoutstaticcastshape;
break;
default:
break;
Output to file
for const auto &shape : shapes
switch shapeType
case S:
outputSquarefoutstaticcastshape;
break;
case R:
outputRectanglefoutstaticcastshape;
break;
case C:
outputCirclefoutstaticcastshape;
break;
case T:
outputTrianglefoutstaticcastshape;
break;
case B:
outputBoxfoutstaticcastshape;
break;
case Y:
outputCylinderfoutstaticcastshape;
break;
case P:
outputPrismfoutstaticcastshape;
break;
default:
break;
Deallocate memory
for auto &shape : shapes
delete shape;
fout.close; Close output file
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started