Help to hold data to place on stack/queue

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 24
Reputation: DLightman is an unknown quantity at this point 
Solved Threads: 0
DLightman DLightman is offline Offline
Newbie Poster

Help to hold data to place on stack/queue

 
0
  #1
Oct 31st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 24
Reputation: DLightman is an unknown quantity at this point 
Solved Threads: 0
DLightman DLightman is offline Offline
Newbie Poster

Re: Help to hold data to place on stack/queue

 
0
  #2
Nov 2nd, 2008
Ack! Nobody?
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Help to hold data to place on stack/queue

 
0
  #3
Nov 2nd, 2008
I would sugguest the vector class, since it does all the finicky dma for you. Use it like this:

  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. class flyer
  7. {
  8. char * _szType;
  9. int _iPriority;
  10. public:
  11. char * _szName;
  12. //add flyer data here (flight time? etc)
  13.  
  14. //im not gonna write the CTORs or DTORs, since they'll be empty
  15. inline void SetPriority(int iP)
  16. {
  17. _iPriority = iP;
  18. if (iP == 0)
  19. _szType = "Gold";
  20. //add more if statements for the rest of the types
  21. }
  22. operator<(flyer const & RHS)
  23. {
  24. return _iPriority < RHS._iPriority;
  25. }
  26. };
  27. int main()
  28. {
  29. vector <flyer> Flyers; //fill this vector with the data that needs to be processed
  30.  
  31. //here's how to add to a vector
  32. flyer temp;
  33. temp._szName = "Fred";
  34. temp.SetPriority(0);
  35. Flyers.push_back(temp);
  36.  
  37. //now once it's all filled up...
  38. //this will leverage off of the operator<
  39. //and will sort in ascending order based on
  40. //priority, with 0 being most important to process
  41. sort(Flyers.begin(), Flyers.end());
  42. //now they can be processed in order with a for loop
  43. for (unsigned int i(0); i < Flyers.size(); ++i)
  44. {
  45. //add processing crap here. Access members of the vector like this:
  46. Flyers[i]._szName = "Foo";
  47. }
  48. }

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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 24
Reputation: DLightman is an unknown quantity at this point 
Solved Threads: 0
DLightman DLightman is offline Offline
Newbie Poster

Re: Help to hold data to place on stack/queue

 
0
  #4
Nov 2nd, 2008
Tried to implement this but got a bunch of compile errors with the code. I tried what I could do but nothing changed much.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Help to hold data to place on stack/queue

 
0
  #5
Nov 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Help to hold data to place on stack/queue

 
0
  #6
Nov 2nd, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 24
Reputation: DLightman is an unknown quantity at this point 
Solved Threads: 0
DLightman DLightman is offline Offline
Newbie Poster

Re: Help to hold data to place on stack/queue

 
0
  #7
Nov 2nd, 2008
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 .
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 24
Reputation: DLightman is an unknown quantity at this point 
Solved Threads: 0
DLightman DLightman is offline Offline
Newbie Poster

Re: Help to hold data to place on stack/queue

 
0
  #8
Nov 2nd, 2008
Sorry, but I got to do it. Only because I do not understand these compile errors:
  1. 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]'
  2.  
  3. stl_algo.h:2555: instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<flyer*, std::vector<flyer, std::allocator<flyer> > >]'
  4.  
  5. CheckInLine.cpp:70: instantiated from here
  6. stl_algo.h:90: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
  7.  
  8. stl_algo.h:91: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
  9. stl_algo.h:93: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
  10. stl_algo.h:97: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
  11. stl_algo.h:99: error: passing `const flyer' as `this' argument of `bool flyer::operator<(const flyer&)' discards qualifiers
  12.  
  13. flyer.h: At global scope:
  14.  
  15. flyer.h:22: warning: inline function `void flyer::SetPriority(int)' used but never defined
  16.  
  17.  
  18. Execution terminated
  19.  
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Help to hold data to place on stack/queue

 
0
  #9
Nov 2nd, 2008
Hmmm. What compiler are you using? I get no errors in VC++.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: Help to hold data to place on stack/queue

 
0
  #10
Nov 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC