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

Hi guys, working on a program to add, delete, and display \"WORKING\" employees

ID: 3766528 • Letter: H

Question

Hi guys, working on a program to add, delete, and display "WORKING" employees that is stored in array.

working means isWorking variable = true. I declared it as a string, if i need to change to bool let me know.

Display function displays "Univeristy Employee 2 week pay period" then each line should contain the name, the classification (SW, ST, FAC), and the amount paid in dollars with 2 decimal points.

but when i run it, its not even going into the if statement when i try to check if isWorking is == "TRUE"

#pragma once
#include <fstream>
#include "Model.h"
#include <iostream>
#include <sstream>
#include "StudentEmployee.h"
#include "Employee.h"
#include "Staff.h"

using namespace std;


Model::Model()
{
}


Model::~Model()
{
}

int studentCounter = 0;
int staffCounter = 0;
int facultyCounter = 0;
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;
           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, isTA, hoursWorked, payRate);
       addEntry(studentEmployeeA);
   }
}

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

}


   void Model::readStaffData()
   {
       string employeeName;
       int employeeID;
       string isWorking;
       double weeklySalary;
       string division;

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

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

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

           istringstream ss(line);

           i = 0;
           while (ss) {
               word = "";
               if (!getline(ss, word, ','))
                   break;
               if (i == 0)
                   employeeName = word;
               if (i == 1)
                   istringstream(word) >> employeeID;
               if (i == 2)
                   isWorking = word;
               if (i == 3)
                   istringstream(word) >> weeklySalary;
               if (i == 4)
                   division = word;
               i++;

           }
           Staff staffObjectA(employeeID, employeeName, isWorking, weeklySalary, division);
           addStaff(staffObjectA);
       }
   }

   void Model::addStaff(Staff staffObject)
   {
       staffArray[staffCounter] = staffObject;
       staffCounter++;
   }

void Model::readFacultyData()
{
   string employeeName;
   int employeeID;
   string isWorking;
   double annualSalary;
   int weeksPerYear;
   string division;

   ifstream file;
   file.open("Programming Assignment 4 Faculty 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;
           if (i == 0)
               employeeName = word;
           if (i == 1)
               istringstream(word) >> employeeID;
           if (i == 2)
               isWorking = word;
           if (i == 3)
               istringstream(word) >> annualSalary;
           if (i == 4)
               istringstream(word) >> weeksPerYear;
           if (i == 5)
               division = word;
           i++;

       }
       Faculty facultyObjectA(employeeID, employeeName, isWorking, annualSalary, weeksPerYear, division);
      
       addFaculty(facultyObjectA);
   }
}


void Model::addFaculty(Faculty facultyObject)
{
   facultyArray[facultyCounter] = facultyObject;
   facultyCounter++;
}

void Model::writeStudentData()
{
   /*ofstream fout("Programming Assignment 4 StudentEmployee Data.txt");
                          
   if (fout.is_open())
   {
      
       cout << "File Opened successfully!!!. Writing data from array to file" << endl;

       for (int i = 0; i < studentCounter + 1; i++)
       {
           fout << studentArray[i];
       }
       cout << "Array data successfully saved into the file test.txt" << endl;
   }
   else
   {
       cout << "File could not be opened." << endl;
   }*/
}

void Model::writeStaffData()
{

}

void Model::writeFacultyData()
{

}

void Model::addEmployee()
{
   string name;
   int id;
   string working;
   string TA;
   int workedHours;
   int wage;
   double weekSalary;
   string division;
   double yearlySalary = 0;
   int weeksPerYear = 0;

   string choice;
   cout << "enter sw to add student employee, st to add staff, fac to add faculty" << endl;

   cin >> choice;
   if (choice == "sw")
   {
       cout << "please enter name" << endl;
       cin >> name;
       cout << "enter id number" << endl;
       cin >> id;
       cout << "enter true if working else enter false" << endl;
       cin >> working;
       cout << "enter true if teaching assistant else enter false" << endl;
       cin >> TA;
       cout << "enter number of hours worked" << endl;
       cin >> workedHours;
       cout << "enter hourly pay" << endl;
       cin >> wage;
       StudentEmployee studentObject(id, name, working, TA, workedHours, wage);
       addEntry(studentObject);
       cout << "employee added" << endl;
   }
   else if (choice == "st")
   {cout << "please enter name" << endl;
   cin >> name;
   cout << "enter id number" << endl;
   cin >> id;
   cout << "enter true if working else enter false" << endl;
   cin >> working;
   cout << "enter weeklySalary" << endl;
   cin >> weekSalary;
   cout << "enter division" << endl;
   cin >> division;
   Staff staffObject(id, name, working, weekSalary, division);
   addStaff(staffObject);
   cout << "employee added" << endl;
   }
       else if (choice == "fac")
           cout << "please enter name" << endl;
   cin >> name;
   cout << "enter id number" << endl;
   cin >> id;
   cout << "enter true if working else enter false" << endl;
   cin >> working;
   cout << "enter true if teaching assistant else enter false" << endl;
   cin >> TA;
   cout << "enter number of hours worked" << endl;
   cin >> workedHours;
   cout << "enter hourly pay" << endl;
   cin >> wage;
   Faculty facultyObject(id, name, working, yearlySalary, weeksPerYear, division);
   addFaculty(facultyObject);
   cout << "employee added" << endl;
}

