The difference between implementing "elevator" in C and C++

C

Process oriented:

      The elevator does not allow foretelling, so the program needs to process passenger requests one by one and update the current state of each variable.
      How to get the shortest time: whether to respond to the request immediately, calculate the total time under different decisions, compare and choose the shortest time

C++

Object-oriented: The objects in the question are: elevator, passengers
  • Elevator
    1) Member variables: elevator floor, elevator target floor, elevator door status (to record whether the elevator currently responds to the passenger request), the current running direction of the elevator
    2) Member function:
          the elevator responds to the request to reach the target floor - update the elevator floor The
          elevator receives the next command and goes to the target floor - update the elevator target floor
          The elevator stops at the current floor - record the current elevator door status
  • Passenger
    1) Member variables: the floor of the passenger, the target floor, the time when the passenger made the request, the current status of the passenger (requested/in progress/unfinished), the time to complete the request
    2) Member function:
          the passenger gets on/off the elevator, that is, update Passenger Current Status
          Passenger Waiting Total Time

the differencebroken thoughts

      Why do I think the implementation of C and C++ is the same in the end (;´д`)ゞ
      Both simulate the elevator status and update it continuously, but it will be clearer to design the code logic from the perspective of the object, the call of the class makes the program various The relationship between members is clearer, and how to make better decisions is still the focus of my efforts

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325425355&siteId=291194637
Recommended