1. Write a program that would print the information (name, year of joining, salary, address) of employees by creating a class named 'Employee'.
  2. Create a function in the Employee class that finds an employee by the given year of joining.
  3. Create a function for sorting the employees according to their given year of joining.
  4. Create a Display Function for Employee Class.

This is what i was asked you make, i coded everything possible, but was unable to implement this part "Create a function for sorting the employees according to their given year of joining." can someone guide me how to add this? i am having trouble while doing so.

This is what i coded so far

#include <iostream>
#include <string>

using namespace std;

class Employee{
    private:
        string name;
        string address;
        int year;
        int salary;

    public:
        Employee(string, int, int, string);
        string getName();
        int getYear();
        int getSalary();
        string getAddress();
        void displayData();
};
Employee::Employee(string n, int y, int sal, string add)
{
    name = n;
    year = y;
    salary = sal;
    address = add;
}
string Employee::getName()
{
    return name;
}
int Employee::getYear()
{
    return year;
}
int Employee::getSalary()
{
    return salary;
}
string Employee::getAddress()
{
    return address;
}
void Employee::displayData()
{
    cout << getName() << '\t' << getYear() << "\t" << getSalary() << '\t' << getAddress();
}

int main()
{
    Employee e1("Robert", 1994, 500000, "64C - WallsStreet");
    Employee e2("Sam", 2000, 740000, "68D - WallsStreet");
    Employee e3("John", 1999, 600000, "26B - WallsStreet");
    cout << "\nName\tYear\tSalary\tAddress" << '\n';
    e1.displayData();
    cout << '\n';
    e2.displayData();
    cout << '\n';
    e3.displayData();
    cout << '\n';
}

Please do take a look at it and update me accordingly,

Has the course (or any previous ones) discussed sorting algorithms, yet? Given the vagueness of the instructions, something very simple such as Bubble Sort or Gnome Sort should be sufficient, but I know that just saying that won't help much if you haven't studied those before.

As an aside, you would usually place a class into a separate source file, and use a header file to import the class declarations into the main program. If the instructor hasn't covered that topic yet, then it isn't a terribly important in such a straightforward program, but you will want to know about it ahead of time.

You generally also want to avoid using namespace std; in programs generally, but again, that's not really relevant in a homework problem like this - it is just something to keep in mind for the future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.