What Are Common Mistakes When Programming an Elevator System in C++?

Click For Summary

Discussion Overview

The discussion revolves around common mistakes encountered when programming an elevator system in C++. Participants are addressing specific coding errors and conceptual misunderstandings related to class design and function declarations within the context of a homework assignment.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant presents a homework statement requiring the creation of an Elevator class with specific functionalities, including error handling for floor requests.
  • The participant's code snippet includes a constructor and a request function, but there is confusion regarding the function's parameters and definitions.
  • Another participant points out that the request function is declared with one parameter but defined with two, leading to a compilation error.
  • A later reply mentions a separate linker error indicating that an entry point must be defined, suggesting a potential issue with the overall program structure.
  • One participant expresses frustration with their understanding of computer science but later finds an external resource that addresses their issue.

Areas of Agreement / Disagreement

Participants generally agree on the nature of the coding errors but do not reach a consensus on the best way to resolve the issues, as one participant finds an external link that may or may not address the problem effectively.

Contextual Notes

The discussion highlights limitations in the provided code, such as the need for a proper entry point in the program and the handling of function parameters, which remain unresolved within the thread.

sheepcountme
Messages
80
Reaction score
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

{
count << "Starting at floor " << currentFloor << endl;

while (newfloor > currentFloor)
{
currentFloor++;
count << "Going up – now at floor " << currentFloor << endl;
}
count << "Stopping at floor " << currentFloor << endl;
}

else // move elevator down
{

count << "Starting at floor " << currentFloor << endl;
while (newfloor < currentFloor)

{

currentFloor--;

count << "Going down – now at floor " << currentFloor << endl;
}

count << "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'
 
Physics news on Phys.org
As the compiler says you have defined a function Request(int,int) but only declared a Request(int)
 
Ah, okay thank you. I'm so awful at comp science.

After fixing that I got just one more error:

LINK : fatal error LNK1561: entry point must be defined

any ideas??
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 15 ·
Replies
15
Views
7K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
7K