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

#pragma once #include \"Employee.h\" #include \"StudentEmployee.h\" #include \"S

ID: 3766207 • Letter: #

Question

#pragma once
#include "Employee.h"
#include "StudentEmployee.h"
#include "Staff.h"
#include "Faculty.h"
#include <iostream>
#include <string>

class Model
{
public:
   Model();
   ~Model();
   void readStudentData();
   void addEntry(StudentEmployee studentObject);
   void readStaffData();
   void readFacultyData();
   void writeStudentData();
   void writeStaffData();
   void writeFacultyData();
   void addEmployee();
   void deleteEmployee();
   void displayEmployees();


private:
   static const int MAX_SIZE = 10;
   StudentEmployee studentArray[MAX_SIZE];
   Staff staffArray[MAX_SIZE];
   Faculty facultyArray[MAX_SIZE];

};

void Model::readStudentData()
{
   string employeeName;
   int employeeID;
   string isWorking;
   int hoursWorked;
   string isTA;
   int payRate;

   ifstream file;
   file.open("Programming Assignment 4 StudentEmployee Data.txt");
   if (file.fail())
   {
       cout << "file not found!";
   }

   string line;
   string word = "";
   char delim = ',';
   int i;

   while (!file.eof())
   {
       if (!getline(file, line))
           break;

       istringstream ss(line);

       i = 0;
       while (ss) {
           word = "";
           if (!getline(ss, word, ','))
               break;
           //cout << word << " ";
           if (i == 0)
               employeeName = word;
           if (i == 1)
               istringstream(word) >> employeeID;
           if (i == 2)
               isWorking = word;
           if (i == 3)
               istringstream(word) >> hoursWorked;
           if (i == 4)
               isTA = word;
           if (i == 5)
               istringstream(word) >> payRate;
           i++;

       }
       //StudentEmployee studentEmployeeA(employeeID, employeeName, isWorking, hoursWorked, payRate);
       //cout << studentEmployeeA.getemployeeName() << endl;
       cout << "Details: name: " << employeeName << " IDnumber: " << employeeID << " isWorking: "
           << isWorking << " hoursWorked:" << hoursWorked << " isTA:" << isTA << " payRate:" << payRate << endl;
       //addEntry(studentEmployeeA);
   }
}

   void Model::addEntry(StudentEmployee studentObject)
   {
       int studentCounter = 0;
       studentArray[studentCounter] = studentObject;
       studentCounter++;

}

Im not sure when to create new objects because its giving me an error when i uncomment those lines

Explanation / Answer

what you written is correct..just un comment the lines... Two fixes needed.

In addEntry method you are initialized studentCounter to 0...so it overWrites previous object stored in zero index always.

Second one...add addEntry method in starting of all methods... some times it leads to visibility issues.

int studentCounter = 0;
void Model::addEntry(StudentEmployee studentObject)
{
//removed counter from gere..as it always initialised to 0
studentArray[studentCounter] = studentObject;
studentCounter++;
}

void Model::readStudentData()
{
string employeeName;
int employeeID;
string isWorking;
int hoursWorked;
string isTA;
int payRate;
ifstream file;
file.open("Programming Assignment 4 StudentEmployee Data.txt");
if (file.fail())
{
cout << "file not found!";
}
string line;
string word = "";
char delim = ',';
int i;
while (!file.eof())
{
if (!getline(file, line))
break;
istringstream ss(line);
i = 0;
while (ss) {
word = "";
if (!getline(ss, word, ','))
break;
//cout << word << " ";
if (i == 0)
employeeName = word;
if (i == 1)
istringstream(word) >> employeeID;
if (i == 2)
isWorking = word;
if (i == 3)
istringstream(word) >> hoursWorked;
if (i == 4)
isTA = word;
if (i == 5)
istringstream(word) >> payRate;
i++;
}
//uncomment these lines as these will create new instance
StudentEmployee studentEmployeeA(employeeID, employeeName, isWorking, hoursWorked, payRate);
cout << studentEmployeeA.getemployeeName() << endl;

cout << "Details: name: " << employeeName << " IDnumber: " << employeeID << " isWorking: "
<< isWorking << " hoursWorked:" << hoursWorked << " isTA:" << isTA << " payRate:" << payRate << endl;
addEntry(studentEmployeeA);
}
}