第三次C++作业

在用两种语言完成电梯调度问题时的感受

用C语言完成的电梯作业时:

   当我用C语言实现电梯问题的时候,我首先想到的就是怎么才能实现这个调度。
我首先把一个模拟电梯的函数给打了出来,先让这个程序模拟电梯的运行,然后加入了算法。在C语言完成电梯问题的过程中,我用了一个,我用了很多的函数来实现这个电梯的代码。就是想着怎么让这个电梯能完成这个最短时间的分配就好。于是我就把所有的变量写在这个Cpp里。
  我是这么完成的:
  1. 首先在代码中写出代码需要的变量。
  2. 然后我在把模拟电梯的函数打好。
    3。再加入电梯的调度算法。

    我用C++完成电梯问题时:

    我先建立了一个elevator类,然后再将这个类中的有关电梯的代码,电梯的变量打进去。就好像这个是专门负责电梯这一块的。在用C++打电梯的调度问题时,我用了一个cpp,一个.h把负责电梯的这一块代码写好,再放进头文件里。
    就是觉得如果C语言来实现这个代码的时候是一个车间的话,C++则是一个公司吧。。不知道这样说对不对emmm.
    然后下面是我的类。

class elevector
{
public:
    int currentFloor;
    int input[3];
    int time;
    int floor;
    int passengerFloor;
    int targetFloor;
    int requestTime;
    elevector(void) ;
    ~elevector() ;
    void goToFloor1(int passengerFloor, int targetFloor, int requestTime, int *time, int* floor);
    void goToFloor2(int passengerFloor, int targetFloor, int requestTime, int *time, int* floor);
    void stop(int* time);
    //void updateDestinationQ(int floor);


};
void elevector::goToFloor1(int passengerFloor, int targetfloor, int requestTime, int *time, int* floor)
{
    int *nowTime;
    nowTime = time;
    if (requestTime > *nowTime)
        *time += (abs)(requestTime - *nowTime);
    *time += (abs)(*floor - targetfloor);
    *floor = targetfloor;
}
void elevector::goToFloor2(int passengerFloor, int targetfloor, int requestTime, int *time, int* floor)
{
    int *nowTime;
    nowTime = time;
    if (requestTime>*nowTime)
        *time += (abs)(requestTime - *nowTime);
    *time += (abs)(*floor - passengerFloor);
    *floor = passengerFloor;
}
void elevector::stop(int* time)
{
    *time += 1;
}
elevector::elevector(void)
{
}


elevector::~elevector()
{
}

转载于:https://www.cnblogs.com/zhanglingxin/p/8999388.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值