0

I am working on an assignment where we create meetings for meeting rooms using pointer members and internal aggregation. I am stuck on the class room. This is where we need to use the Rule of 3, however, we have additional functions to write, and I am not sure what to do about this in the function header. The instructions are as follows:

Room

Design the class Room implementing internal aggregation with the following private attributes: string d_name Meeting** d_schedule which is a pointer to pointer, here a pointer to be directed at an array of meeting pointers. int d_nMeetings which should hold the current number of meetings.

The class should also define a set of functions: The constructor Room(string _name). The setter and getter void setName(string) and string getName(). bool add( Meeting* ) to add an additional meeting to this room. The function should always return true as you will not need to check for time conflicts in this assignment. There should be no fixed number of meetings but this function should grow the array at d_schedule by one with every call to add. void print() which simply loops over all meetings in d_schedule and prints them in arbitrary order.

As the class Room has a pointer member and is to implement internal aggregation, you must implement the rule of 3 (but you can skip the assignment operator, making it effectively a rule of 2).

I have started this for room.h

#include "meeting.h"

class Room{
private:
  std::string d_name;
  Meeting** d_schedule;
  int d_nMeetings;

public:
  Room(std::string _name);
  void setName(std::string);
  std::string getName();
  bool add(Meeting*);
  void print();
};

And room.cpp

#include "room.h"
#include <iostream>

Room::Room(std::string _name)
{
  d_name = name;
  d_nMeetings = 0;
}

void Room::setName(std::string)
{
  d_name = name;
}

std::string Room::getName()
{
  return d_name;
}

bool Room::add(Meeting*)
{
  d_schedule++;
  d_nMeetings++;
}

This is the code for the other 2 classes:

Meeting.h

#include <vector>
#include <string>
#include "item.h"

class Meeting: public Item{
protected:
  bool d_coffee;
  std::vector<std::string> d_participants;

public:
  Meeting(std::string, Time, int, bool, std::vector<std::string>, int);
  void print();
};

Meeting.cpp

#include "meeting.h"
#include <iostream>
#include <string>
#include <vector>
#include "item.h"

Meeting::Meeting(std::string _what, Time _deadline, int _duration, bool         _coffee, std::vector<std::string> _participants, int _priority = 0) :      Item(_what, _deadline, _duration, priority = 0)
{
  d_coffee = _coffee;
  d_participants = _participants;
}

void Meeting::print()
{
   Item::print();
}

Item.h

struct Time{
  int d_year;
  int d_month;
  int d_day;
  int d_hour;
  int d_minutes;
};

class Item{
protected:
  std::string d_what;
  Time d_deadline;
  int d_duration;
  int d_priority;

public:
  Item(std::string, Time, int, int);
  void print();
};

Item.cpp

#include "item.h"
#include <iostream>
#include <string>

Item::Item(std::string _what, Time _deadline, int _duration, int _priority = 0)
{
  d_what = _what;
  d_deadline = _deadline;
  d_duration = _duration;
  d_priority = _priority;
}

void Item::print()
{
  std::cout << " " << d_what << "Deadline:  " << d_deadline.d_year << "/" <<   d_deadline.d_month << "/" << d_deadline.d_day << " " <<
 d_deadline.d_hour << " : " << d_deadline.d_minutes << " Duration: " << d_duration << " Priority: " << d_priority << std::endl;
}

Thank you very much for your help.

sheap
  • 1
  • It's all well explained in depth with the answers on the marked duplicate. Do some research before actually asking. – πάντα ῥεῖ Oct 18 '15 at 20:05
  • I read this article already and don't understand in terms of this context. Thank you. – sheap Oct 18 '15 at 20:11
  • Well, maybe you should try to make your question clearer, what you actually don't understand, where you're stuck respectively. – πάντα ῥεῖ Oct 18 '15 at 20:23
  • "but you can skip the assignment operator, making it effectively a rule of 2" - huh? – M.M Oct 19 '15 at 01:43
  • It looks like you are being asked to write a correct destructor and copy-constructor for `Room`. BTW `Room` has a poor design that you would not use in real code, but it looks like you're stuck with it. – M.M Oct 19 '15 at 01:44
  • so how would this be done? They are asking for the Meeting** d_schedule which I do not understand. – sheap Oct 19 '15 at 16:28

0 Answers0