void Model::deleteEmployee()
{
       string type;
       int idNum;
       cout << "please enter sw to delete student employee st to delete staff employee and fac to delete faculty employee" << endl;
       cin >> type;

       if (type == "sw")
       {
           cout << "enter id of employee to delete" << endl;
           cin >> idNum;
           for (int i = 0; i < studentCounter; i++)
               if (idNum == studentArray[i].getemployeeID())
               {
                   for (int j = i; j < studentCounter-1; j++)
                   {
                       studentArray[j] = studentArray[j + 1];
                   }
                   studentCounter--;
               }

       }
       else if (type == "st")
       {
           cout << "enter id of employee to delete" << endl;
           for (int i = 0; i < staffCounter; i++)
               if (idNum == staffArray[i].getemployeeID())
               {
                   for (int j = i; j < staffCounter; j++)
                   {
                       staffArray[j] = staffArray[j + 1];
                   }
                   staffCounter--;
               }

       }
       else if (type == "fac")
       {
           cout << "enter id of employee to delete" << endl;
           for (int i = 0; i < facultyCounter; i++)
               if (idNum == facultyArray[i].getemployeeID())
               {
                   for (int j = i; j < facultyCounter; j++)
                   {
                       facultyArray[j] = facultyArray[j + 1];
                   }
                   facultyCounter--;
               }

       }
      
   }


void Model::displayEmployees()
{
   string workingStatus;
  
   cout << "The University two-week pay period" << endl;

   //if (workingStatus == "sw")
   //{
   //   cout << "enter id of employee to delete" << endl;
   for (int i = 0; i < studentCounter; i++)
   if (studentArray[i].getIsWorking() == "TRUE")
           {
               cout << "Name of working employees:" << studentArray[i].getemployeeName() << endl;

cout << studentArray[i].getPay() << endl;
           }

  
}

Explanation / Answer

Answer:

modify getIsWorking() in StudentEmployee, Employee,Staff,Faculty classes as follows,

string getIsWorking()

{

return working;//this returns either TRUE or FALSE

}

modify the void Model::displayEmployess() as follows,

void Model::displayEmployees()

{

    string workingStatus;

    cout<<"Please enter sw ->student employee, st->staff employee, fac->faculty employee:"<<endl;

cin>>workingStatus;

    cout << "The University two-week pay period" << endl;

    if (workingStatus == "sw")

    {

       

    for (int i = 0; i < studentCounter; i++)

    if (studentArray[i].getIsWorking() == "TRUE")

            {

                cout << "Name of working employees:" << studentArray[i].getemployeeName() << endl;

                cout << studentArray[i].getPay() << endl;

            }

     }

     else if (workingStatus == "st")

    {

       

    for (int i = 0; i < staffCounter; i++)

    if (staffArray[i].getIsWorking() == "true")

            {

                cout << "Name of working employees:" << staffArray[i].getemployeeName() << endl;

                cout << staffArray[i].getPay() << endl;

            }

     }

else if (workingStatus == "fac")

    {

       

    for (int i = 0; i < facultyCounter; i++)

    if (facultyArray[i].getIsWorking() == "true")

            {

                cout << "Name of working employees:" << facultyArray[i].getemployeeName() << endl;

                cout << facultyArray[i].getPay() << endl;

            }

     }

}

Writing information to file:

You can use the following as the base to write student employee, staff employee, faculty employee information into an output file.  

void Model::writeStudentData()

{

    ofstream fout("studentEmployeeOutData.txt");

                             

    if (fout.is_open())

    {

       

        cout << "File Opened successfully!!!. Writing data from array to file" << endl;

        for (int i = 0; i < studentCounter ; i++)

        {

            fout << studentArray[i].getemployeeID()<<" "<<studentArray[i].getemployeename()<<" "<<studentArray[i].getPay()<<endl;

        }

        cout << "Array data successfully saved into the file test.txt" << endl;

    }

    else

    {

        cout << "File could not be opened." << endl;

    }

}

void Model::writeStaffData()

{

    ofstream fout("staffEmployeeOutData.txt");

                             

    if (fout.is_open())

    {

       

        cout << "File Opened successfully!!!. Writing data from array to file" << endl;

        for (int i = 0; i < staffCounter ; i++)

        {

            fout << staffArray[i].getemployeeID()<<" "<<staffArray[i].getemployeename()<<" "<<staffArray[i].getPay()<<endl;

        }

        cout << "Array data successfully saved into the file test.txt" << endl;

    }

    else

    {

        cout << "File could not be opened." << endl;

    }

}

void Model::writeFacultyData()

{

    ofstream fout("FacultyEmployeeOutData.txt");

                             

    if (fout.is_open())

    {

       

        cout << "File Opened successfully!!!. Writing data from array to file" << endl;

        for (int i = 0; i < facultyCounter ; i++)

        {

            fout << facultyArray[i].getemployeeID()<<" "<<facultyArray[i].getemployeename()<<" "<<facultyArray[i].getPay()<<endl;

        }

        cout << "Array data successfully saved into the file test.txt" << endl;

    }

    else

    {

        cout << "File could not be opened." << endl;

    }

}

Note: Since user hasn’t provided the complete program hence I am unable to run the program.

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