处理需要在c+中一起存储的3种int类型的正确方法+;? 所以我只是想学习一些C++,并且正在为公司的面试建立一个模型应用程序。

处理需要在c+中一起存储的3种int类型的正确方法+;? 所以我只是想学习一些C++,并且正在为公司的面试建立一个模型应用程序。,c++,arrays,types,elements,C++,Arrays,Types,Elements,我需要一种方法来处理事情更干净,然后只使用5个数组 我掌握的数据是: (int) Name of company member (e.g 1 John, 2 Jessica) (int) Day of the week (e.g 1 Monday, 2 Tuesday) (int) Timee slot for that day (e.g 1 9-10am, 2 10-11am) 现在我有一些类似于: bool johnMondaySchedule[7] = {true, true, true

我需要一种方法来处理事情更干净,然后只使用5个数组

我掌握的数据是:

(int) Name of company member (e.g 1 John, 2 Jessica)
(int) Day of the week (e.g 1 Monday, 2 Tuesday)
(int) Timee slot for that day (e.g 1 9-10am, 2 10-11am)
现在我有一些类似于:

bool johnMondaySchedule[7] = {true, true, true, true, true, true, true};
所以我有5个布尔数组,johnTuesday,johnWednesday,等等。每个真值代表时间段(0=9.10am,1=10-11am)

但我有5个客户,每个客户每周5天,每个客户有7个时段。
我觉得拥有25个布尔数组是非常低效的

我该怎么办? 我需要能够轻松地预订其中一个时间段(通过提供3个元素,对应于成员名称的int、日期和时间段)

我还需要一种简单的方法来迭代这些内容并将它们打印到屏幕上

我查看了散列图、元组、队列,但找不到任何适合我需要的东西


执行布尔数组是唯一的方法吗?

您可能想创建一些封装概念的类

#include <string>
#include <set>
#include <ctime>

struct Appointment
{
  Appointment(std::string client, std::time begin, std::time duration);

  const std::string &getClient()   const { return mClient; }
  std::time          getTime()     const { return mBegin; }
  std::time          getDuration() const { return mDuration; }

  bool operator<(const Appointment &right) 
  { 
    if (mBegin != right.mBegin)
      return mBegin < right.mBegin;

    if (mClient != right.mClient)
      return mClient < right.mClient;

    return mDuration < right.mDuration;
  }

private:
  std::string mClient;
  std::time_t mBegin;
  std::time_t mDuration;
};

struct Schedule
{
  typedef coll_type::const_iterator iterator;

  bool makeAppointment(Appointment a);

  iterator begin() const { return mAppts.begin(); }
  iterator end()   const { return mAppts.end(); }

private:
  typedef std::set<Appointment> coll_type;

  coll_type mAppts;  // sorted by begin time first, client name second, duration third
};
#包括
#包括
#包括
结构任命
{
约会(std::string客户端,std::time begin,std::time duration);
const std::string&getClient()const{return mClient;}
std::time getTime()常量{return mBegin;}
std::time getDuration()常量{return mDuration;}

bool运算符“我觉得拥有25个布尔数组非常低效”为什么你觉得它会低效?我查看了哈希映射、元组、队列,但找不到任何适合我需要的东西“为什么它们不适合你的需要?映射听起来像你需要的。这很糟糕,但不是因为“低效”。这是不好的,因为它用变量名编码数据-这通常表明设计不好。如果添加了新用户,会发生什么?会为他/她重新编码程序吗?布尔表示什么?可用性?为什么不为每个人提供事件向量,其中每个事件都有开始和结束日期时间?当我启动co时丁:我了解到,行数越少,效率就越高,因此,如果有其他选择,我认为25个布尔数组的效率就越低。@rawrsquid,谁教你的?????