In this assignment you will modify the Beam class that you s

In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functions and/or attributes to the files beam.cpp and beam.h. A revised version of main.cpp is given with this assignment that will use the new functionality you have included. Your completed assignment will compile and link with this version of main.cpp to produce the output shown below.

Your program must have or do the following:

An additional (overloaded) constructor function that takes 2 float parameters of length and depth and sets those instead of the default values. Everything else will be the same as the default case.

A new function called setDepth(float depth). Be sure to correctly set the width within this function.

A new operator << that takes a string and assigns it to the name of the beam object. This means you also need to add a private data member of type string name to the object.

Modify printStats() to also print the beam name.

Sample Output

Length: 40 ft

Width: 4.41 in

Depth: 14 in

Material: steel

Name: Joe

This is the beam.h code

#ifndef BEAM_H

#define BEAM_H

using namespace std;

class Beam

{

   private:

       float length, width, depth;  

       enum Material {STEEL, ALUM};

       Material material;  

  

  

   public:

       Beam();

       void setLength(float len);

       float getLength();

       void printStats();

       Beam operator+(Beam a);

};

#endif


This is the beam.cpp code

#include <iostream>

#include \"beam.h\"

Beam :: Beam()

{

   length = 20;

   depth = 12;

   width = .315*depth;

   material = STEEL;

  

}

void Beam :: setLength(float len)

{

   length = len;

}

float Beam :: getLength()

{

   return length;

}

void Beam :: printStats()

{

   cout << \"Lenth: \" << length << endl;

   cout<< \"width: \" << width << endl;

   cout << \"Depth: \" << depth << endl;

   cout << \"Material: \";

   switch(material)

   {

       case STEEL:

           cout << \"steel\ \";

           break;

       case ALUM:

           cout << \"aluminum\ \";

           break;

           default:

           break;

       }

   }

Beam Beam :: operator+(Beam a)

{

   Beam b;

  

   b.length = length + a.length;

   b.depth = depth + a.depth;

   b.width = width + a.width;

  

   return b;

}

This is the main.cpp code

This is the beam.h code

#ifndef BEAM_H

#define BEAM_H

using namespace std;

class Beam

{

   private:

       float length, width, depth;  

       enum Material {STEEL, ALUM};

       Material material;  

  

  

   public:

       Beam();

       void setLength(float len);

       float getLength();

       void printStats();

       Beam operator+(Beam a);

};

#endif


This is the beam.cpp code

#include <iostream>

#include \"beam.h\"

Beam :: Beam()

{

   length = 20;

   depth = 12;

   width = .315*depth;

   material = STEEL;

  

}

void Beam :: setLength(float len)

{

   length = len;

}

float Beam :: getLength()

{

   return length;

}

void Beam :: printStats()

{

   cout << \"Lenth: \" << length << endl;

   cout<< \"width: \" << width << endl;

   cout << \"Depth: \" << depth << endl;

   cout << \"Material: \";

   switch(material)

   {

       case STEEL:

           cout << \"steel\ \";

           break;

       case ALUM:

           cout << \"aluminum\ \";

           break;

           default:

           break;

       }

   }

Beam Beam :: operator+(Beam a)

{

   Beam b;

  

   b.length = length + a.length;

   b.depth = depth + a.depth;

   b.width = width + a.width;

  

   return b;

}

This is the main.cpp code

  #include <iostream>  #include \"beam.h\"    int main() {          Beam beam1; // LAB          //beam1.printStats();  // LAB            Beam beam2;  // LAB          beam2 = beam1 + beam1; // LAB          beam2 << \"Joe\"; // HW          beam2.setDepth(14); // HW          beam2.printStats(); // LAB          return 0;  }  

Solution

// modify beam.cpp code

#include <iostream>

#include \"beam.h\"

Beam :: Beam()

{

   length = 20;

   depth = 12;

   width = .315*depth;

   material = STEEL;

}

void Beam :: setLength(float len)

{

   length = len;

}

float Beam :: getLength()

{

   return length;

}

void Beam :: printStats()

{

   cout << \"Lenth: \" << length << endl;

   cout<< \"width: \" << width << endl;

   cout << \"Depth: \" << depth << endl;

   cout << \"Material: \";

cout<<\"Beamname:<<bname<<endl;

   switch(material)

   {

       case STEEL:

           cout << \"steel\ \";

           break;

       case ALUM:

           cout << \"aluminum\ \";

           break;

           default:

           break;

       }

   }

Beam Beam :: operator+(Beam a)

{

   Beam b;

  

   b.length = length + a.length;

   b.depth = depth + a.depth;

   b.width = width + a.width;

  

   return b;

}

Beam::Beam(float lenght, float depth) // contructor for Beam class

{

length=setLength(4);

depth=setDepth(5.2);

}

float beam::setDepth(float) //setdepth function

{

praivate string bname;

praivate float width=3.2;

beam b;

cout<<\"enter beam name \";

cin>>bname;

b.bname=bname;

}

This is the main.cpp code

In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio
In this assignment, you will modify the Beam class that you started in lab. You will add some additional functionality to the class by adding additional functio

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site