Completely Confused with Selection Sorting

Hi there,

So, I am having quite a lot of problems working on this program. It is suppose to be a program that uses selection sorting to sort a list of employees based on their department, and then after sorting by department it will work by salary. The problem is I can't get this code output what I want, but I have gotten it to compile. It instead gives some wonky output that isn't anywhere near what I want.
Please help!

Here's the code I currently am in the progress of working on:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <string>
#include <vector>
using namespace std;


class Employee_Record
{
private:
    int id;
    string department;
    string name;
    int salary;
public:
    Employee_Record(): id(0), department(""), name(""), salary(0) { }
    Employee_Record(int new_id, string new_department, string new_name, int new_salary): id(new_id), department(new_department), name(new_name), salary(new_salary) { }
    int get_id() { return id; }
    string get_department() { return department; }
    string get_name() { return name; }
    int get_salary() { return salary; }
    void set_department(string new_department) { department = new_department; }
    void set_name(string new_name) { name = new_name; }
    void set_salary(int new_salary) { salary = new_salary; }
};


Here's the contents of the file I am feeding into the program:

[code]3456 14 Jackie 1200
1234 12 Kay 8000
8765 13 Mac 200
7776 10 Hey 2200
1122 12 Tess 7600
9080 14 Tom 1300
4321 12 Adam 7000
2468 12 Mat 7500
7777 10 Timothy 20000
8888 11 Kim 3000 


And lastly, here's the wonky output I am currently getting:

1
2
3
4
5
6
7
8
9
10
3456 14 Jackie 1200
1234 12 Kay 8000
1234 12 Kay 8000
7776 10 Hey 2200
7776 10 Hey 2200
7776 10 Hey 2200
7776 10 Hey 2200
7776 10 Hey 2200
7777 10 Timothy 20000
7776 10 Hey 2200


Just a side note, the first column is id#, second is department, third is name, and fourth is salary.
Last edited on
No one? Least some hints to get me on the right track!
Hooray! I Figured it out! Was actually a simple fix, the for loop was not suppose to be in the while loop, but after it. Now I can successfully sort the departments, now to sort the salaries as well. :)
Topic archived. No new replies allowed.