Question: For this assignment we are going to continue to work on some fundamental skills as we learn about more complex structures. For this assignment there

For this assignment we are going to continue to work on some fundamental skills as we learn about more complex structures. For this assignment there is a class called Record. It contains details for each employee of a company.

You're assignment is to write the code for the compare function for this class. This compare function has a small twist. There are two arguments, the first is an enum tag telling the function which field to use for comparison, the second is the compared Record. As noted in the header file, the function returns an int. The return value of zero indicates that the two objects are the same based on the field requested. Positive return values mean the compared object is lesser (or sequentially before), negative mean the compared object is greater(or sequentially after).

The test code included with this lab will sort a set of Records based on your compare function. The sort is already written (sortBy). When you are running in develop mode enter the field you would like to sort by. If the output does not show that the field are sorted based on the field you requested - there is a bug in your compare function that you will want to fix. You will be tested on all fields, so you should check them all before running in submit mode. You may submit more than once.

#include #include #include "Record.h"

using namespace std;

void printRecords(vector employees) { for ( auto it:employees) { it->print(); } }

void sortBy(Record::fieldType sortField, vector &employees) { bool sorted = false; while (!sorted) { sorted = true; for (unsigned int i=0; i < employees.size()-1; i++) { if (employees[i]->compare(sortField, employees[i+1]) > 0 ) { Record* temp = employees[i]; employees[i] = employees[i+1]; employees[i+1] = temp; sorted = false; } } } } int main() { std::vector employees; employees.push_back(new Record("David", "Bowie", 5, 8, 0)); employees.push_back(new Record("Kim", "Kardashian", 15, 9, 2)); employees.push_back(new Record("Khloe", "Kardashian", 5, 10, 3)); employees.push_back(new Record("David", "Lee Roth", 9, 4, 1)); employees.push_back(new Record("Greta", "Garbo", 1, 3, 5)); cout<<"Unsorted"<>sortField; switch (sortField) { case 0: sortBy(Record::firstNameField, employees); break; case 1: sortBy(Record::lastNameField, employees); break; case 2: sortBy(Record::yearsInServiceField, employees); break; case 3: sortBy(Record::incomeGradeField, employees); break; case 4: sortBy(Record::reviewPerformanceField, employees); break; default:cout<<"Unknown field"<

HOW THE OUT PUT SHOULD LOOK:

Unsorted

Name: Bowie, David, years in service:5, grade: 8, last review: Improvement Plan

Name: Kardashian, Kim, years in service:15, grade: 9, last review: Meets Expectations

Name: Kardashian, Khloe, years in service:5, grade: 10, last review: Outstanding

Name: Lee Roth, David, years in service:9, grade: 4, last review: Below Expectations

Name: Garbo, Greta, years in service:1, grade: 3, last review: Outstanding enter a field (0-4) to sort by:

Sorted

Name: Bowie, David, years in service:5, grade: 8, last review: Improvement Plan

Name: Lee Roth, David, years in service:9, grade: 4, last review: Below Expectations

Name: Garbo, Greta, years in service:1, grade: 3, last review: Outstanding

Name: Kardashian, Khloe, years in service:5, grade: 10, last review: Outstanding

Name: Kardashian, Kim, years in service:15, grade: 9, last review: Meets Expectations

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!