Question

In: Computer Science

****NEED CODED IN C++, READ THE INSTRUCTIONS CAREFULLY AND PAY ATTENTION TO THE INPUT FILE, IT...

****NEED CODED IN C++, READ THE INSTRUCTIONS CAREFULLY AND PAY ATTENTION TO THE INPUT FILE, IT IS REQUIRED FOR USE IN THE PROBLEM****

You are to generate a list of customers to serve based on the customer’s priority, i.e. create a priority queue/list for a local company. The company has been receiving request and the request are recorded in a file, in the order the request was made. The company processes each user based on their priority, the highest priority which is the largest number. Priorities of equal value are first come first served as listed in the input file.  

Your input is a collection of customer IDs and priority, one per line.  

You are to read in the data and insert new data into a sorted linked list. The linked list is sorted by priority.

A customer may need an update on his order. He may submit a request a second time in order to change his priority level. If so, you will search the linked list, change the priority and adjust the new order in the sorted link list.

Input file: Priority Queue.txt

Output: List of ID’s with priorities in priority order

Example input:

1345 4

8243 1

Example output:

Customer Processing Order

Customer ID Priority

4124 5
1345 4

….    ….

Restrictions: Use an ordered link list for the data structure and a nice formatted print out.

INPUT FILE (NECESSARY TO IMPORT THE DATA INTO THE PROGRAM, NEEDS TO BE USED WITH IFSTREAM)

Priority Queue.txt

1432 2
8234 3
2124 5
8123 2
1314 2
1432 4
7141 3
7123 4
5523 1
6543 2
1731 5
3813 4
7213 5
3318 5
7213 3
7131 2
8882 3
9974 1
7221 3
7342 4
5523 3
3113 5
7002 4
9769 1
3145 5
7145 3
8834 2
9123 4
7878 1
7588 4
2025 1
6069 3
2025 3

The instructions can be translated as follows:

The objective is to make a priority queue/list.

The requests made to fill this queue include a 4-digit customer number and priority level ranging from 1 through 5.

This information is stored in a file.

If 2 customers have the same prio level, then the one that comes first in the list is treated as higher prio.

(first come, first serve basis)

I need to read in Priority Queue.txt to a sorted linked list. (sorted by prio)

I also need to insert new data into this linked list based on user input.

The input is based on a user being able to submit a 2nd request by entering their ID to change their prio level.

I can assume that when they do this, they bump their priority by 1. This is assumed because this program would serve no real function if every customer could just send another request and automatically be prio-5 or set that themself.

In this case, you want to search the Linked List, find the customer ID, change the prio, and adjust the new order in the sorted Linked List.

An ordered Linked List must be used for the data structure, and the output must be formatted neatly.

For input, this program will port in Priority Queue.txt for data.

For output, the program will display the Customer IDs in order of priority, keeping the FCFS rule in mind.

It will then prompt a user to be able to input their Customer ID for another request, bumping their prio by 1, re-sorting the LL, then outputting the new list.

Again, this is CODED IN C++ AND USES THE INPUT FILE FOR DATA.

Solutions

Expert Solution

#include <iostream>
#include <utility>
#include <fstream>

using namespace std;

class Node {
public:
        pair <int, int> data ;
        Node* next;
};

void display(Node* head)
{
        while (head != NULL)
        {
                cout << head->data.first << " " << head->data.second << "\n";
                head = head->next;
        }
}
void update_list(Node* head, int customerId, int priority)
{
    // This function updates lists with the given customerId and priority.
        Node* node = new Node();
        node->data = make_pair(customerId, priority);
        Node *prev = head;
        Node *curr = head->next;
        while (curr != NULL)
        {
                // Check whether given customerId is already existed in linked list
                if (curr->data.first == customerId)
                {
                        // if given customerId is already existed then remove entry from the linked list
                        prev->next = curr->next;
                        break;
                }
                prev = curr;
                curr = curr->next;
        }
        prev = head;
        curr = head->next;
        while (curr != NULL)
        {
            //This loop finds the point where new node should be inserted.
                if (curr->data.second < priority)
                {
                        break;
                }
                prev = curr;
                curr = curr->next;
        }
        prev->next = node;
        node->next = curr;

}
int main()
{
        ifstream infile;
        infile.open("priorityqueue.txt");
        Node *head = new Node(); //Dummy head node;
        head->data = make_pair(-1, 5);//Dummy data
        head->next = NULL;
        int customerId, priority;
        while (infile >> customerId >> priority)
        {
                update_list(head, customerId, priority);
        }
        display(head->next);
    //  Asks users for more updates
        cout << "Make another request by entering your customerId and priority\n";
        while (cin >> customerId >> priority)
        {
           // Asks user for more updates
                update_list(head, customerId, priority);
                display(head->next);
                cout << "Make another request by entering your customerId and priority\n";
        }
        return 0;
}

