I am trying to implement a airline check-in line. I have three types of customers-generic, frequent flyers, and elite. Elite further breaks down down into gold, silver and bronze. The ranking follows that generic and frequent flyers are the lowest priority of customers. The check-in clerks can wait on these customers and added to a queue until an Elite customer is next in line. Since Elite customers have higher ranking, the generic or frequent flyer must wait until this Eilte customer is added to its stack. Then the generic or frequent flyer can be added to a queue. For example the line looks like:

1. generic
2. frequent
3. gold
4. bronze

1 can be added to the queue because 2 has the same rank. But 2 can't be processed until 3 and 4 are added to their appropriate stack.

I was hoping someone could provide me some help. I've been banging my head on trying to think on how to hold a customer for processing and process the next customers in line with higher ranking. Then adding the customer I had to hold. My implementation just processes one customer right after the other. Please any help would be awesome.

Recommended Answers

All 9 Replies

Ack! Nobody?

I would sugguest the vector class, since it does all the finicky dma for you. Use it like this:

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

class flyer
{
    char *  _szType;
    int      _iPriority;
    public:
    char *  _szName;
    //add flyer data here (flight time? etc)
    
    //im not gonna write the CTORs or DTORs, since they'll be empty
    inline void SetPriority(int iP)
    {
         _iPriority = iP;
         if (iP == 0)
               _szType = "Gold";
         //add more if statements for the rest of the types
    }
    operator<(flyer const & RHS)
    {
        return _iPriority < RHS._iPriority;
    }
};
int main()
{
    vector <flyer> Flyers; //fill this vector with the data that needs to be processed

    //here's how to add to a vector
    flyer temp;
    temp._szName = "Fred";
    temp.SetPriority(0);
    Flyers.push_back(temp);

//now once it's all filled up...
//this will leverage off of the operator<
//and will sort in ascending order based on
//priority, with 0 being most important to process
   sort(Flyers.begin(), Flyers.end());
//now they can be processed in order with a for loop
for (unsigned int i(0); i < Flyers.size(); ++i)
{
     //add processing crap here.  Access members of the vector like this:
    Flyers[i]._szName = "Foo";
}      
}

I'm not sure if you understand any of that, or if your teacher will let you hand it in. But it's probably the best way to tackle that problem. Also, I'm not sure what you mean by 'Process', but that shouldn't matter much.

Tried to implement this but got a bunch of compile errors with the code. I tried what I could do but nothing changed much.

Lol well i didn't compile it. I never usually do when I post on here, it's just a rough outline of that you should be doing. But, just for you, I will fix it.

I forgot to put bool before the word operator. It compiles if you fix that. But it won't do anything... It's up to you to replace the comments with the actual implementation of the program (ie a menu, actual useful members in the class, etc...) I won't write the whole thing for you :P

Thanks for the help. The other things I think I can do. I never expected the code handed to me wrapped in a pretty bow :icon_biggrin: .

Sorry, but I got to do it. Only because I do not understand these compile errors:

stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&) [with _Tp = flyer]':stl_algo.h:2484:   instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<flyer*, std::vector<flyer, std::allocator<flyer> > >, _Size = int]'

stl_algo.h:2555:   instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<flyer*, std::vector<flyer, std::allocator<flyer> > >]'

CheckInLine.cpp:70:   instantiated from here
stl_algo.h:90: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers

stl_algo.h:91: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
stl_algo.h:93: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
stl_algo.h:97: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
stl_algo.h:99: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers

flyer.h: At global scope:

flyer.h:22: warning: inline function `void flyer::SetPriority(int)' used but never defined


Execution terminated

Hmmm. What compiler are you using? I get no errors in VC++.

Perhaps put the inline keyword before operator, or make a proper seperate header file/c++ implementation. If that doesn't work, write a CTOR and DTOR that do nothing. I don't really understand why your compiler has so many errors while mine doesn't even have a warning.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.