I am new to C++ and I have been working on this for a while to display volume for two classes of objects. What is wrong with the code I typed. Thank you!
#include <iostream>
#include <string>
using namespace std;
class Prism //setting the class as prism.
{
private:
double height;
double width;
double length;
public:
double getVolume(void)
{
return length * width * height;
}
int main()
{
Prism Prism1; //Declaring prism.
Pyramid Pyramid1; //declaring pryriamid.
double volume = 0.0; //setting what the volume is.
double Volume = 0.0; //setting what the volume is.
Prism1.setHeight(7.0); //setting the height for the prism.
Prism1.setWidth(7.0); //setting the Width for the prism.
Prism1.setLength(7.0); //setting the Length for the prism.
Pyramid1.setHeight(7.0); //setting the height for the pyriamid.
Pyramid1.setWidth(7.0); //setting the width for the pyriamid.
Pyramid1.setLength(7.0); //setting the length for the pyriamid.
volume = Prism1.getVolume(); //
cout << "The volmue of the rectangular prism is " << volume << ".\n"; //outputting a message of what the final volume is to the user.
Volume = Pyramid1.getVolume(); //
cout << "The volmue of the square base pyramid is " << Volume << ".\n"; //outputting a message of what the final volume is to the user.
#include <iostream>
#include <string>
usingnamespace std;
class Prism //setting the class as prism.
{
private:
double height;
double width;
double length;
public:
double getVolume(void)
{
return length * width * height;
}
void setLength(double l)
{
length = l;
}
void setWidth(double w)
{
width = w;
}
void setHeight(double h)
{
height = h;
}
void Display()
{
cout << "You have crafted a Rectangular prism.\n";
cout<<"Height "<<height<<endl;
cout<<"Width "<<width<<endl;
cout<<"Length "<<length<<endl;
}
};
class Pyramid
{
private:
double Height;
double Width;
double Length;
public:
double getVolume(void)
{
return (Length * Width * Height) / 3;
}
void setLength(double L)
{
Length = L;
}
void setWidth(double W)
{
Width = W;
}
void setHeight(double H)
{
Height = H;
}
void Display2()
{
cout << "You have crafted a Rectangular pyramid.\n";
cout<<"Height "<<Height<<endl;
cout<<"Width "<<Width<<endl;
cout<<"Length "<<Length<<endl;
}
};
int main()
{
Prism Prism1; //Declaring prism.
Pyramid Pyramid1; //declaring pryriamid.
double volume = 0.0; //setting what the volume is.
double Volume = 0.0;
Prism1.setHeight(7.0); //setting the height for the prism.
Prism1.setWidth(7.0); //setting the Width for the prism.
Prism1.setLength(7.0); //setting the Length for the prism.
Pyramid1.setHeight(7.0); //setting the height for the pyriamid.
Pyramid1.setWidth(7.0); //setting the width for the pyriamid.
Pyramid1.setLength(7.0); //setting the length for the pyriamid.
volume = Prism1.getVolume(); //
cout << "The volmue of the rectangular prism is " << volume << ".\n"; //outputting a message of what the final volume is to the user.
Prism1.Display();
Volume = Pyramid1.getVolume(); //
cout << "The volmue of the square base pyramid is " << Volume << ".\n"; //outputting a message of what the final volume is to the user.
Pyramid1.Display2();
return 0;
}