./test testPassedPrintReportEmployee
Test Name: testPassedPrintReportEmployee
FAILED this test
Expected result:
Managers: 1
Your result:
Managers: 0.000000
is still failing
Assistant
The error you’re encountering in your test indicates that the expected output for the number of managers is 1, but your program is returning 0.000000. This could be due to various reasons in your implementation. To troubleshoot and potentially resolve this issue, consider the following steps:
User
Assistant
Check the Logic for Counting Managers: Review the part of your code that counts managers. Ensure that you are correctly identifying and counting the managers based on whatever criteria you have established (e.g., specific roles or attributes).
Data Initialization: Ensure the dataset you are using in your test correctly populates a manager. It’s possible that the test data does not have any managers, leading to the 0 count.
Type of Variable: It seems you might be returning a floating-point number (as indicated by .000000) instead of an integer. Verify the data type of the variable that stores the count of managers. It should be an integer, not a float. You can convert it to an integer before returning or printing.
Print Formatting: If your test expects "Managers: 1" but your output is "Managers: 0.000000", check how you are formatting the output string. You might be accidentally formatting the count as a float. You can force the output to be formatted as an integer.
Test Cases: Verify that your test case is valid and that the setup for it is correct. If you have access to the test data files or database entries, ensure there is a manager available as expected.
Debugging: You can add debug print statements before the counting occurs to see what your criteria for managers are and what the initial data looks like. This will help isolate where things might be going wrong.
Here's an example of how you might implement the counting and formatting correctly in pseudo-code:
python
def print_report(employees):
manager_count = sum(1 for e in employees if e.role == 'manager') # Count the managers
print(f"Managers: {int(manager_count)}") # Ensure to print as an integer
By following the above tips and carefully reviewing your code, you should be able to identify the cause of the test failure and correct it. If you have specific code snippets to share, I'd be glad to offer more targeted advice.
//Destructor
Employees::~Employees() {
//Go through vector and delete each employee object
if(workers != nullptr) {
// Loop through each index of the workers vector
for (unsigned int i = 0; i < workers->size(); i++) {
//Delete the employee at index i
delete workers->at(i);
}
//Delete the workers vector
delete workers;
//Set workers pointer to nullptr
//To avoind dangling pointers
workers = nullptr;
}
}
//Copy Constructor
//responsible for creating new copy of workers vector
//
Employees::Employees(const Employees &other)
{
//Create a new vector for copied employees
workers = new vector<Employee*>();
code
//Loop through the original workers vector
for (unsigned int i = 0; i < other.workers->size(); i++) {
//Create employee object for worker at i
Employee* originalEmp = other.workers->at(i);
//Clone the employee
Employee* clonedEmp = originalEmp->clone();
//add the cloned employee to the new vector
workers->push_back(clonedEmp);
}
//Set the number of managers, clerks, stylists and vets
numManagers = other.numManagers;
numClerks = other.numClerks;
numStylists = other.numStylists;
numVets = other.numVets;
}
void Employees::addEmployee(string line)
{
//Splitting the string by spaces
code
//Variable to hold whats obtained from the original
string s;
stringstream ss(line);
//Vector to hold the split string
vector<string> splitString;
while(getline(ss, s, ' ')) {
splitString.push_back(s);
}
//Get employee information
//Pay Code
string payCode = splitString.at(0);
//First Name
string firstName = splitString.at(1);
//Last Name
string lastName = splitString.at(2);
//Employee ID
int employeeID = stoi(splitString.at(3));
//Depending on the pay code
//It's going to be salary, hourly, vaccine or appointment
double amount = stod(splitString.at(4));
//Create a new employee based on paycode
Employee* newEmployee = nullptr;
switch(stoi(payCode)) {
case 1: //Manager
newEmployee = new Manager(firstName, lastName, employeeID, amount);
//Increase number of managers
numManagers++;
break;
case 2:
{//Clerk
int hoursWorked = stoi(splitString.at(5));
newEmployee = new Clerk(firstName, lastName, employeeID, amount, hoursWorked);
//Increase number of clerks
numClerks++;
break;
}
case 3:
{//Vet
// int vaccineNumber = stoi(splitString.at(5));
newEmployee = new Vet(firstName, lastName, employeeID, amount);
//Increase number of vets
numVets++;
break;
}
case 4:
{ //Stylist
double numberOfAppt = stoi(splitString.at(5));
newEmployee = new Stylist(firstName, lastName, employeeID, amount, numberOfAppt);
//Increase number of stylists
numStylists++;
break;
}
}
//Add the new employee to the workers vector
workers->push_back(newEmployee);
}
double Employees::calculateWeeklyPay()
{
// Check if there are any employees
if (workers->empty()) {
return 0.0;
}
code
double total = 0.0;
//Loop through the workers vector
//and calculate their weekly pay
for (unsigned int i = 0; i < workers->size(); i++) {
total += workers->at(i)->calcWeeklyPay();
}
return total;
}
string Employees::printReport()
{
// Check if there are any employees
if (workers->empty()) {
return "No employees to report.";
}
//Sort the emploeyees by employee number
sort(workers->begin(), workers->end(), compareEmployees);
//String to return the report
ostringstream report;
report << "Weekly Pay Report for Pete's Pets" << endl;
report << endl;
report << "Employee Weekly Pay" << endl;
//Get the total payroll
double total = calculateWeeklyPay();
//Add each employee's info to the report
for(unsigned int i =0; i < workers->size(); i++) {
Employee* employee = workers->at(i);
report << setw(25)<< employee->toString() << setw(10) << fixed << setprecision(2) << employee->calcWeeklyPay() << endl;
}
//Add the total to the report
report << "Total payroll: " << total << endl;
report << "Managers: " << getNumManagers() << endl;
report << "Clerks: " << getNumClerks() << endl;
report << "Vets: " << getNumVets () << endl;
report << "Stylists: " << getNumStylists() << endl;
return report.str();
}
Employees &Employees::operator=(const Employees &other)
{
//Check for self assignement
if (this == &other) {
return *this;
}
code
//If this is not null we loop through vector
//And delete existing employees
if(workers != nullptr){
for(unsigned int i = 0; i < workers->size(); i++) {
delete workers->at(i);
}
//Delete the workers vector when done
delete workers;
workers = nullptr;
}
//Deepy copy other object
workers = new vector<Employee*>;
for(unsigned int i = 0; i < other.workers->size(); i++) {
workers->push_back(other.workers->at(i)->clone());
}
numManagers = other.numManagers;
numClerks = other.numClerks;
numVets = other.numVets;
numStylists = other.numStylists;
return *this;
}
this is my class
int testPassedPrintReportEmployee()
{
int returnResult = 1;
string expectedString = "";
string student = "";
Employees employees;
Based on the code you provided, you're encountering an issue where the testPassedPrintReportEmployee() test expects the count of managers to be 1, but your implementation returns 0.000000 instead. Here's a breakdown of what could be causing this issue, as well as recommendations on how to fix it.
Potential Issues:
Input Data File (employees.txt): Ensure that the employees.txt file contains an employee entry for a manager. For instance, a line that looks something like:
code
1 John Doe 11111 5000.00
This line indicates that John Doe is a manager (indicated by the 1 in the beginning), with an employee ID of 11111 and a salary of 5000.00.
Add Employee Logic:
In your addEmployee method, you correctly increment the numManagers counter when adding a manager. Make sure that this part is actually executed by checking whether the correct line from employees.txt is processed.
Reading from the File: In the loop where you read from the file, ensure that you're actually getting input lines. Use condition checks to validate the format of each line read to ensure your parsing is robust.
Floating Point Display: The failure message shows 0.000000 which typically indicates that you are somehow formatting or outputting numManagers as a double rather than an integer. Check the output line where you print managers in printReport().
Suggested Code Changes:
Modify the Print Report Function: Ensure the manager count is returned as an integer rather than a floating-point number.
with the following to ensure there's no floating-point display:
cpp
report << "Managers: " << numManagers << endl;
Ensure That Managers Are Added Correctly:
Here is how a valid line should look in your input file:
plaintext
1 John Doe 11111 5000.00
Make sure you include this kind of line in your employees.txt file.
Make Sure of Data Type Consistency:
If you are handling numManagers as an integer, make sure that you're not inadvertently changing its type during calculations or while retrieving its value.
Debugging: You can add intermediate print statements in the addEmployee method to confirm that the manager's data is being parsed correctly and that numManagers is being updated:
If you have not tested with the correct input, please add to employees.txt the following lines:
code
1 John Doe 11111 5000.00
2 Jane Smith 22222 20.00 40
3 Dr. Bob 33333 700.00
4 Sally Stylist 44444 150.00 10
Summary:
Ensure your input data is correct.
Confirm that the number of managers is being calculated and printed correctly.
Validate all inputs and outputs for types and correctness, especially looking out for issues with floating-point numbers.
By going through these points, you should be able to resolve the issue with your test case not passing. Please update me if the suggestions above do not resolve the issue, and we can further investigate.
Not yet included in a published release.
ifstream in;
string line;
string fileName = "employees.txt";
string result;
char result1[80];
int empNum;
double total;
in.open(fileName);
if (!in)
{
student = "Could not open file: " + fileName;
expectedString = "Opened file: " + fileName + "\n";
printResultsStr(returnResult, expectedString, student);
return 1;
}
// read a line and add to employees
while (!in.eof())
{
getline(in, line);
employees.addEmployee(line);
}
// report
istringstream inp(employees.printReport());
inp.getline(result1, 80, '\n'); //"Weekly Pay Report for Pete's Pets"
inp.getline(result1, 80, '\n'); // empty line
inp.getline(result1, 80, '\n'); //"Employee Weekly Pay"
inp >> empNum;
if (empNum != 11111)
{
expectedString = "First employee number should be 11111\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 22222)
{
expectedString = "Second employee number should be 22222\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 33333)
{
expectedString = "Third employee number should be 33333\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp >> empNum;
if (empNum != 44444)
{
expectedString = "Fourth employee number should be 44444\n";
student = empNum;
}
else
{
inp.getline(result1, 80, '\n'); // get the rest of the line
inp.getline(result1, 80, '\n'); // empty line
inp >> result; //"Total"
inp >> result; //"payroll"
inp >> total;
if (((total - 3550.00) > .01))
{
expectedString = "total: 3500.00\n";
student = "total: " + to_string(total);
}
else
{
inp >> result; //"Managers"
inp >> total;
if (total != 1)
{
expectedString = "Managers: 1\n";
student = "Managers: " + to_string(total);
}
else
{
inp >> result; //"Clerks"
inp >> total;
if (total != 1)
{
expectedString = "Clerks: 1\n";
student = "Clerks: " + to_string(total);
}
else
{
inp >> result; //"Vets"
inp >> total;
if (total != 1)
{
expectedString = "Vets: 1\n";
student = "Vets: " + to_string(total);
}
else
{
inp >> result; //"Sylist"
inp >> total;
if (total != 1)
{
expectedString = "Stylist: 1\n";
student = "Stylist: " + to_string(total);
}
else returnResult =0;
}
}
}
}
}
}
}
}
printResultsStr(returnResult, expectedString, student);
return returnResult;