When in doubt I turn to you guys so thanks in advance.

Instructions: Create a C++ program that uses a class named Triangle (shown below) in order to produce a subclass of Triangle called Prism. Use the program to create a Prism object that calculates the volume and surface area of the Prism when supplied values for a width, height, and length of the Prism. As you can see, the width and height are defined in the Triangle class. The volume of the Prism should be calculated by multiplying the area of the triangle by the length of the Prism.

Prompt the user for the values of width, height, and length. Validate these values to make sure they are not negative. If a negative value is entered, force the user to make another entry. If all three values are zero, use a default constructor for Prism that takes the default value of width and height from Triangle and assigns a value of 10 to length in the default constructor of Prism. Within the subclass Prism include an overriding function named findArea() that computes the surface area of the prism (the sum of the areas of all five sides). Obtain the area of the end of the prism from the findArea() function in the Triangle class. Use this value and the area of each side to compute the total surface area of a Prism. (ie., surface area = 2 times the area of an end plus the three sides. You may assume that the ends are isosceles triangles – ie., 2 sides are equal length.)

You will need to compute the slanting side (ss) of the triangular end of the prism when computing the surface area. ss = square root of ( ½ width * ½ width + height * height)

Havn't formated the output yet want to figure everything else out first. I'm a little lost on subclasses. I'm getting some funky numbers back.Code:#include<iostream> #include<iomanip> #include<string> #include<math.h> using namespace std; class Triangle { protected: double width, height; public: Triangle(); Triangle(double, double); double getWidth(); double getHeight(); double findArea(); }; Triangle::Triangle() { width =7; height = 8; } Triangle::Triangle(double w, double h) { width = w; height = h; } double Triangle::findArea() { return(width * height * 0.5); } double Triangle::getWidth() { return width; } double Triangle::getHeight() { return height; } class Prism : public Triangle { private: double length; public: Prism(); Prism(double); double getLength(); double calcVolume(); double findArea(); }; Prism::Prism() : Triangle() { length = 10; } Prism::Prism(double l) : Triangle(width,height) { length = l; } double Prism::getLength() { return length; } double Prism::calcVolume() { return length * Triangle::findArea(); } double Prism::findArea() { double ss, surfArea; ss = sqrt(((.5 * width)*(.5 * width))+(height*height)); surfArea = (2*Triangle::findArea())+ 3*ss; return surfArea; } int main() { char loopValue = 'y'; double width, height, length; cout<<"===Lab 12 has successfully started for Drew Faber==="<<endl; do{ cout<<endl; cout<<"Enter the value for width "; cin>>width; while(width < 0) { cout<<endl; cout<<"The width may not be Negative! Please re-enter! "; cin>>width; } cout<<endl; cout<<"Enter the value for height "; cin>>height; while(height < 0) { cout<<endl; cout<<"The height may not be Negative! Please re-enter! "; cin>>height; } cout<<endl; cout<<"Enter the value for length "; cin>>length; while(length < 0) { cout<<endl; cout<<"The length may not be Negative! Please re-enter! "; cin>>length; } if(width == 0 && height == 0 && length == 0) { Prism myPrism; cout<<"The width of the Prism is "<<myPrism.getWidth()<<endl; cout<<"The height of the Prism is "<<myPrism.getHeight()<<endl; cout<<"The length of the Prism is "<<myPrism.getLength()<<endl; cout<<"The Volume is "<<myPrism.calcVolume()<<" cubic units"<<endl; cout<<"The Surface Area is"<<myPrism.findArea()<<" square units"<<endl; } else { Prism myPrism(length); cout<<"The width of the Prism is "<<myPrism.getWidth()<<endl; cout<<"The height of the Prism is "<<myPrism.getHeight()<<endl; cout<<"The length of the Prism is "<<myPrism.getLength()<<endl; cout<<"The Volume is "<<myPrism.calcVolume()<<" cubic units"<<endl; cout<<"The Surface Area is"<<myPrism.findArea()<<" square units"<<endl; } cout<<endl; cout<<"Would you like to enter more data(Y/N) "<<endl; cin>>loopValue; }while(loopValue == 'y' || loopValue == 'Y'); cout<<endl; cout<<"===Lab 12 has successfully terminated for Drew Faber==="; cout<<endl; system("pause"); }

Tweet This+ 1 thisPost To Linkedin