Problem with elevator program

I am new to C++ so just remember that I have never programmed before and I am just looking for some pointers on finishing this program. I have a main with output that is already complete. My problem is with the class file .h and .cpp. If anyone can just tell me some of my mistakes and an idea on how to fix them I will greatly appreciate it. I am trying to grasp the concept of class files interacting with main files.This is very simple for almost everyone on here but remember I am a beginner.

Main File with output:
#include <iostream>
#include <string>
using namespace std;
#include "elevator.h"
int main()
{
elevator aLift(1);
aLift.select(5);
aLift.select(3);

return 0;
}

Output must be:
start on floor 1
going up to 2
going up to 3
going up to 4
going up to 5
open at 5
going down to 4
going down to 3
open at 3


My problem is in my class files. I am not even sure what should be an accessor and what should be a modifier.

My .h file:
#include <string>
using namespace std;
class elevator {
public:

//--constructor

elevator(int initFloor);


//--modifiers

void select(int selected_floor);


//--accessors

int aLift() const;






private:
int my_floor;





my .cpp file:

#include <iostream>
#include <string>
using namespace std;
#include "elevator.h"


//--constructors

elevator::elevator(int initFloor)
{
my_floor = initFloor;

}

//--modifier

void elevator::select(int selected_floor)
{

while(my_floor < selected_floor)
cout << "Going up to " << ++my_floor << endl;

while(my_floor > selected_floor)
cout << "Going down to " << --my_floor << endl;
}

//--accessors

int elevator::aLift() const
{
return my_floor
}


I would appreciate anything that would put me in the right direction. I am not good with c++ lingo so in plain English if possible.
Last edited on
I may be wrong but I think #include "elevator.h" has to go before using namespace std;
Topic archived. No new replies allowed.