当前位置: 首页>>代码示例>>C++>>正文


C++ Floor::GetAbove方法代码示例

本文整理汇总了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;
}
开发者ID:ChrisDue,项目名称:Elevator,代码行数:57,代码来源:Elevator.cpp


注:本文中的Floor::GetAbove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。