Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: Write a C++ program that will allow a research lab manager to monitor t

ID: 3753830 • Letter: P

Question

Problem: Write a C++ program that will allow a research lab manager to monitor the access to a research lab. Each member of the lab has access provided by their personal ID Card. Your program will provide information about the timing of the arrivals and departures of the lab staff. Your program will be provided with a dataset where each row records an event, which is represented by the following information:

1) ID number - a positive integer number

2) Person's name - a string

3) Time of the event - a string in "01:23AM" format (“dd:dd:AM” or “dd:dd:PM”)

Each event records the use of an ID card to either enter or exit the lab. A given data set corresponds to one day and is already sorted by ID number. You should assume that the lab is empty at the beginning of the day and events are consistent - a given person cannot enter or exit without the event being recorded, a given person cannot enter the lab twice without exiting once in between, etc.

The program should first read the events from a text file named “dataset.txt”. It will contain up to 100 events. See the sample file on the class website.

Then, it should offer the user a menu with the following options:

1. Display the events sorted by ID number.

2. Display the events sorted by the time of event.

3. Print the person's name given his/her ID number.

4. Find out whether some person is still in the lab given his/her ID number.

5. Quit

The program should perform the selected operation and then re-display the menu. Do not change the menu numbers associated with the operations. Display an error message if the user enters an inappropriate number.

For options 1 and 2, display the information for each event on a single, separate line. The values should line up in columns (use setw). Headers for the table are optional.

For the Lookup operations, label the output values appropriately. For options 3 and 4, If the person is not found, display an appropriate message.

Additional Requirements:

• This program must be done in a Linux or Unix environment, using a command line compiler like g++. Do not use codeblocks, eclipse, or Xcode to compile.

• Your program must compile and run, otherwise you will receive a score of 0.

• The program must be modular (use top-down design), with significant work done by functions. Each function should perform a single, well-defined task.

• Use a partially filled array of structures to store the events: Use a counter variable to count the number of events that are read in from the file, and use this value as the size of the array for the search and sort functions.

• Your program should work for an input file with any number of events up to 100.

• You MUST use binary search for option 3, Lookup name by ID.

• You may use (and modify) the code from the book. See the Resources tool in TRACS. Please look at this code before you start implementing your program.

• I will put a sample input file on the class website (dataset.txt) and the console output from running my solution on that file (output2.txt).

HARDCODE INPUT DATA:

dataset100.txt

dataset.txt

THIS IS THE OUTPUT AND HOW IT SHOULD LOOK:

Explanation / Answer

#include <new>

#include "LinkedList.h"

LinkedList::LinkedList(){

}

LinkedList::~LinkedList(){

    Node *x = first;

    while(x != NULL) {

        Node *y = x;

        x = x ->next;

        delete y;

    }

}

LinkedList::LinkedList(const LinkedList &origList){

    int count = 0;

    Node *x = origList.first;

    while(x != NULL) {

        insert(x->data, count++);

        x = x ->next;

    }

}

const LinkedList & LinkedList::operator=(const LinkedList & rightHandSide){

    resetList();

    int count = 0;

    Node *x = rightHandSide.first;

    while(x != NULL) {

        insert(x->data, count++);

        x = x ->next;

    }

    return *this;

}

bool LinkedList::isEmpty() const{

    return mySize == 0;

}

int LinkedList::getListSize() const{

    return mySize;

}

void LinkedList::display(std::ostream & out) const{

    Node *x = first;

    while(x != NULL) {

        out << x->data << " ";

        x = x ->next;

    }

    out << " ";

}

LinkedList operator+(const LinkedList & x, const LinkedList & y){

    LinkedList c;

    int xSize = x.getListSize();

    int ySize = y.getListSize();

    LinkedList::ListElement *data1 = new LinkedList::ListElement[xSize];

    LinkedList::ListElement *data2 = new LinkedList::ListElement[ySize];

    x.getListElement(0, xSize-1, data1);

    y.getListElement(0, ySize-1, data2);

    int i=0, j=0, count = 0;

    while(i < xSize || j < ySize) {

        if(i < xSize) {

            c.insert(data1[i], count++);

            i++;

        }

        if(j < ySize) {

            c.insert(data2[j], count++);

            j++;

        }

    }

    return c;

}

