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

(C++ please) please help me with questions 3 and 4. if possible plz screen shot

ID: 3852951 • Letter: #

Question

(C++ please) please help me with questions 3 and 4. if possible plz screen shot the outputs of each part

3. Enter elevator.cpp and perform the following operations:

a) Examine the source code, compile, and execute the program. .

b) Modify elevator.cpp to add a new member function called getFloor(), which returns the floor the elevator is currently on. Then call this function from within main() and have main() output the returned value. Compile and execute the program. Submit the code and the output.

c) Create an array E of three elevators inside main() and initialize each elevator in the array. Send the first elevator to the 8th floor, the second elevator to the 3rd floor, and the third elevator to the 5th floor. Compile and execute the program generating appropriate output. Submit the code and the output.

d) Pointers to struct variables work the same way they do in C. Create a pointer eptr to an elevator and initialize it to the second elevator. Use this pointer to send the elevator to the 4th floor. Compile and execute the program. Submit the code and the output.

4. Member functions do not take up space inside each variable of the new type. The struct is only as big as the data members it contains. Prove this to yourself by writing a program strsize.cpp which creates a struct with both data and function members, and an identical struct with data members only. Print the sizeof each struct variable and compare the two values. Submit the code and the output.

------------------------------------------------------------------------------------------------------------------------------

Elevator.cpp is below:

#include

#define FLOORS 10

using namespace std;

struct elevator {

int floorSelected;

int floorNumber;

void initialize();

void selectFloor(int floor);

void go();

};

void elevator::initialize() {

floorSelected

= 0;

floorNumber = 0;

}

void elevator::selectFloor(int floor) {

if (floor < 0 || floor >= FLOORS)

return;

floorSelected = floor;

}

void elevator::go() {

if (floorNumber < floorSelected)

while (++floorNumber < flo

orSelected)

cout << "floor: " << floorNumber << " going up!" << endl;

else if (floorNumber > floorSelected)

while (

--

floorNumber > floorSelected)

cout << "floor: " << floorNumber << " going down!" << endl;

cout << "floor: " << floorNumber << " stopping." << endl;

}

int main() {

elevator A;

A.initialize();

A.selectFloor(7);

A.go();

}

Explanation / Answer

Elevator.cpp :

#include
#define FLOORS 10
using namespace std;
struct elevator {
int floorSelected;
int floorNumber;
void initialize();
void selectFloor(int floor);
void go();
};
void elevator::initialize() {
floorSelected
= 0;
floorNumber = 0;
}
void elevator::selectFloor(int floor) {
if (floor < 0 || floor >= FLOORS)
return;
floorSelected = floor;
}
void elevator::go() {
if (floorNumber < floorSelected)
while (++floorNumber < flo
orSelected)
cout << "floor: " << floorNumber << " going up!" << endl;
else if (floorNumber > floorSelected)
while (
--
floorNumber > floorSelected)
cout << "floor: " << floorNumber << " going down!" << endl;
cout << "floor: " << floorNumber << " stopping." << endl;
}
int main() {
elevator A;
A.initialize();
A.selectFloor(7);
A.go();
}