Related Solutions

c++ Please read the instructions carefully. You must put the proper items in the proper file...
c++ Please read the instructions carefully. You must put the proper items in the proper file (eitehr SSandwich.h or SSandwich.cpp. Do NOT include any main function in your submission. You are encouraged to write your own main function to test what you are submitting. You are submit two files via BlackBoard: A file named SSandwich.h, a header file defining the class SSandwich. No inline methods are permitted. Any enum classes should be defined here also. Your header file should have...
I need C++ program that Read an input file of text.txt one word at a time....
I need C++ program that Read an input file of text.txt one word at a time. The file should consist of about 500 words. The program should remove all punctuations,keep only words. Store the words in a built-in STL container, such as vector or map.Can someone help with any additional comments that I can understand the logic?thank you
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give me either partial answers, or incorrect skeleton. PLEASE YOU CAN'T CHANGE WHAT IS THERE, YOU CAN ONLY ADD. void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. alot of people give me either partial answers, or incorrect skeleton. PLEASE YOU CAN'T CHANGE WHAT IS THERE, YOU CAN ONLY ADD. void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? *IMPORTANT* PLEASE READ CAREFULLY....
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? *IMPORTANT* PLEASE READ CAREFULLY. WE HAVE TO DO WHAT THIS ASSIGNMENT DOES OR WE WILL MARKED OFF POINTS. IT DOES NOT HELP WHEN YOU CHANGE THE SKELETON TO YOU'RE PREFERENCE. THIS IS FOR A BASIC C++ LEVEL CLASS SO WE HAVE TO STICK TO BASIC C++ CODE. HOWEVER IT COULD BE WRONG IN TERMS OF WORKING CONDITIONS SO PLEASE HELP FIX THESE. *IMPORTANT* void readFile(Candidate candidates[]) – reads...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? ****IMPORTANT**** PLEASE READ CAREFULLY...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. HOW TO DO? ****IMPORTANT**** PLEASE READ CAREFULLY ****IMPORTANT**** ***GOALS*** HOW TO CHECK FOR COMMAS, TILL THE END OF FILE. IT WILL CHECK THE LINE FOR THE APPRORIATE FORMAT IN THE TEXT FILE. IF THERE IS MISSING A COMMA, IT WILL IGNORE, IF THERE IS A WHITE SPACE, IT WILL CORRECT AND READ LINE, IF IT IS MISSING 1 OF THE 3 INFORMATION, IT WILL IGNORE. Display candidates’ names using displayList() function...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. void readFile(Candidate candidates[]) –...
INPUT FILE INTO ARRAY. CHECKING FOR COMMAS AND SUCH. PLEASE READ CAREFULLY. void readFile(Candidate candidates[]) – reads the elections.txt file, fills the candidates[] array. Hint: use substr() and find() functions. Set Score to 0. void List(Candidate candidates[]) – prints the array of Candidate structs. One candidate per one line, include all fields. Use setw() to display nice looking list. void displayCandidate(Candidate candidates[]) – prints the complete information about the candidate . Candidate First(Candidate candidates[]) – returns single struct element: candidate...
Please read the instructions and  find attached for the first wiki . Instructions for students: Read carefully...
Please read the instructions and  find attached for the first wiki . Instructions for students: Read carefully the attached document and then post your comments bearing in mind the following questions: 1- What are the pros and cons of rent controls? 2- Why economists disagree on the usefulness of rent control? 3- Do you believe rent control can help the poor? Edit Wiki Content rent control Rent regulation can take various forms, including rent control (the placing of a cap on...
C Programming file.c takes in one input argument that denotes a file to be read. It...
C Programming file.c takes in one input argument that denotes a file to be read. It needs to convert the contents of that file into a character array (char *) and then into a an unsigned character array (unsigned char *). Please fix and or complete the program, and explain any of the changes too: ---- #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { FILE *f; f = fopen(argv[1], "r"); if( !f ) { exit(1); }...
c++. please read this task carefully. First, try given examples of input to your code, if...
c++. please read this task carefully. First, try given examples of input to your code, if it works, then send it here. Create structure Applicants with following fields: struct applicants{ int id; string name; string surname; int subject1,subject2,subject3,selectedSubject; string specialCase; int total; }; SpecialCase (if applicant has "Awardee of Olympiads", then this field is "true", otherwise "false"). Do not forget that all "Awardees of Olympiads" will gain grants automatically. If the total points are same your algorithm have to choose...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT