help with functions explaining

hi guys i would like to get some brief explanation for these functions. I don't have a good vision on this code. so kindly guys can please..please :) give some help

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
int main()
{
   SandwichQueue sQ;

    Order testCases[15];
    Order temp;
    string s = "sandwich";
    string c = "customer";

    for(int i = 0; i < 15; i++)
      {        
        testCases[i].sandwich = s;
        testCases[i].customerName = c;
        testCases[i].orderNbr = i;
        testCases[i].fries = i%2;
      }

    //a few tests...

    //add one
    sQ.push(testCases[0]);

    //remove one
    testCases[0] = sQ.pop();

    //Next test wrap around
    for(int i = 0; i < 3; i++)    // explain
      {
        sQ.push(testCases[i]);
        sQ.push(testCases[i]);
        temp = sQ.pop();

      }

    //test undrflow
    for(int i = 0; i < 11; i++)    // explain
      {
        if(!sQ.isEmpty())
          temp = sQ.pop();
        else
          cout << "Q empty - no more sandwiches" << endl;
      }

    //test overflow
    for(int i = 0; i < 15; i++)
      {
        sQ.push(testCases[i]);
      }
	
}

SandwichQueue::SandwichQueue()      // 
{
    qSize = initialSize;
    orderQ = new Order[initialSize];
    back = qSize - 1;
    front = 0;
}

bool SandwichQueue::isEmpty()  // what dose size doing!! 
{                              // what the different between SIZE and qSize
	if (size() == 0)
		return true;
	else
		return false;
}


int SandwichQueue::size()     // explain
{
	return (back - front + 1 + qSize) % qSize;

}


if i want to check if it's empty. i can check with size or what!!
Last edited on
You are trying to understand a incomplete piece of code here. Where is the definition of class SandwichQueue or Order. In their definition there should be what you are looking for. You are using member function for both but I can't tell what they do since no code is shown. Where is the rest?
sorry about that.. here is the whole code

it needs to complete those three functions.
Order pop();
void push(const Order& sandwich);
void expandQ();
I did some of code but i'm not sure abot them

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
#include <iostream>
#include <sstream>
using namespace std;
const int initialSize = 5;


struct Order {

	
	string sandwich;
	string customerName;
	int orderNbr;
	bool fries;
};


class SandwichQueue{

  public:

    SandwichQueue();
    
    //Interface for queue
    Order pop();
    void push(const Order& sandwich);
    void expandQ();
    bool isEmpty();
    int size();	

  private:

    //qSize is size of array, not amount stored in queue
    int qSize;
    Order* orderQ;
    int front;
    int back;
	
};

int main()
{

    SandwichQueue sQ;

    Order testCases[15];
    Order temp;

    string s = "sandwich";
    string c = "customer";

    for(int i = 0; i < 15; i++)
      {
        
        testCases[i].sandwich = s;
        testCases[i].customerName = c;
        testCases[i].orderNbr = i;
        testCases[i].fries = i%2;
      }



    //a few tests...

    //add one
    sQ.push(testCases[0]);

    //remove one
    testCases[0] = sQ.pop();


    //Next test wrap around
    for(int i = 0; i < 3; i++)    // explain
      {
        sQ.push(testCases[i]);
        sQ.push(testCases[i]);
        temp = sQ.pop();

      }

    //test undrflow
    for(int i = 0; i < 11; i++)
      {
        if(!sQ.isEmpty())
          temp = sQ.pop();
        else
          cout << "Q empty - no more sandwiches" << endl;
      }

    //test overflow
    for(int i = 0; i < 15; i++)
      {
        sQ.push(testCases[i]);
      }
	
}

SandwichQueue::SandwichQueue()
{
    qSize = initialSize;
    orderQ = new Order[initialSize];
    back = qSize - 1;
    front = 0;
}

bool SandwichQueue::isEmpty()
{
	if (size() == 0)
		return true;
	else
		return false;
}


int SandwichQueue::size()
{

	return (back - front + 1 + qSize) % qSize;

}

//function to pop
Order SandwichQueue::pop()
{
    if (!SQ.isempty())
      SQ.pop();
      
      else
      return temp;

}

//push an element, make sure it is not full, if it is call expand funciton
void SandwichQueue::push(const Order& sw)
{
    
	
}

//Double the queue size, copy the values, and reset back and front
void SandwichQueue::expandQ()
{
    for(testcases[i]> size)


}


Last edited on
I'm not sure if this a good way to pop an element and make it an empty.

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
//function to pop
Order SandwichQueue::pop()
{
    if (!SQ.isempty())
      SQ.pop();
      
      else
      return temp;

}

//push an element, make sure it is not full, if it is call expand funciton
void SandwichQueue::push(const Order& sw)
{
    
	
}

//Double the queue size, copy the values, and reset back and front
void SandwichQueue::expandQ()
{
    if(testcases[i]> size())
      

}
please i need some help
Topic archived. No new replies allowed.