• 软件工程课堂作业(七)续——电梯调度之整体设计


    一、题目要求:

          1、可以获得电梯和乘客所在楼层;

          2、可以根据乘客的需求到达想到达的楼层。

    二、设计思路:

          1、通过用户输入可以获取乘客和电梯所在楼层;

          2、通过循环,输出电梯向上/向下走的过程。

    三、源代码:

     1 // 电梯调度——胡亚宝
     2 //
     3 
     4 #include "stdafx.h"
     5 #include<iostream>
     6 using namespace std; 
     7 
     8 
     9 int _tmain()
    10 {
    11     int a,b,c,m,i;
    12     cout<<"***************************电梯运行模拟系统*******************************"<<endl;
    13     cout<<"请输入电梯所在楼层:";
    14     cin>>a;
    15     cout<<endl;
    16     cout<<"请输入乘客所在楼层:";
    17     cin>>b;
    18     cout<<endl;
    19     if(b>=2&&b<8)
    20     {
    21         cout<<"抱歉!电梯2-7楼停!"<<endl;
    22         cout<<"请重新输入乘客所在楼层:";
    23         cin>>b;
    24         cout<<endl;
    25     }
    26     cout<<"请选择乘客乘坐的方向:"<<endl;
    27     cout<<"上行(1)"<<endl;
    28     cout<<"下行(0)"<<endl;
    29     cin>>c;
    30     if(c==1)
    31     {
    32         if(a<b)
    33         {
    34             for(i=a+1;i<=b;i++)
    35             {
    36                 cout<<"电梯正在上行到第"<<i<<"层楼"<<endl;
    37                 
    38             }
    39         }
    40         else
    41         {
    42             for(i=b-1;i>=a;i--)
    43             {
    44                 cout<<"电梯正在下行到第"<<i<<"层楼"<<endl;
    45             }
    46         }
    47         cout<<'a'<<"电梯已到第"<<b<<"层,请进入电梯。"<<endl;    //'a'输出一个声音
    48         cout<<"请选择要去的楼层:";
    49         cin>>m;
    50         for(i=b+1;i<=m;i++)
    51         {
    52             cout<<"电梯正在上行到第"<<i<<"层楼"<<endl;
    53         }
    54         cout<<'a'<<""<<m<<"层已经到了!"<<endl;
    55     }
    56     else
    57     {
    58         if(a<b)
    59         {
    60             for(i=a+1;i<=b;i++)
    61             {
    62                 cout<<"电梯正在上行到第"<<i<<"层楼"<<endl;
    63             }
    64         }
    65         else
    66         {
    67             for(i=a-1;i>=b;i--)
    68             {
    69                 cout<<"电梯正在下行到第"<<i<<"层楼"<<endl;
    70             }
    71         }
    72         cout<<'a'<<"电梯已到第"<<b<<"层,请进入电梯。"<<endl;
    73         cout<<"请选择要去的楼层:";
    74         cin>>m;
    75         if(m>1&&m<8)
    76             {
    77                 cout<<"抱歉!电梯不在2-7楼停!"<<endl;
    78                 cout<<"请在8楼下,走楼梯步行!"<<endl;
    79                 for(i=b;i>=8;i--)
    80                 {
    81                     cout<<"电梯正在下行到第"<<i<<"层楼"<<endl;
    82                 }
    83                 cout<<'a'<<""<<8<<"层已经到了,请走楼梯,谢谢!"<<endl;
    84             }
    85         else
    86         {
    87             for(i=b;i>=m;i--)
    88             {
    89                 cout<<"电梯正在下行到第"<<i<<"层楼"<<endl;
    90             }
    91             cout<<'a'<<""<<m<<"层已经到了!"<<endl;
    92             }
    93     }
    94     return 0;
    95 }

    四、运行结果:

    五、心得体会:

          这次任务比要求的时间晚了很多,当时想了这道题,但是没什么思路,想的太多,想实现的东西也太多。这次只是实现的一些获得楼层、实现电梯走的过程、输出到达电梯这些功能。

          这次实践感触颇多,认真理清思路,就能解决问题。

  • 相关阅读:
    Python_命名空间和作用域_25
    Python_函数_复习_习题_24
    Python_每日习题_0001_数字组合
    Python_试题_23
    Python_初识函数和返回值_22
    linux-shell-引用-命令替换-命令退出状态-逻辑操作符
    linux-shell-变量参数
    Python-复习-文件操作-21
    Python-注册登陆-20
    linux-vim
  • 原文地址:https://www.cnblogs.com/huyabaoboke/p/4575866.html
Copyright © 2020-2023  润新知