Using C++ to: Handling Priorities with Linked Lists: Design a class called suppo
ID: 3756282 • Letter: U
Question
Using C++ to:
Handling Priorities with Linked Lists:
Design a class called supportTicket that handles information about reported IT support issues. A ticket includes an id number, the location of the equipment (e.g., building and room number), a short description of the issue, and a priority level. A valid priority level is a value from 1-5. Tickets are services based on their priority level, from highest to lowest. More than one ticket may have the same priority level. However, when entering an item into the list that has the same priority as another item, the newest item should come after any previously entered items with the same priority. When a ticket is serviced, it is removed from the list.
Implement a menu system that allows the program user to add a support ticket, service a ticket (remove it from list), and list active tickets in order of priority.
Explanation / Answer
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
class Location{
private:
std::string building;
std::string roomNumber;
public:
Location(std::string _building, std::string _roomNumber){
building = _building;
roomNumber = _roomNumber;
};
std::string getLocation(){
return building +"-"+ roomNumber;
};
};
class SupportTicket{
private:
int id;
std::string location;
std::string description;
int priorityLevel;
public:
SupportTicket(int _id, Location _location, std::string _description, int _priorityLevel){
id = _id;
location = _location.getLocation();
description = _description;
priorityLevel = _priorityLevel;
};
std::string getTicket(){
return id + ":" + location + ":" + description;
};
int getPriorityLevel(){
return priorityLevel;
};
};
class SupportTickets{
private:
std::vector<SupportTicket> tickets;
public:
SupportTickets(){};
void insertNewTicket(SupportTicket supportTicket){
int priorityLevel = supportTicket.getPriorityLevel();
int position = 0;
for(SupportTicket ticket: tickets){
if(ticket.getPriorityLevel() >= supportTicket.getPriorityLevel())
position++;
}
tickets.insert(tickets.begin()+position, supportTicket);
};
SupportTicket getLatestTicketByPriority(){
SupportTicket st = tickets.front();
tickets.erase(tickets.begin());
return st;
};
};
int main()
{
SupportTickets sts = SupportTickets();
Location l1 = Location("Phase2","32");
Location l2 = Location("Phase2","31");
Location l3 = Location("Phase2","30");
SupportTicket s1 = SupportTicket(1,l1,"d1",1);
SupportTicket s2 = SupportTicket(1,l2,"d2",1);
SupportTicket s3 = SupportTicket(1,l3,"d3",2);
SupportTicket s4 = SupportTicket(1,l2,"d4",3);
SupportTicket s5 = SupportTicket(1,l3,"d5",5);
sts.insertNewTicket(s1);
sts.insertNewTicket(s2);
sts.insertNewTicket(s3);
sts.insertNewTicket(s4);
sts.insertNewTicket(s5);
cout << sts.getLatestTicketByPriority().getTicket();
cout << sts.getLatestTicketByPriority().getTicket();
cout << sts.getLatestTicketByPriority().getTicket();
cout << sts.getLatestTicketByPriority().getTicket();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.