| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 649 人关注过本帖
标题:谁能帮我解决一道关于电梯的题目,C++语言
只看楼主 加入收藏
g929904018
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-13
收藏
 问题点数:0 回复次数:1 
谁能帮我解决一道关于电梯的题目,C++语言
题目:
    一个一百层的大楼,一个电梯,很多乘客(我定义了20个);
    说明:60岁以上的乘客无需排队进入电梯,其余都需要排队,每个乘客进、出电梯都是1s,电梯在相邻两层楼运行时间10s,电梯容量13;
          乘客属性:编号ID,来等电梯时间Coming time,年龄Age,起始楼层Source floor,目的楼层Destination floor,离开时间Leaving time

    例如:Customer ID    Coming time    Age    Source floor    Destination floor    Leaving time
            21               123        65        2                9   
            2                16         45        80               5   
            4                382        14        1                99   
          程序的输入数据由input.txt文件读入,其中客户ID,Coming time,Age,Source floor,Destination floor都随机生成,但要注意Age不能超出[7,99]范围,
          Source floor和 Destination floor不能相同,Customer ID不能重复。(这点我已经做到,我完成了随机生成和将生成的数字存到txt文档里)
         
    要求:(1)面向对象程序设计方法,类模板的应用;类中有属性和方法
          (2)采用合适的求解问题算法,如排序、电梯调度算法等;
          (3)链表的应用、队列的应用等;
          (4)文件的读写操作;
          (5)程序测试计划、用例的设计和测试方法。
          (6)主函数只能定义变量和调用的函数方法,不能有任何其他的运算
   
    求:   每个乘客的离开时间Leaving time。

    以下是我自己写的生成随机数和将随机数存到txt文档里的程式码,希望能够有人完成这个题目。
#include <iostream>
#include <fstream>    //文件读取、写入头文件
#include <ctime>      //随机生成数的头文件
using namespace std;

class Customer
{
public:
    int ID;
    int Coming_time;
    int Age;
    int Source_floor;
    int Destination_floor;
    int Leaving_time;
};
Customer customer[20];  //定义10个人乘电梯

//定义一个计算时间的类,将停下时间、启动时间、和运行时间记下

void Stochastic()//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<随机生成数字
{
    for(int i=0;i<20;i++)//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<随机生成 ID
    {
        int num=0;
        customer[i].ID = rand() % 20 + 1;       //生成随机数在1~10以内,随机数是根据系统时间产生的
        for(int j=0 ; j<i ; j++)                //此处为控制生成不同随机数
        {
            if(customer[i].ID == customer[j].ID)//如果生成了相同随机数,则重新生成,知道生成不同随机数为止
            {
                num ++;
                break;
            }
            else
                continue;
        }
        if(num != 0)
            i--;
    }

    for(int j=0;j<20;j++)
    {  
        //随机生成 Coming time  在1~1000以内
        customer[j].Coming_time = rand() % 1000 + 1;
        
        //随机生成 Age          在7~99以内   
        customer[j].Age = rand() % 92 + 7;
        
        //随机生成 Source floor 在1~100以内
        customer[j].Source_floor  = rand() % 99 + 1;

    }

    for(int r=0;r<20;r++)
    {
        //随机生成 Destination floor 在1~100以内
        customer[r].Destination_floor  = rand() % 99 + 1;

        //如果出发楼层和目的楼层一样,则重新生成目的楼层
        if(customer[r].Destination_floor == customer[r].Source_floor)  
            r--;
    }
    cout<<"随机生成数值成功!"<<endl;
}

void Read_in()//将随机生成的ID、coming_time、age、source_floor、destination_floor存储进Input.txt文件里
{
    ofstream outfile("Input.txt");
    for(int i=0 ; i<20 ; i++)
    {
        outfile<<endl<<customer[i].ID<<"\t\t"<<customer[i].Coming_time<<"\t\t"<<customer[i].Age<<"\t\t"<<customer[i].Source_floor
            <<"\t\t"<<customer[i].Destination_floor;
    }
    outfile.close();
    cout<<"储存随机生成数成功!"<<endl;
}

int main()
{
    srand((unsigned)time(0));     //初始化生成随机函数时间种子
    Stochastic();      //随机生成 ID、coming_time、age、source_floor、destination_floor 这些数值
    Read_in();       //将随机生成的 ID、coming_time、age、source_floor、destination_floor 存储进Input.txt文件里
    return 0;
}
搜索更多相关主题的帖子: 电梯 时间 
2013-05-13 15:57
g929904018
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-5-13
收藏
得分:0 
PS:上面程序的方式是不对的,需要要求是面向对象,随机生成的函数也是要包含到类里面的。
2013-05-13 16:09
快速回复:谁能帮我解决一道关于电梯的题目,C++语言
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015699 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved