zoukankan      html  css  js  c++  java
  • 第二次c艹作业

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

    类的代码如下
    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++;//送乘客
    

    }

  • 相关阅读:
    Linux shell脚本学习
    正则表达式 学习-编辑
    新装ubuntu使用vi时方向键不起作用
    vi
    ln
    crontab
    64bit ubuntu 14 04 LTS 安装 google chrome
    64bit ubuntu 14 04 LTS 安装 adobe flash player
    glogin.sql的常用配置
    sql基本语句(一)select
  • 原文地址:https://www.cnblogs.com/menmamizigeda/p/8999601.html
Copyright © 2011-2022 走看看