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

Implementation This section further describes each class method found within the

ID: 3542506 • Letter: I

Question

Implementation
This section further describes each class method found within the UML diagram.



Class Employee
? get/setName gets and sets the employee's private name variable. Be sure to filter out bad input, such as empty strings.
? get/setEmployeeId gets and sets the employee's ID number. Be sure to filter out ID numbers that are less than or equal to zero.
? set/isWorking sets and gets whether or not the employee is working. No filtering is required.
? toString returns a tab-delimited string in the following format: "name id is working"
Class StudentEmployee
? get/setPayRate gets and sets the employee's pay rate. Be sure to filter out negative values.
? get/setHoursWorked gets and sets the hours worked for the current week. Be sure to filter out negative values.
? getWeeklyPay computes the student's weekly pay. To calculate, multiply the number of hours worked times the pay rate.
? set/isWorkStudy sets and gets whether the student is work study.
? toString() returns a tab-delimited string in the following format: "name id is working hours worked is work study pay rate"
Testing Our Classes
Use your main function to test the StudentEmployee class. In main, prompt the user for a CSV (comma separated value) file to open. Then, using the provided StringSplitter class, split the CSV using the comma as a delimiter and use the data to create a new StudentEmployee. Finally, output all StudentEmployees onto the screen.



OUTPUT SAMPLE:


we have :


CVS.TXT



StringSplitter.h

#ifndef STRINGSPLITTER_H
#define STRINGSPLITTER_H

#include <string>
#include <vector>

using namespace std;

class StringSplitter
{
public:

    //Accepts a string and a delimiter.  Will use items_found to return the number
    //of items found as well as an array of strings where each element is a piece of
    //the original string.
    static string * split(string text, string delimiter, int &items_found)
    {
        //vectors are dynamically expanding arrays
        vector<string> pieces;

        //find the first delimiter
        int location = text.find(delimiter);

        //we are starting at the beginning of our string
        int start = 0;

        //go until we have no more delimiters
        while(location != string::npos)
        {
            //add the current piece to our list of pieces
            string piece = text.substr(start, location - start);
            pieces.push_back(piece);

            //update our index markers for the next round
            start = location + 1;
            location = text.find(delimiter, start);
        }

        //at the end of our loop, we're going to have one trailing piece to take care of.
        //handle that now.
        string piece = text.substr(start, location - start);
        pieces.push_back(piece);

        //convert from vector into an array of strings
        int size = pieces.size();
        string *pieces_str = new string[size];
        for(int i = 0; i < size; i++)
        {
            pieces_str[i] = pieces.at(i);
        }
        items_found = size;
        return pieces_str;            
    }
};

#endif

Stan Stanley 1.23E+08 TRUE 19 FALSE 10.95
Ralph Maccio 2.59E+08 TRUE 15 FALSE 9.55
Julie Andrews 1.12E+08 FALSE 0 FALSE 0
Janice Young 5.59E+08 TRUE 19 TRUE 11.75
Implementation This section further describes each class method found within the UML diagram. Class Employee ? get/setName gets and sets the employee's private name variable. Be sure to filter out bad input, such as empty strings. ? get/setEmployeeId gets and sets the employee's ID number. Be sure to filter out ID numbers that are less than or equal to zero. ? set/isWorking sets and gets whether or not the employee is working. No filtering is required. ? toString returns a tab-delimited string in the following format: "name id is working" Class StudentEmployee ? get/setPayRate gets and sets the employee's pay rate. Be sure to filter out negative values. ? get/setHoursWorked gets and sets the hours worked for the current week. Be sure to filter out negative values. ? getWeeklyPay computes the student's weekly pay. To calculate, multiply the number of hours worked times the pay rate. ? set/isWorkStudy sets and gets whether the student is work study. ? toString() returns a tab-delimited string in the following format: "name id is working hours worked is work study pay rate" Testing Our Classes Use your main function to test the StudentEmployee class. In main, prompt the user for a CSV (comma separated value) file to open. Then, using the provided StringSplitter class, split the CSV using the comma as a delimiter and use the data to create a new StudentEmployee. Finally, output all StudentEmployees onto the screen.

Explanation / Answer

#include <iostream>

#include <string>

#include <sstream>

int main()

{

std::string token, text("Here:is:some:text");

std::istringstream iss(text);

while ( getline(iss, token, ':') )

{

std::cout << token << std::endl;

}

return 0;

}

/* my output

Here

is

some

text

*/