due at midnight on +60
For this project, we will explore structured data. Based on the sample code for employees provided in class, you should declare a vector of employees and fill it with data representing 4-5 people.
Then your program should sort the data in different ways – by name, by salary, by ID number, by hire date – and print the results. Here’s the output of my solution (which didn’t include the date structure):
SORTED BY LAST NAME
29837 Barton Frank $43,560
29999 Cline Kim $1,038,094
29570 Middleton Zoltan $931,352
29140 Zarkov Alice $87,100
SORTED BY SALARY
29999 Cline Kim $1,038,094
29570 Middleton Zoltan $931,352
29140 Zarkov Alice $87,100
29837 Barton Frank $43,560
SORTED BY FIRST NAME
29140 Zarkov Alice $87,100
29837 Barton Frank $43,560
29999 Cline Kim $1,038,094
29570 Middleton Zoltan $931,352
SORTED BY ID NUMBER
29140 Zarkov Alice $87,100
29570 Middleton Zoltan $931,352
29837 Barton Frank $43,560
29999 Cline Kim $1,038,094
Here’s a sketch of a technique for sorting a vector in C++. It uses a built-in sort
function, but you will need to define and provide the sort criterion as a function:
#include <algorithm> // Needed for sort
// Define struct employee and other functions
// Define sort criteria as boolean functions
// comparing two employees. For example:
bool byLastName(employee e1, employee e2)
{
return e1.lastName < e2.lastName;
}
int main()
{
vector<employee> team = // ... Initialize yourself ...
// To sort:
sort(team.begin(), team.end(), byLastName);
// Now the order of entries in the team vector
// has been rearranged, so you can print them.
return 0;
}
Name your program p12sort.cpp
and submit to this dropbox.