Second Object Oriented Programming Assignment

The general idea of ​​c language and c++ implementation

C language
First, you can use floor[]an array to store the request when reading the request, and then simulate the operation of the elevator, and judge whether there is a request that meets the conditions when it is running, and process the request if there is. At the same time, it is also necessary to judge whether there are passengers entering or exiting the elevator. If there is an elevator, it will stop. The elevator stops and the time changes. It is necessary to judge again whether there is a new request to be processed. Re-judgment to go to the floor.
Because C++
is C++, an elevator class must be built. Because of the existence of member functions, several judgment codes in the C process can be integrated into several member functions. In fact, in the implementation of c, these can also be implemented with functions, but the advantage of c++ may be that it can change multiple variables without so many parameters. Process the request in the main function, call the stop function, judge whether to stop, then call goingfloorthe floor to judge the going, and finally execute the goingfunction to realize the operation of the elevator.

In general, there is still a big difference between the two, but I still use the idea of ​​c in terms of thinking. From the point of view of process-oriented and object-oriented names, process-oriented solves the problem of having multiple objects in a process. Participate in the problem, while in object-oriented objects can participate in multiple processes at the same time. Well, there are many features of c++ mentioned in the MOOC, but these are not the difference in the starting point of thinking. The above is just my personal conjecture. There are still many doubts about the difference between c and c++.

Elevator

#include<iostream>
using namespace std;
class Elevatorscheduling
{
    public:
        
        int currentfloor; //当前位置
        int indicator; //运行方向
        int people;//电梯内人数 
        int t;//时间 
        int nextfloor;
        Elevatorscheduling();//初始化 
        ~Elevatorscheduling();
        void destinationfloor(int gotofloor);
        void showfloor();
};
Elevatorscheduling::Elevatorscheduling()
{
    currentfloor=0;
    indicator=0;
    people=0;
    t=0;
}
Elevatorscheduling::~Elevatorscheduling()
{
    
}
void Elevatorscheduling::destinationfloor(int gotofloor)
{
    nextfloor=gotofloor;
    if(nextfloor>currentfloor)
    {
        indicator=1;
    }
    else if(nextfloor<currentfloor)
    {
        indicator=-1;
    }
}
void Elevatorscheduling::showfloor()
{
    cout<<currentfloor<<endl;
}

Guess you like

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