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

If you have this code with two classes.. how do you initialize member data? What

ID: 3558057 • Letter: I

Question

If you have this code with two classes.. how do you initialize member data?

What code do you add to the constructor definitio so that an Elevator object member data variables are initialized such that man1 has weight 216 and the elevator fixed limit is set to whatever value is passed to its constructor?

class Person

{

public:

Person(int w); // weight is set to w

private:

int weight;

};

class Elevator

{

Public:

Elevator (int x); //elevator with weight limit x

private:

Person man1;

const int LIMIT; //weight limit for person on elevator

};   

Explanation / Answer

#include <iostream>
using namespace std;

class Person
{
public:
Person(int w=216); // weight is set to w
private:
int weight;
};
Person::Person(int w)
{
weight = w;
}

class Elevator
{
public:
Elevator (int x); //elevator with weight limit x
private:
Person man1;
const int LIMIT; //weight limit for person on elevator
};

Elevator::Elevator(int x):LIMIT(x)
{

}

int main()
{
   Elevator E1(4);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote