- #1
sheepcountme
- 80
- 1
Homework Statement
This program simulates the actions of two elevators in a building. The building has MAXFLOOR floors - make this a program constant and set it to 15.
You need to write an Elevator class. This class will have only one member variable, which is the floor of the building on which the elevator is currently located. You will need a default constructor for the class (one with no arguments) that sets the member variable to 1. You will also need an accessor function for the member variable. Finally, you will need a member function of the class that is invoked whenever someone presses the button to call the elevator to come to some floor x. This function (name it call) should have a single parameter for the requesting floor x, and should do the following:
1. Check to see that the value of x is between 1 and MAXFLOOR. If the floor request is out of range, report that this is an invalid request and do nothing.
2. If x is the current floor, write out "Doors Opening"
3. If x is above the current floor, write out the starting floor, a message that the elevator is going up, and the successive floor numbers until it gets to floor x.
4. If x is below the current floor, do something similar for going down.
The application code should do the following:
1. Create two elevator objects
2. For every elevator call, decide which of the two elevators is closer to the requesting floor and dispatch that elevator.
Homework Equations
c++ stuff
The Attempt at a Solution
#include <iostream>
using namespace std;
class Elevator
{ private:
int currentFloor;
int MAXFLOOR;
public:
Elevator(int = 1);
void request(int);
};
Elevator::Elevator(int cfloor)
{
currentFloor = cfloor;
}
void Elevator::request(int newfloor, int MAXFLOOR)
{
MAXFLOOR=15;
if (newfloor < 1 || newfloor > MAXFLOOR || newfloor == currentFloor)
; // doing nothing
else if (newfloor > currentFloor) // move elevator up
{
cout << "Starting at floor " << currentFloor << endl;
while (newfloor > currentFloor)
{
currentFloor++;
cout << "Going up – now at floor " << currentFloor << endl;
}
cout << "Stopping at floor " << currentFloor << endl;
}
else // move elevator down
{
cout << "Starting at floor " << currentFloor << endl;
while (newfloor < currentFloor)
{
currentFloor--;
cout << "Going down – now at floor " << currentFloor << endl;
}
cout << "Stopping at floor " << currentFloor << endl;
}
return;
}
I am getting the following errors but I don't understand what it says is wrong with my program or how to fix it...
elevator.cpp(23): error C2511: 'void Elevator::request(int,int)' : overloaded member function not found in 'Elevator'
elevator.cpp(5) : see declaration of 'Elevator'