Hi..
I suppose to have a programe to read a data from a file and enqueu it to the Queue.
The programme works like a Priority queue whether the ladies queue need to be inserted to queue first before the gentleman...
But i think i need to try first how to actually read the data from the file and put it into Queue before i need to implement the priority ...
Here is the function prototype
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
const int MAX = 20;
class Person
{
friend ostream& operator << (ostream&, Person&);
public:
Person(); // Do nothing
Person(char [],char);
Person(const Person&);
char getSex () const;
Person& operator*= (const Person&);
private:
char name [MAX];
char sex;
};
struct Node;
typedef Node* NodePtr;
struct Node
{
Person p;
NodePtr next;
};
class Queue
{
friend ostream& operator << (ostream&, Queue&);
public:
Queue(); // head&tail
void enqueue (const Person&); // insert person to Q
Person dequeue (); //delete person from Q
int getSize(); //get size of infile
bool isEmpty(); // if Q isEmpty
private:
NodePtr head,tail;
static int size;
};
int Queue::size = 0;
Here is what i try to do but it can't works
Person::Person (char name[],char sex)
{
int i;
while (i<MAX)
{
if(name[i] != '\0')
this->name[i]=name[i];
else
break;
i++;
}
this-> sex = sex;
}
void Queue::enqueue (const Person& name)
{
NodePtr temp = new Node;
temp -> p = name;
temp -> next = NULL;
if (tail == NULL)
head = temp;
else
tail -> next = temp;
tail = temp;
size++;
}
int main ()
{
char name [MAX];
char sex;
fstream infile;
Queue q;
q.dequeue ();
infile.open ("infile.txt", ios::in);
if (!infile.good())
{
cout <<" opened for reading failed" << endl;
cout << "End of task" << endl;
exit (1);
}
else
{
cout << " successfully opened for reading" << endl;
}
while (!infile.eof())
{
for (int i=0;i<MAX;i++)
{
infile << name[i];
q.enqueue (name[i]);
}
}
infile.close();
}
Appreciate any of your help
Thank you