### Singly Linked List, Employee Data

I need help with storing data in a singly-linked list where the nodes in the list correspond to each day in a 31-day month. An employee passes in between 1 and 5 slips per day every time they sell a product. These slips must include Product ID, staffID, and total dollar amount of products sold in a day. So I need a list of 31 different slips essentially.

The problem is, my output keeps doing the same slip every day for 31 days because I know it's working off the attributes of one employee. I believe my problem is in my Employee constructor, considering this would only randomize the values once upon object intialization. I need it to randomize ONE employee's attributes for each node in the singly linked list.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` ``````#ifndef EMPLOYEE_H #define EMPLOYEE_H #include using namespace std; class Slip; class Employee { private: int prodID, prodCost, total; int NUMSLIPS; Employee* next; public: Employee(); virtual ~Employee(); friend class Slip; }; #endif Employee::Employee() { srand(time(0)); NUMSLIPS = 1; prodID = 0; //for (int j = 1; j < 31; j++) { NUMSLIPS = rand() % 5 + 1; total = 0; for (int i = 1; i < NUMSLIPS; i++) { prodID = rand() % 5 + 1; if (prodID == 1) prodCost = 5; else if (prodID == 2) prodCost = 10; else if (prodID == 3) prodCost = 15; else if (prodID == 4) prodCost = 20; else prodCost = 50; total += prodCost; cout << "Slip " << i << ": ID" << prodID << " Cost: \$" << prodCost << endl; } cout << "Total for day: \$" << total << endl; //} next = 0; } Employee::~Employee() { } ``````

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394`` ``````#ifndef SLIP_H #define SLIP_H #include "Employee.h" #include using namespace std; class Slip { private: Employee* topNode; public: Slip(); Slip(const Slip &); virtual ~Slip(); void push(); void pop(); Employee* top(); bool isEmpty(); bool isFull(); Slip& operator=(const Slip &); class StackEmptyException { }; }; #endif Slip::Slip() { topNode = 0; } Slip::Slip(const Slip& st) { if (st.topNode == NULL) { topNode == NULL; } else { topNode = new Employee(); Employee* current = topNode; Employee* stTop = st.topNode; Employee* currentSt = stTop; while (currentSt->next != NULL) { current->next = new Employee(); currentSt = currentSt->next; current = current->next; } } } Slip::~Slip() { while (!isEmpty()) pop(); } void Slip::push() { try { Employee* newNode = new Employee(); newNode->next = topNode; topNode = newNode; } catch (bad_alloc &e) { cout << "memory allocation exception: " << e.what() << endl; exit(1); } } void Slip::pop() { if (isEmpty()) throw StackEmptyException(); Employee* discard = topNode; topNode = topNode->next; delete discard; } Employee* Slip::top() { if (isEmpty()) throw StackEmptyException(); return topNode; } bool Slip::isEmpty() { return (topNode == 0); } bool Slip::isFull() { return false; } Slip& Slip::operator=(const Slip& slip) { Slip temp(slip);``````

 ``12345678910111213141516171819202122232425`` ``````#include "Employee.h" #include "Slip.h" #include #include #include using namespace std; int main() { //Employee e1; Slip slip; for (int i = 1; i < 31; i++) slip.push(); for (int i = 1; i < 31; i++) { slip.top(); slip.pop(); } return 0; }``````
You design is wrong. Line 11 should be moved to the `Slip` class. The `Employee` needs an array of 5 slips and a count for the available slips.

The class `Slip` shouldn't know anything about `Employee`. So move most if not all functions to `Employee`.

The constructs should initialize the members not much more. So I would suggest that you move the generation of the random data to main.

So:
 ``1234567891011`` ``````class Slip { private: int prodID = 0, prodCost = 0, total = 0; // total must be calculated by Employee ... class Employee { private: Slip slip_array[5]; int NUMSLIPS = 0;``````
I have since figured out my problem. Sometimes, I have a hard time viewing classes and objects as actual datatypes. I was trying to integrate a singly-linked list into my SalesPerson class rather than using Node class and List class as templated classes that simply form the architecture, if you will, of a singly-linked list. I then passed objects of types SalesPerson into the templated list. Thank you for you help though!