View the step-by-step solution to:

This is the question: Design a system to keep track of employee data.

I have a complete code that I don't know how to finish please help. This is the question::


Design a system to keep track of employee data. The system should keep track of an employee's name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, hint, you need something extra. This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee's full name (example):


17 5.25 Daniel Katz

18 6.75 John F. Jones


Additionally we would like to be able to print payroll information from data in a different file. The data is the employee's id number and a number of hours that they worked (example):


17 40

18 20

18 20


As you see we can have the same number listed twice in which case that person should be paid the sum of the numbers (John Jones did 40 hours work, but it's listed as 20+20).


You should start by reading in the first file and storing the data as objects in a linked list. You will need to create the linked list class and the Employee data class. You may choose to use the Linked List class we created, or you may opt to make your own doubly linked list class. (Note: if you cannot get either working, you can use the STL list class but 20% will be deducted). The Linked list could be templated or not, it's up to you, however templating it would allow it to be used for other projects, so it might be a good idea.


Once you have read in the information from the first file, read in the second file. Ultimately we would like to print payroll information based on the hourly wage from the first file multiplied by the number of times an employee worked in the second file. How you implement this is entirely up to you.


The output must be in sorted (descending; so the person who gets paid most prints first) order in the form of:

*********Payroll Information********

Daniel latz, $270

John F. Jones, $210

*********End payroll**************


MY CODE:

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <fstream>//so we can access our files!
using namespace std;

template <class T>
class LList; //predefine so we can let friend work in LLNode

/*template <class T>
class Employee{
private:
    //file1
    T ID; //int id;
    T payWage; //double payWage;
    T name; //string name;
    //file2
    //T ID; //int id;
    T hoursWorked; //int hoursWorked;
public:
    ifstream;//check that it is actually opened
    ofstream;
};*/

template <class T>
class LLNode{
    T data;//employee
    LLNode<T>* next;//ptr to the next node
    LLNode<T>* prev;//ptr to the previous node
public:
    LLNode(const T& newdata = T(), LLNode<T>* newnext = nullptr, LLNode<T>* newprev = nullptr): data(newdata), next(newnext), prev(newprev){}//constructor
    friend class LList<T>;//friend class to access LList Node
};

template <class T>
class LList {
private:
    LLNode<T>* head; //the only item stored in the list class is a ptr to the first node on the list!
    LLNode<T>* tail;
    LLNode<T>* recursiveCopy(LLNode<T>* rhs);//copy?
public:
    LList();// : head(nullptr){}//default constructor empty list
    ~LList(); // { clear();}//destructor
    LList(const LList<T>& rhs);
    //LList(const LList& rhs) : head(nullptr) {*this = rhs;}//copy
    LList<T>& operator = (const LList<T>& rhs); //assignment operator***
   
    
    //void insertAtHead (T newdata); //update head ptr to the newly created node and new node's next ptr to pt to previous head-insert to list
    //T removeFromHead();//advance head to heads next
    //bool isEmpty() const { return head == nullptr;} //checks to see if head ptr is null
    void clear(); //eliminate nodes- constantly call remove from head until empty
    //void insertAtEnd (T newData);//same as pushback
    //void insertAtPoint(LLNode<T>* ptr, T newdata);//same as push front
    
    void push_back(const T&);//same as insert at end
    void push_front(const T& data){head->next = new LLNode<T>(data, head->next, head); head->next->next->prev = head->next;}
    //
    T pop_back();//
    T pop_front();//
    int size();// const; //how many nodes are on list?
};
//===============================
template <class T>//destructor clears nodes
LList<T>::~LList(){
    clear();
    delete head;
    delete tail;
}

//===============================
template <class T>//copy constructor
LList<T>::LList(const LList<T>& rhs) {//
    head = new LLNode<T>();
    tail = new LLNode<T>();
    head->next = tail;
    tail->prev = head;
    *this = rhs;//call to the assignment operator***
}
//===============================
template <class T>//assignment operator
LList<T>::LList() {//build two nodes, make dummy head and dummy tail
    head = new LLNode<T>();
    tail = new LLNode<T>();
    head->next = tail;
    tail->prev = head;
}
//===============================
template <class T>
void LList<T>::insertAtEnd(T newdata){
    if (isEmpty()){
        inserAtHead(newdata);
        return;
    }
    LLNode<T>* temp = new LLNode <T> (newdata);
    LLNode<T>* end = head;
    while (end->next != nullptr)
        end = end->next;
    end->next = temp;
}
//===============================
template <class T>
int LList<T>::size() const{
    int count = 0;
    LLNode<T>* temp = head;
    while (temp != nullptr){
        count++;
        temp = temp->next;
    }
    return count;
}
//===============================
void openInputFile(ifstream& inFile) {//create a file if not there
    string filename;
    cout << "What filename would you like to open: ";
    cin >> filename;
    inFile.open(filename);//attempt to open
    while (!inFile) {//check flag to see if successful
        cout << "Bad filename!" << endl;
        cout << "What filename would you like to open: ";
        cin >> filename;
        inFile.clear(); //release all flags!
        inFile.open(filename);
    }
}

int main() {
    ifstream inFile;
    openInputFile(inFile);
    int temp;
    int sum = 0;
    int count = 0;
    string name;
    while (inFile >> temp){
        sum+= temp;
        count++;
        inFile.ignore(1, ' ');//ignore the spaces
        getline(inFile, name);
        cout<<name<<endl;
    }
    return 0;
}

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question