本文整理汇总了C++中Floor::GetAbove方法的典型用法代码示例。如果您正苦于以下问题:C++ Floor::GetAbove方法的具体用法?C++ Floor::GetAbove怎么用?C++ Floor::GetAbove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Floor
的用法示例。
在下文中一共展示了Floor::GetAbove方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CanReachFloor
/**
* Checks if the middle of each floor is reachable from the elevator.
* @param lowestFloorOfElevator pointer of the lowest floor which has an interface to the elevator
* @param highestFloorOfElevator pointer of the highest floor which has an interface to the elevator
* @return pointer of the floor which is unreachable, otherwise returns null pointer
*/
Floor* Elevator::CanReachFloor(Floor *lowestFloorOfElevator, Floor *highestFloorOfElevator) {
bool currentFloorIsHighestFloor = true;
// pointer to the current floor, which will be checked
Floor *currentFloor = lowestFloorOfElevator;
// determines the half of the height of the current floor
double halfHeightOfCurrentFloor = currentFloor->GetHeight() / 2.0;
// height counter is used to check if an elevator can reach a floor
double heightCounter = halfHeightOfCurrentFloor;
// take the next floor above
currentFloor = currentFloor->GetAbove();
while (currentFloorIsHighestFloor) {
// determines the half of the height of the current floor
halfHeightOfCurrentFloor = currentFloor->GetHeight() / 2.0;
if (!HasFloor(currentFloor)) {
heightCounter += currentFloor->GetHeight();
} else {
heightCounter += halfHeightOfCurrentFloor;
double value = fmod(heightCounter, speed_);
heightCounter += halfHeightOfCurrentFloor;
// checks the determined value if it is unequal zero
if (value != 0) {
return currentFloor;
}
}
// checks if the current floor is the highest floor
if (currentFloor == highestFloorOfElevator) {
currentFloorIsHighestFloor = false;
} else {
currentFloor = currentFloor->GetAbove();
}
}
return nullptr;
}