Question
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,
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. Edit Record.cpp to get the correct output.
CORRECT OUTPUT:
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
main.cpp
#include
using namespace std;
void printRecords(vector
void sortBy(Record::fieldType sortField, vector Record.h #include using namespace std; void printRecords(vector void sortBy(Record::fieldType sortField, vector Record.cpp #include "Record.h" using namespace std; Record::Record(std::string first, std::string last, int years, int grade , int review) { firstName = first; lastName = last; yearsInService = years; incomeGrade = grade; reviewPerformance = min(3,review); } void Record::print() { cout<<"Name: "< // compares specified field between two Records // returns 0 if equal, // returns <0 if compared object is lesser,>0 if compared object greater int Record::compare(Record::fieldType field, Record* compareRecord) { return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started