Priority Comparing using Queues

Recently I created a program using queues implementing priorities.
I've managed to correct all errors except one, where I keep stumbling into.
1
2
error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
if(p > queVect[j]) //if new item larger, 

I've searched all clues online but there's no precise answer to solve the issue since each situation differs from mine.
Can anyone help? I'd really appreciate that.
I'll post the code below:

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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include <iostream>
#include <string>
#include <vector>
using namespace std;
////////////////////////////////////////////////////////////////
class Person
{
    public:
    int priority;
    string lastName;
    string firstName;
    int socialsecurity;
    int age;
//--------------------------------------------------------------
Person(int p, string last, string first, int a, int ss) : lastName(last), firstName(first), age(a), socialsecurity(ss), priority(p)
{ }
//--------------------------------------------------------------
void displayPerson()
{
    if (priority ==1)
    {
        cout<<"!!       Patient needs iImmediate Attention!      !! \n";
    }
    else if(priority ==2)
    {
         cout<<"!!       Patient needs Rapid Intervention!      !! \n";
    }
    else if(priority ==3)
    {
        cout<<"!!       Patient with Significant but non life-threatening injuries      !! \n";
    }
    else if(priority ==4)
    {
        cout<<"!!       Patient with Minor Interventions | Not Urgent      !! \n";
    }
    cout<<"{ \n";
    cout << "Social Security #: '" <<socialsecurity<<"' \n";
    cout << "First name: '" <<firstName<<"' \n";
    cout << "Last name: '" <<lastName<<"' \n";
    cout << "Age: '" <<age<<"' \n";
}
//--------------------------------------------------------------
}; //end class Person
////////////////////////////////////////////////////////////////
class PriorityP
{
    private:
    int maxSize; //size of stack vector
    vector<Person*> queVect; //stack vector
    int nItems;

