Elevator Program - Newbie to C++

Hey everyone. Im just starting out in C++ and need a little bit of help on a project I am doing. I have the output / test cpp done already and most of the 'h' file.

I need help with the '.cpp' file and a look over of my 'h' file.

Instructions: Need to write a class definition and implement the member functions for class elevator with a constructor that places an elevator at a selected floor. Include a select member function that allows floors to be selected. For every floor, the message going up or going down should be displayed before the current floor.

Sample output that the book gave:

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
doing down to 3
open at 3


Output / cpp file (I have already gone over this part with another classmate and this file is done)
1
2
3
4
5
6
7
8
9
10
11
// same as 8H.cpp

#include "elevator.h" // student work is in elevator, elevator.h and elevator.cpp
int main()
{
  elevator aLift(1);
  aLift.select(5);
  aLift.select(3);

  return 0;
}


my h file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef ELEVATOR_H
#define ELEVATOR_H

#include <iostream>
#include <string>
using namespace std;

class elevator {

public:

	elevator();

	//--constructor

	elevator(int initFloor);


	//--modifiers

	void select(int selected_floor);


	//--accessors

	int aLift() const;



private:
	int	my_floor;



};


#endif 


I dont have anything for the elevator.cpp as of yet. Still working through it now
Looks fine so far. Might be a little strange to call your object by the same name as a class member.

Since they want messages printed you could add another member for that purpose. The outputs all have a msg and a number so you could create a function like that too. A 'get_floor()' accessor would be useful for that msg.
Last edited on
Topic archived. No new replies allowed.