Guest User

Untitled

a guest
Sep 29th, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. using namespace std;
  4. const int initialSize = 5;
  5.  
  6.  
  7. struct Order {
  8.  
  9.  
  10.         string sandwich;
  11.         string customerName;
  12.         int orderNbr;
  13.         bool fries;
  14. };
  15.  
  16.  
  17. class SandwichQueue{
  18.  
  19. public:
  20.  
  21.         SandwichQueue();
  22.  
  23.         //Interface for queue
  24.         Order pop();
  25.         void push(const Order& sandwich);
  26.         void expandQ();
  27.         bool isEmpty();
  28.         int size();
  29.  
  30. private:
  31.  
  32.         //qSize is size of array, not amount stored in queue
  33.         int qSize;
  34.         Order* orderQ;
  35.         int front;
  36.         int back;
  37.  
  38. };
  39.  
  40. int main()
  41. {
  42.  
  43.         SandwichQueue sQ;
  44.  
  45.         Order testCases[15];
  46.         Order temp;
  47.  
  48.         string s = "sandwich";
  49.         string c = "customer";
  50.  
  51.         for(int i = 0; i < 15; i++)
  52.         {
  53.  
  54.                 testCases[i].sandwich = s;
  55.                 testCases[i].customerName = c;
  56.                 testCases[i].orderNbr = i;
  57.                 testCases[i].fries = i%2;
  58.         }
  59.  
  60.  
  61.  
  62.         //a few tests...
  63.  
  64.         //add one
  65.         sQ.push(testCases[0]);
  66.  
  67.         //remove one
  68.         testCases[0] = sQ.pop();
  69.  
  70.  
  71.         //Next test wrap around
  72.         for(int i = 0; i < 3; i++)
  73.         {
  74.                 sQ.push(testCases[i]);
  75.                 sQ.push(testCases[i]);
  76.                 temp = sQ.pop();
  77.  
  78.         }
  79.  
  80.         //test undrflow
  81.         for(int i = 0; i < 11; i++)
  82.         {
  83.                 if(!sQ.isEmpty())
  84.                         temp = sQ.pop();
  85.                 else
  86.                         cout << "Q empty - no more sandwiches" << endl;
  87.         }
  88.  
  89.         //test overflow
  90.         for(int i = 0; i < 15; i++)
  91.         {
  92.                 sQ.push(testCases[i]);
  93.         }
  94.  
  95. }
  96.  
  97. SandwichQueue::SandwichQueue()
  98. {
  99.         qSize = initialSize;
  100.         orderQ = new Order[initialSize];
  101.         back = qSize - 1;
  102.         front = 0;
  103. }
  104.  
  105. bool SandwichQueue::isEmpty()
  106. {
  107.         if (size() == 0)
  108.                 return true;
  109.         else
  110.                 return false;
  111. }
  112.  
  113.  
  114. int SandwichQueue::size()
  115. {
  116.  
  117.         return (back - front + 1 + qSize) % qSize;
  118.  
  119. }
  120.  
  121. //function to pop
  122. Order SandwichQueue::pop()
  123. {
  124.  
  125.    
  126.  
  127.  
  128.  
  129. }
  130.  
  131. //push an element, make sure it is not full, if it is call expand funciton
  132. void SandwichQueue::push(const Order& sw)
  133. {
  134.  
  135.  
  136.  
  137.  
  138. }
  139.  
  140. //Double the queue size, copy the values, and reset back and front
  141. void SandwichQueue::expandQ()
  142. {
  143.  
  144.  
  145.  
  146. }
  147.  
  148.  
  149.  
  150.  
Advertisement
Add Comment
Please, Sign In to add comment