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

Write a class, named solids, which should combine the cube, prism and cylinder c

ID: 3868709 • Letter: W

Question

Write a class, named solids, which should combine the cube, prism and cylinder classes into a single template class.
A specimen of the main program that instantiates the cylinder, prism and cube classes is listed below:

correct the below code and run it in c++

template <typename T>

class solid : public T

{

public:

double compute_volume()

{

return (height*compute_area());

}

double compute_surface_area()

{

return (height*compute_perimeter() + 2 * compute_area());

}

};

int main(void)

{

circle cir;

triangle tri;

square sqr;

cylinder cyl;

prism pri;

cube cube;

cir.set_side(1);

// print the area and perimeter of the object

cout << "Area of Circle: " << cir.compute_area() << endl;

cout << "Circumference of Circle: " << cir.compute_perimeter() << endl << endl;

tri.set_side(5);

// print the area and perimeter of the object

cout << "Area of Triangle: " << tri.compute_area() << endl;

cout << "Perimeter of Triangle: " << tri.compute_perimeter() << endl << endl;

sqr.set_side(7);

// print the area and perimeter of the object

cout << "Area of Square: " << sqr.compute_area() << endl;

cout << "Perimeter of Square: " << sqr.compute_perimeter() << endl << endl;

cyl.set_side(1);

cyl.set_height(2);

// print the volume and surface area of the object

cout << "Volume of Cylinder: " << cyl.compute_volume() << endl;

cout << "Surface Area of Cylinder: " << cyl.compute_surface_area() << endl << endl;

pri.set_side(5);

pri.set_height(6);

// print the volume and surface area of the object

cout << "Volume of Prism: " << pri.compute_volume() << endl;

cout << "Surface Area of Prism: " << pri.compute_surface_area() << endl << endl;

cube.set_side(3);

cube.set_height(4);

// print the volume of the object

cout << "Volume of Cube: " << cube.compute_volume() << endl;

cout << "Surface Area of Cube: " << cube.compute_surface_area() << endl << endl;

return 0;

}

Explanation / Answer

class solid : public T

{

public:

double compute_volume()

{

return (height*compute_area());

}

double compute_surface_area()

{

return (height*compute_perimeter() + 2 * compute_area());

}

};

int main(void)

{

circle cir;

triangle tri;

square sqr;

cylinder cyl;

prism pri;

cube cube;

cir.set_side(1);

cout << "Area of Circle: " << cir.compute_area() << endl;

cout << "Circumference of Circle: " << cir.compute_perimeter() << endl << endl;

tri.set_side(5);

cout << "Area of Triangle: " << tri.compute_area() << endl;

cout << "Perimeter of Triangle: " << tri.compute_perimeter() << endl << endl;

sqr.set_side(7);

cout << "Area of Square: " << sqr.compute_area() << endl;

cout << "Perimeter of Square: " << sqr.compute_perimeter() << endl << endl;

cyl.set_side(1);

cyl.set_height(2);

cout << "Volume of Cylinder: " << cyl.compute_volume() << endl;

cout << "Surface Area of Cylinder: " << cyl.compute_surface_area() << endl << endl;

pri.set_side(5);

pri.set_height(6);

cout << "Volume of Prism: " << pri.compute_volume() << endl;

cout << "Surface Area of Prism: " << pri.compute_surface_area() << endl << endl;

cube.set_side(3);

cube.set_height(4);

cout << "Volume of Cube: " << cube.compute_volume() << endl;

cout << "Surface Area of Cube: " << cube.compute_surface_area() << endl << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote