Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions In this assignment, you will modify the Beam class that is already provided. You will add some new functionality to the class by adding

Instructions

In this assignment, you will modify the Beam class that is already provided. You will add some new functionality to the class by adding additional functions to the file beam.cpp. A header file beam.h with the data members and function prototypes is already uploaded. There is also a main program called main_hw.cpp that uses this new functionality. Do not modify either beam.h or main_hw.cpp. Start with your beam.cpp file and make additions to it. Compiling and running main_hw.cpp with your new beam.cpp class file will produce the output shown below. You can also test your class file after submission.

Your program must have the following:

An additional (overloaded) constructor function that takes 2 input float parameters, the length and depth in that order, and uses these values instead of the default values. Everything else will be the same as the default case.

A new accessor function call getWidth() that returns the width as type float.

A new operator << that takes a string and assigns it to a new private data member of type string.

A new accessor function called getName() that returns the name as a string.

Sample Output:

Width: 7.56 Name: Joe 

beam.h

#ifndef BEAM_H

#define BEAM_H

#include

using namespace std;

class Beam {

public:

Beam();

Beam(float len, float dep);

void setLength(float length);

float getLength();

float getWidth();

string getName();

void printStats();

Beam operator+(Beam b);

Beam operator<<(string n);

private:

float length, width, depth;

enum Material {STEEL, ALUM};

Material material;

bool composite;

std::string name;

};

#endif

beam.cpp

#include #include "beam.h"

/* start with your program from lab here */

main_hw.cpp

#include

#include "beam.h"

int main() {

Beam beam1(40,24);

beam1 << "Joe";

cout << "Width: " << beam1.getWidth() << endl;

cout << "Name: " << beam1.getName() << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Systems A 360-degree Approach

Authors: Jawwad ShamsiMuhammad Khojaye

1st Edition

0429531575, 9780429531576

More Books

Students also viewed these Databases questions