    public:
//--------------------------------------------------------------
PriorityP(int s) : maxSize(s), nItems(0)  //constructor
{
    queVect.resize(maxSize); //size the vector
}
//--------------------------------------------------------------
void insert(int p, string last, string first, int a, int ss) //insert item
{
    int j;
    if (isFull())
    {
        cout<<"Woah! Queue is FULL! \n The data entered could not be inserted! \n";
        return;
    }
    else
    {
        if(nItems==0) //if no items,
        {
            queVect[nItems++] = new Person(p, last, first, a, ss); //insert at 0
        }
        else //if items,
        {

            if(nItems==0) //if no items,
            {
                queVect[nItems++] = new Person(p, last, first, a, ss); //insert at 0
            }
            else //if items,
            {
                for(j=nItems-1; j>=0; j--) //start at end,
                    {
                        if( p > queVect[j] ) //if new item larger,
                        {
                            queVect[j+1] = queVect[j]; //shift upward
                        }
                        else //if smaller,
                        break; //done shifting
                    } //end for
                queVect[j+1] = new Person(p, last, first, a, ss); //insert it
                nItems++;
            } //end else (nItems > 0)
        }
    } //end if (wrap-around)
} //end insert()
//-------------------------------------------------------------
double remove() //remove minimum item
{
    if (isEmpty())
    {
        cout<<"Database is EMPTY!"<<endl;
        return false;
    }
    else
    {
         queVect[--nItems];
    }
}
//-------------------------------------------------------------
double peekMin() //peek at minimum item
{
     queVect[nItems-1];
}
//-------------------------------------------------------------
double peekMax() //peek at minimum item
{
     queVect[nItems=0];
}
//-------------------------------------------------------------
bool isEmpty() //true if queue is empty
{
    return (nItems==0);
}
//-------------------------------------------------------------
bool isFull() //true if queue is full
{
    return (nItems == maxSize);
}
//-------------------------------------------------------------
void showmenu() //show menu to help user navigate through program
{
    cout<<"Please select from one of the options below to continue \n"
        <<"1. Insert patient by Priority \n"
        <<"2. Patient next in line for medical inspection \n"
        <<"3. Checking patient Priority \n"
        <<"4. Exit program \n"<<endl;
}
//-------------------------------------------------------------
void prioritydet() //showing priority to user when entering patient into program
{
     cout<<"List for priority to be determined \n"
         <<"Please select from the list below \n"
         <<"1. Immediate Attention! | Life-threatening \n"
         <<"2. Rapid Intervention | Urgent | Close Monitoring \n"
         <<"3. Significant but non life-threatening | Less Urgent \n"
         <<"4. Minor Intervention | Not Urgent \n";
}
//-------------------------------------------------------------
}; //end class PriorityQ
////////////////////////////////////////////////////////////////
int main()
{
    double p;
    string last;
    string first;
    int a;
    int s;
    int ss;
    int choice1, choice2;

    cout<<"Welcome to the Priority Queues Program \n Let's BEGIN ---> \n How much data do you want to enter overall in the database? \n";
    cout<<"Please state size of database below:\n ";
    cin>>s;
    PriorityP thePQ(s); //priority queue, size stated by user
    cout<<"Thank you \n Preparing the database for you, please wait... \n";
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    cout<<endl;
    thePQ.showmenu();
    cin>>choice1;
    while (choice1 != 4)
    {
        switch (choice1)
        {
        case 1: //INSERTING PATIENT INTO PROGRAM, PRIORITY IS STATED BY USER AND SORTED BY PROGRAM
                cout<<"Please insert the priority of the patient \n"<<endl;
                thePQ.prioritydet();
                cout<<endl;
                cin>>p;
                cout<<"Please insert the patient's first name \n";
                cin>>first;
                cout<<"Please insert the person's last name \n";
                cin>>last;
                cout<<"Please insert the patient's age \n";
                cin>>a;
                cout<<endl;
                thePQ.insert(p, last, first, a, ss);
                cout<<"Please wait while the information is being stored in the database...\n \n \n Thank you \n";
                thePQ.showmenu();
                cin>>choice1;

            break;
        case 2: //REMOVING PATIENT BY PRIORITY
                cout<<"Please wait while the next patient profile loads \n"
                    <<" \n"
                    <<" \n"
                    <<" \n"
                    <<"Thank you for waiting \n";
                cout<<"Next patient in line is... \n";
                cout<<"{ "<<thePQ.peekMax()<<"} \n";
                thePQ.remove();
                thePQ.showmenu();
                cin>>choice1;
            break;
        case 3://CHECKING PATIENT BY PRIOROTY
                cout<<"Press #1 to check the patient next in line with the least priority \n \n  OR  \n \n Press #2 to check the patient who is next in line and needs urgent attention \n";
                cin>>choice2;
                if (choice2 == 1)
                {
                    cout<<"The patient next in line with the least priority is: \n";
                    cout<<"{ "<<thePQ.peekMin()<<" }\n";
                    break;
                }
                else if (choice2 == 2)
                {
                    cout<<"The patient next in who needs urgent attention is: \n";
                    cout<<"{ "<<thePQ.peekMax()<<" }\n";
                    break;
                }
                thePQ.showmenu();
                cin>>choice1;
        break;
            default: cout<<"Am sorry \n that was not an option, please try that again \n";
        }
    }
cout<<"Goodbye \n";
cout << endl;
return 0;
} //end main() 
Last edited on
Firstly, look at the description of your problem:
I've managed to correct all errors except one, where I keep stumbling into. I've searched all clues online but there's no precise answer to solve the issue

You should be more specific than that!

One thing I notice with a quick perusal:
1
2
3
4
double peekMax() //peek at minimum item
{
     queVect[nItems=0];   // should be  return queVect[0];
}


!!EDIT!! Wait a second! Why is it returning a double? Should be a Person*.

And your remove() function is defined to return a double (should probably be void).
1
2
3
4
5
6
7
8
9
void remove() //remove minimum item
{
    if (isEmpty())
    {
        cout<<"Database is EMPTY!"<<endl;
        exit(1);  // include <cstdlib>
    }
    --nItems;
}

Last edited on
Topic archived. No new replies allowed.