-
Notifications
You must be signed in to change notification settings - Fork 0
/
ccqueue.h
89 lines (77 loc) · 2.78 KB
/
ccqueue.h
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
// Description: Definition of a customer complaint queue class
#include <sstream>
#include <string>
#include <algorithm>
#include "dlinkedlist.h"
#include "ticket.h"
using namespace std;
class CCQueue
{
private:
DLinkedList<Ticket> tickets; // collection of ticket objects
unsigned int maxticketid; // largest-valued ticketid.
public:
/**
*default constructor
*maxticketid begins at 0
*note that tickets does not need to be re-declared
*/
CCQueue();
// MUTATORS
/**
*enqueues a new ticket at the back of the ticket queue and returns true
*ticketid is assigned automatically as 1+maxticketid if enqueueing is
*possible
*does not enqueue and returns false if either parameter is empty string
*POST: new ticket with supplied parameters is added to back of tickets,
* maxticketid is incremented
*PARAM: customer and complaint fields to pass to Ticket constructor
*/
bool Add(string customer, string complaint);
/**
*removes and returns an item from the front of the ticket queue
*throws a logic_error if the ticket queue is empty
*POST: first item of the ticket queue is removed
*/
Ticket Service();
/**
*moves an item towards the front of the queue by 1 position and returns
*true
*returns false if supplied index is 0 (first item) or outside the list
*boundaries
*POST:DLinkedList items at position and position-1 swap spots in the list
*PARAM: initial index of item to move up
*/
bool MoveUp(int index);
/**
*moves an item towards the back of the queue by 1 position and returns
*true
*returns false if supplied index is the last item or outside the list
*boundaries
*POST:DLinkedList items at position and position+1 swap spots in the list
*PARAM: initial index of item to move down*/
bool MoveDown(int index);
// ACCESSORS
// returns the number of tickets
int Size() const;
/**
*returns a formatted string with the ticket queue contents
*You may use this function to check the contents of your queue
*You do not need to copy this into your .cpp file
*/
string PrintStatus() const
{
string complainttext;
ostringstream output;
output << "Ticket queue contains " << tickets.Size() << " open tickets.\n";
output << "Position\tTicket ID\tCustomer\tShort description\n";
output << "-----------------------------------------------------------------------\n";
for (int i = 0; i < tickets.Size(); i++)
{
complainttext = tickets.ElementAt(i).GetComplaint();
output << i+1 << "\t\t" << tickets.ElementAt(i).GetID() << "\t\t"
<< tickets.ElementAt(i).GetCustomer() << "\t" << complainttext.substr(0, std::min((int)20, (int)complainttext.length())) << "...\n";
}
return output.str();
}
};