int operator==(const LinkedList & x, const LinkedList & y){

    int xSize = x.getListSize();

    int ySize = y.getListSize();

    if(xSize != ySize) {

        return 0;

    }

    LinkedList::ListElement *data1 = new LinkedList::ListElement[xSize];

    LinkedList::ListElement *data2 = new LinkedList::ListElement[ySize];

    x.getListElement(0, xSize-1, data1);

    y.getListElement(0, ySize-1, data2);

    for(int i=0; i<xSize; i++) {

        LinkedList::ListElement d = data1[i];

        bool found = false;

        for(int j=0; j<ySize; j++) {

            if(d == data2[j]) {

                found = true;

                break;

            }

        }

        if(!found) {

            return 0;

        }

    }

    for(int i=0; i<ySize; i++) {

        LinkedList::ListElement d = data2[i];

        bool found = false;

        for(int j=0; j<xSize; j++) {

            if(d == data1[j]) {

                found = true;

                break;

            }

        }

        if(!found) {

            return 0;

        }

    }

    return 1;

}

void LinkedList::resetList(){

    Node *x = first;

    while(x != NULL) {

        Node *y = x->next;

        delete x;

        x = y;

    }

    first = NULL;

    mySize = 0;

}

LinkedList::ErrorCode LinkedList::insert(ListElement item, int pos){

    int size = getListSize();

    if(pos < 0 || pos > size) {

        return ILLEGAL_LIST_POSITION;

    }

    Node *x = new Node;

    x->data = item;

    x->next = NULL;

    if(pos == 0) {

        x->next = first;

        first = x;

    } else {

        Node *y = first;

        while(pos != 1) {

            y = y ->next;

            pos--;

        }      

        x->next = y->next;

        y->next = x;

    }

    mySize++;

    return NO_ERROR;

}

LinkedList::ErrorCode LinkedList::erase(int pos){

    int size = getListSize();

    if(pos < 0 || pos >= size) {

        return ILLEGAL_LIST_POSITION;

    }

    if(pos == 0) {

        Node *y = first;

        first = first->next;

        delete y;

    } else {

        Node *y = first;

        while(pos != 1) {

            y = y ->next;

            pos--;

        }

        Node *x = y->next;

        y->next = y->next->next;

        delete x;

    }

    mySize--;

    return NO_ERROR;

}

LinkedList::ErrorCode LinkedList::move(int n, int m){

    int size = getListSize();

    if(n < 0 || n >= size) {

        return ILLEGAL_LIST_POSITION;

    }

    if(m < 0 || m >= size) {

        return ILLEGAL_LIST_POSITION;

    }

    if(m != n) {

        Node *a = first;

        int count = 0;

        while(a != NULL) {

            if(n == count) {

                break;

            }

            a = a ->next;

            count++;

        }

        ListElement temp = a->data;

        erase(n);

        insert(temp, m);

    }

    return NO_ERROR;

}

void LinkedList::reverse(){

    Node *current = first;

        Node prev = NULL, next = NULL;

        while (current != NULL) {

            next = current->next;

            // Reverse current node's pointer

            current->next = prev;

            prev = current;

            current = next;

        }

        first = prev;

}

LinkedList::ErrorCode LinkedList::getListElement(int posStart, int posEnd, ListElement rv[]) const {

    int size = getListSize();

    if(posStart < 0 || posStart >= size) {

        return ILLEGAL_LIST_POSITION;

    }

    if(posEnd < 0 || posEnd >= size) {

        return ILLEGAL_LIST_POSITION;

    }

    if(posEnd < posStart) {

        return ILLEGAL_LIST_POSITION;

    }

    int index = 0;

    Node x, y;

    Node *a = first;

    int count = 0;

    while(a != NULL) {

        if(posStart == count) {

            x = a;

        }

        if(posEnd == count) {

            y = a;

        }

        a = a ->next;

        count++;

    }

    a = x;

    while(a != y->next) {

        rv[index++] = a->data;

        a = a->next;

    }

    return NO_ERROR;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote