Insertion Queue

The program is required to read from queue.txt output to the screen giving female as priority.

The program works like a Priority queue where the female will be inserted to queue first before the gentleman...

I can't read my queue.txt & not sure what's wrong. Pls advise me.

[queue.txt]
F Mary1
M Wilson1
F Mary2
F Mary3
M Wilson2
F Mary4

How can I perform insertion queue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

const int MAX = 30;

class People
{
friend ostream& operator << (ostream&, People&);

public:
People(); // Perform nothing
People(char [],char);
People(const Person&);

char getSex () const;
People& operator*= (const People&);

private:
char name [MAX];
char sex;
};

struct Node;
typedef Node* NodePtr;

struct Node
{
People p;
NodePtr next;
};

class Queue
{
friend ostream& operator << (ostream&, Queue&);

public:
Queue(); // head&tail

void enqueue (const People&); // insert person to Q
People 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;



//Classes Functions

People::People (char name[],char sex)
{
int i= 0;
while (i<MAX)
{
if(name[i] != '\0')
strcpy(name[i],name[i]);
else
i++;
}
this-> sex = sex;
}

People::People (const People& p)
{
int i= 0;
while (i<MAX)
{
if(name[i] != '\0')
this->name[i]=p.name[i];
else
break;
i++;
}
this-> sex = p.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++;
}


//Main function

int main ()
{
	char name [MAX];
	char sex;
	fstream infile;
	Queue q;
	
	q.dequeue ();
	
	infile.open ("queue.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();	
}
Topic archived. No new replies allowed.