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

Please write this program in C++ and make sure it runs before submitting for poi

ID: 643548 • Letter: P

Question

Please write this program in C++ and make sure it runs before submitting for points.

Write a program that

          - defines the class Cuboid which has the following:

                   - default constructor (has no parameters)

                   - constructor that has 3 parameters (height, length, width)

                   - data members

                             - height, length, width

                   - member functions

                             - one to initialize the data members

                             - one to get the values of the data members

                             - one that returns the volume

                             - one that returns the surface area

                             - one that increases each dimension by a specified factor

                   (Function definitions outside of the class!!!)

          - in main()

                   - instantiate a Cuboid object and initialize at the time of definition

                             - make sure the constructor with parameters is called

                      - define an array of 2 Cuboid objects

                             - use a loop to have the user enter the height, length, width for

                               these 2 objects

                   - increase one of the three objects by a certain factor

                   - display the dimensions , the volume, and the surface area for each of

                      the three objects

Explanation / Answer

#include <iostream>

using namespace std;

class Cuboid
{
private:
   float l, b, h;
public:
   Cuboid();
   Cuboid(float len, float br, float he);
   void Init(float len, float br, float he);
   float GetLength();
   float GetBreadth();
   float GetHeight();
   float GetVolume();
   float GetSurfaceArea();
   void IncreaseBy(float d);
};

Cuboid::Cuboid(){}
Cuboid::Cuboid(float len, float br, float he)
{
   l = len; b = br; h = he;
}
void Cuboid::Init(float len, float br, float he)
{
   l = len; b = br; h = he;
}
float Cuboid::GetLength()
{
   return l;
}
float Cuboid::GetBreadth()
{
   return b;
}
float Cuboid::GetHeight()
{
   return h;
}
float Cuboid::GetVolume()
{
   return l*b*h;
}
float Cuboid::GetSurfaceArea()
{
   return 2 * (l*b + b*h + l*h);
}
void Cuboid::IncreaseBy(float d)
{
   l += d; b += d; h += d;
}

int main()
{
   Cuboid a(1.0, 2.0, 3.0);
   Cuboid b[2];
   float len, br, he;
   for (int i = 0; i < 2; i++)
   {
       cout << "Enter length,breadth and height:";
       cin >> len >> br >> he;
       b[i].Init(len, br, he);
   }

   b[0].IncreaseBy(2.6);
   cout << "Length:" << a.GetLength() << " Breadth:" << a.GetBreadth() << " Height:" << a.GetHeight() << " Volume:" << a.GetVolume() << " Surface Area:" << a.GetSurfaceArea() << endl;
   cout << endl;
   for (int i = 0; i < 2; i++)
   {
       cout << "Length:" << b[i].GetLength() << " Breadth:" << b[i].GetBreadth() << " Height:" << b[i].GetHeight() << " Volume:" << b[i].GetVolume() << " Surface Area:" << b[i].GetSurfaceArea() << endl;
       cout << endl;
   }
}