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)