第二次c艹作业

1,c语言实现方法:按照电梯运行方式,改变被定义为全局变量的结构体的数值。
c艹实现方法:用类来存放电梯的属性,整个过程都是对类操作。
两者不同:c语言是面向过程的,整个函数里都要对电梯的参数进行修改;而c++在程序运行中是对表示电梯状态类进行修改。1330851-20180506230831753-1798005815.png

类的代码如下
elevator.h

pragma once

class elevator
{
public:
int lift;//电梯所在楼层
int request;//请求的时间
int from;//请求的楼层
int to;//目的地楼层
int time;//总时间
elevator();
~elevator();
void move(int &lift, int from, int to, int &time, int request);
};

elevator.cpp

include"elevator.h"

include

include<math.h>

include

using namespace std;
void elevator::move(int &lift, int from, int to, int &time, int request)
{
int ss,sss; ss = lift;
if (request > time)
time += request - time;
time += abs(from - lift);
lift = from;//去接乘客
if (ss != from)
{

    cout << time << " " << lift << endl;time++;
}
time += abs(to - lift);
lift = to;
cout << time <<" "<< lift << endl;
if (ss != to)time++;//送乘客

}

转载于:https://www.cnblogs.com/menmamizigeda/p/8999601.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值