| | |
Help to hold data to place on stack/queue
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 24
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
I would sugguest the vector class, since it does all the finicky dma for you. Use it like this:
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.
C++ Syntax (Toggle Plain Text)
#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.
•
•
Join Date: Oct 2008
Posts: 24
Reputation:
Solved Threads: 0
Sorry, but I got to do it. Only because I do not understand these compile errors:
C++ Syntax (Toggle Plain Text)
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
![]() |
Other Threads in the C++ Forum
- Previous Thread: the == test
- Next Thread: I need serious help!
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data database delete desktop developer directshow dll encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream input int integer java lazy lib linux loop looping loops map math matrix memory multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





