1

So I'm trying to make an array of rooms, each with 2 queues. I have a class containing info of the people that will be in the rooms, a class for the Queue algorithm, and a class for the rooms. What I first tried was making the 2 queues in the Room as private members, then using a default constructor of the room to create the room. After getting an error for everytime the queue functions were used I did some googling and found that I need to have the constructor as:

Rooms(Person pat):NormalList(pat){};

in order for the class object to be private members. The Rooms class looks like:

class Rooms
    {
    private:
    Queue<Person> NormalList;
    Queue<Person> EmergencyList;
    bool doctor;
    string docName;
    string specialty;


public:
    Rooms();
    Rooms(Person pat):NormalList(pat){};

    void addToNormal(Person);
    void addToEmergency(Person);

    bool checkDoctor();
    string getDocName() const;
    string getSpecialty();
    bool setDoctor(Person);

    void removeDoc();
    void removePat(Person);

    int getEmergLength() const;
    int getNormLength() const;

    bool isEmergEmpty() const;
    bool isNormEmpty() const;
};

The problem now is I cant figure out how to make my room object an array. I originally had it as

Rooms room[100];

but now it needs to be created as:

Rooms room(Default /*object of class Person*/);

and I cant figure out how to make it an array. Could you guys please give me a hand? I've been struggling with this for quite some time and only have a day left for it

MCV Example: Main:

#include "Rooms.h"
int main()
{
    Person Default;
    //Rooms rooms[100](Default);
    Rooms rooms[100];

    rooms[0].addToEmergency(Default);

    return 0;
}

Queue.h:

#include <iostream>
#include <string>
using namespace std;

#ifndef Queue_h
#define Queue_h


class FullQueue
{};

class EmptyQueue
{};

template <class ItemType>
struct NodeType;

template <class ItemType>
class Queue
{
private:
    NodeType <ItemType>* front;
    NodeType <ItemType>* rear;
    int length;

public:
    Queue();
    Queue(ItemType);
    void Enqueue(ItemType);
    bool IsFull() const;
};
#endif /* Queue_h */

Queue.cpp:

#include "Queue.h"


template <class ItemType>
Queue <ItemType>::Queue()
{

    front = NULL;
    rear = NULL;
    length = 0;

}

template <class ItemType>
Queue <ItemType>::Queue(ItemType pat)
{
    front = pat;
}

template <class ItemType>
void Queue<ItemType>::Enqueue(ItemType item)
{
    if(IsFull())
        throw FullQueue();

    length++;

    NodeType <ItemType>* tmpNode;

    tmpNode = new NodeType <ItemType>;
    tmpNode -> info = item;
    tmpNode -> next = NULL;
    if (rear == NULL)
    {
        front = tmpNode;
    }
    else
    {
        rear -> next = tmpNode;
    }
    rear = tmpNode;
}

Rooms.h:

#ifndef Rooms_h
#define Rooms_h

#include "Queue.h"
#include "Person.h"


class Rooms
{
private:
    Queue<Person> NormalList;
    Queue<Person> EmergencyList;
    bool doctor;
    string docName;
    string specialty;


public:
    Rooms();
    Rooms(Person pat):NormalList(pat){};

    void addToNormal(Person);
    void addToEmergency(Person);

    bool checkDoctor();
    string getDocName() const;
    string getSpecialty();
    bool setDoctor(Person);

    void removeDoc();
    void removePat(Person);

    int getEmergLength() const;
    int getNormLength() const;

    bool isEmergEmpty() const;
    bool isNormEmpty() const;
};
#endif /* Rooms_h */

Rooms.cpp:

#include "Rooms.h"
Rooms::Rooms()
{
    doctor = false;
    docName = " ";
    specialty = " ";
}
void Rooms::addToNormal(Person pat)
{
    if(!NormalList.IsFull())
        NormalList.Enqueue(pat);
}

Person.h:

#ifndef Person_h
#define Person_h
#include <iostream>
#include <string>
using namespace std;

class Person
{
private:
    bool doctor;
    int roomNum;

    string specialty;
    string name;

    bool patient;
    bool emergency;
    int age;

public:
    Person();
};
#endif /* Person_h */

Person.cpp:

#include "Person.h"

Person::Person()
{
    doctor = false;
    roomNum = 0;

    specialty = "";
    name = "";

    patient = false;
    emergency = false;
    age = 0;
}

Error:

Undefined symbols for architecture x86_64:
  "Queue<Person>::Enqueue(Person)", referenced from:
      Rooms::addToNormal(Person) in Rooms.o
  "Queue<Person>::Queue()", referenced from:
      Rooms::Rooms() in Rooms.o
  "Rooms::addToEmergency(Person)", referenced from:
      _main in main.o
  "Queue<Person>::IsFull() const", referenced from:
      Rooms::addToNormal(Person) in Rooms.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Stw59
  • 21
  • 4
  • Can you create a default constructor for `Queue`? If you can, you can create a default constructor of `Room` also. – R Sahu Nov 18 '15 at 03:00
  • @RSahu I have a default for Queue, and a default for Room, but when I used the default for room it gave me an error for every time a Queue function was used. I'll add the errors to main because I'm not familiar with formatting in these replies. – Stw59 Nov 18 '15 at 03:03
  • Then, `Rooms room[100];` should work. – R Sahu Nov 18 '15 at 03:05
  • Please post a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). It will be so much easier to answer than seeing bits and pieces of code. – R Sahu Nov 18 '15 at 03:08
  • @RSahu Alright, I added a code sample – Stw59 Nov 18 '15 at 03:21
  • You need to implement the member functions of `Queue` in a header file, not in a .cpp file. – R Sahu Nov 18 '15 at 03:26
  • @RSahu So I would just need to put Queue.cpp into Queue.h? Whats the reasoning behind that? I've never heard of that being needed. – Stw59 Nov 18 '15 at 03:31
  • The duplicate question has many answers with a lot of detail. – R Sahu Nov 18 '15 at 03:33

0 Answers0