Question

In: Computer Science

In this Question using c++, you are to develop an employee management system using classes. You...

In this Question using c++, you are to develop an employee management system using classes. You need to develop two classes: Date and Employee.

The Date class has the three attributes (int): month, day, and year.

The class has the following member functions: • string getDate(void): returns a string with the date information (e.g, Mach 27, 2020).

In addition to these, declare and implement proper constructors, a copy constructor, a destructor, and getters and setters for all data members.

The Emplyee class has the following attributes: • string name • int age • string position • Date hired_date • double salary_rate

The class has the following member functions: • string getEmployee(void): returns a string with the employee information. e.g., Name: Andy Pak Age: 38 Position: Software Engineer Hired date: September 2, 2016 Salary rate: $35.5/hour Days of hired: 1491 days Days of working: 1026 days Accumulated salary: $291,384 • int getHiredDays(void): returns the number of days since the employee was hired. • Int getWorkingDays (void): returns the number of working days excluding weekends and public holidays. • double getAccumulatedSalary: returns the accumulated salary since the employee was hired (5 days per week and 8 hours per day). In addition to these, declare and implement proper constructors, a copy constructor, a destructor, and getters and setters for all data members. If necessary, include helping functions in the class. Your application reads a file (“employees.txt” available in the Moodle) to construct Employee objects (and Date objects) and put them into an array. The application provides an interactive interface for the user to get the employees’ information.

Solutions

Expert Solution

CODE:

#include<iostream>
#include<string>
#include<fstream>
using namespace std;
//Date class
class Date
{
private:
    int month;
    int day;
    int year;
public:
//constructors default, parameterized and copy
    Date() {}
    Date(int d, int m, int y) {
        day = d;
        month = m;
        year = y;
    }
    Date(const Date& d1)
    {
        day = d1.day;
        month = d1.month;
        year = d1.year;
    }
    //getters and setters
   int getDay() {
        return day;
    }
    void setDay(int d) {
        day = d;
    }
    int getMonth() {
        return month;
    }
    void setMonth(int m) {
        month = m;
    }
    int getYear() {
        return year;
    }
    void setYear(int y) {
        year = y;
    }
    //returns the date in required format
    string getDate()
    {
      string s;
      switch (month)
      {
        case 1:
              s="January";
              break;
        case 2:
              s="February";
              break;
        case 3:
              s="March";
              break;
        case 4:
              s="April";
              break;
        case 5:
              s="May";
              break;
        case 6:
              s="June";
              break;
        case 7:
              s="July";
              break;
        case 8:
              s="August";
              break;
        case 9:
              s="September";
              break;
        case 10:
              s="October";
              break;
        case 11:
              s="November";
              break;
        case 12:
              s="December";
              break;
        default:
              s="Invalid month.";
              break;
        }
        s+=" "+to_string(day)+", "+to_string(year);
        return s;
    }
    //destructor
    ~Date(){}
};
//employee class
class Employee
{
private:
//variables
    string name;
    int age;
    string position;
    Date hired_date;
    double salary_rate;

public:
//getters and setters
    string getName() {
        return name;
    }

    void setName(string n) {
        name = n;
    }

    int getAge() {
        return age;
    }

    void setAge(int a) {
        age = a;
    }

    string getPosition() {
        return position;
    }

    void setPosition(string p) {
        position = p;
    }

    Date getHired_date() {
        return hired_date;
    }

    void setHired_date(Date h) {
        hired_date = h;
    }

    double getSalary_rate() {
        return salary_rate;
    }

    void setSalary_rate(double s) {
        salary_rate = s;
    }
      //constructors : default, parameterized, copy
    Employee(){}
    Employee(string n, int a, string p, Date h, double s) {
        name = n;
        age = a;
        position = p;
        hired_date = h;
        salary_rate = s;
    }
    Employee(const Employee& e)
    {
        name = e.name;
        age = e.age;
        position = e.position;
        hired_date = e.hired_date;
        salary_rate = e.salary_rate;
    }
    //destructor
    ~Employee(){}
    //returns the count of leap year
    int countLeapYears(Date d)
    {
        int years = d.getYear();
        if (d.getMonth() <= 2)
            years--;
        return years / 4 - years / 100 + years / 400;
    }
    //returns the number of days a person was hired
    int getHiredDays()
    {
        int noOfdays[] = {31,28,31,30,31,30,31,31,30,31,30,31} ;
        Date dt2(30, 9, 2020);
        long int n1 = hired_date.getYear()*365 + hired_date.getDay();
        for (int i=0; i<hired_date.getMonth() - 1; i++)
            n1 += noOfdays[i];
        n1 += countLeapYears(hired_date);
        long int n2 = dt2.getYear()*365 + dt2.getDay();
        for (int i=0; i<dt2.getMonth() - 1; i++)
            n2 += noOfdays[i];
        n2 += countLeapYears(dt2);
        return (n2 - n1);
    }
    //returns number of working days
    int getWorkingDays()
    {
        int days = getHiredDays();
        //removing weekends
        days=days-(days/7)*2;
        // there are averagely 13 public holidays in america
        int publicHolidaysAverage = 13;
        days -= publicHolidaysAverage;
        return days;
    }
    //returns the Acccumulated salary
    double getAccumulatedSalary()
    {
        return salary_rate * 8 * getWorkingDays();
    }
    //returns details of an employee in a particular format
    string getEmployee()
    {
        string s;
        s = "\nName: " + name +
            "\nAge: " + to_string(age) +
            "\nPosition: " + position +
            "\nHired Date: " + hired_date.getDate() +
            "\nSalary rate: $" + to_string(salary_rate) + "/hour" +
            "\nDays of Hired: " + to_string(getHiredDays()) + " days" +
            "\nDays of working: " + to_string(getWorkingDays()) + " days" +
            "\nAcccumulated Salary: " + to_string(getAccumulatedSalary()) + "\n";
        return s;
    }
};
int main()
{
//defining variables and arrays
    Employee empArray[10];
    //counts the number of file taken input from file
    int counter = 0;
    //opening file to read from
    fstream f;
    f.open("employee.txt",ios::in);
    //if file not opened exit the program
    if(!f.is_open())
    {
        cout<<"\n File Not opened";
        exit(1);
    }
    //defining the variables
    string name, position,temp;
    int age,d,m,y;
    Date hDate;
    double srate;
    //reading from file and adding it to array
    while(getline(f,name))
    {
        f>>age;
        getline(f, temp);
        getline(f,position);
        f>>d>>m>>y;
        f>>srate;
        Date dom(d,m,y);
        Employee emp2(name,age,position,dom,srate);
        empArray[counter] = emp2;
        getline(f,temp);
        counter++;
    }
    //printing the array
    for(int i=0;i<counter;i++)
        cout<<empArray[i].getEmployee()<<endl;
}

In file "employee.txt":

Andy pak
38
software engineer
2 9 2016
35.5
donald duck
32
manager
2 9 2017
30.5


OUTPUT:

Name: Andy pak
Age: 38
Position: software engineer
Hired Date: September 2, 2016
Salary rate: $35.500000/hour
Days of Hired: 1489 days
Days of working: 1052 days
Acccumulated Salary: 298768.000000


Name: donald duck
Age: 32
Position: manager
Hired Date: September 2, 2017
Salary rate: $30.500000/hour
Days of Hired: 1124 days
Days of working: 791 days
Acccumulated Salary: 193004.000000

Ask any questions if you have in comment section below.

Please rate the answer.


Related Solutions

As an enterprise system developer, you need to develop the registration page of the employee management...
As an enterprise system developer, you need to develop the registration page of the employee management system. The administrator of the system registers a new employee using the GUI developed in JSP. The required table ‘Employee’ is provided in mysql database with columns as employee id, name, address, city, state and zip code as shown in figure. Write a GUI snippet/JSP code with GUI components to take the user’s input. Separately, write the servlet code to insert the input records...
implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID,...
implementing linked list using c++ Develop an algorithm to implement an employee list with employee ID, name, designation and department using linked list and perform the following operations on the list. Add employee details based on department Remove employee details based on ID if found, otherwise display appropriate message Display employee details Count the number of employees in each department
Using C language The system that you will develop holds the personal information for a number...
Using C language The system that you will develop holds the personal information for a number of students and the information of the course each student is registered in. The assumption is that each student is registered in a single course only. But the system will have a number of students saved. REQUIREMENTS: In this lab, you will introduce a simple student records system, which will save the student information as well as a single course that the student is...
Write a C++ program that will be an information system for Oregon State University using classes...
Write a C++ program that will be an information system for Oregon State University using classes as well as demonstrating a basic understanding of inheritance and polymorphism. You will create a representation of an Oregon State University information system that will contain information about the university. The university will contain a name of the university, n number of buildings, and m number of people. People can be either a student or an instructor. Every person will have a name and...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this...
Create a C++ code for the mastermind game using classes(private classes and public classes). Using this uml as a reference.
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for...
use eclipse Develop the classes for the following requirements: 1. A class named Employee (general, for college) 2. A class named Instructor (more specific, for college) 3. A class named Staff (more specific, for college, HR officer, Marking staff) Tasks: 1. Figure out the relationships among the classes; 2. Determine the abstract class, and the child classes; 3. For the abstract class, determine at least one abstract method; 4. Each class should at least two data members and one extra...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using...
Develop an algorithm to implement an employee list with employee ID ,name designation and department using link list and perform the following operation on the list i)add employee details based on department ii)remove employee details iv)count the number of employee in each department
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments....
Write a C++ program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to do the following: 1....
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte...
Develop a program using Threads in C/C++ to estimate the value of PI using the Monte Carlo method use: C/C++ #include srand((unsigned)(myid)); x = ((double)rand()) / ((double)RAND_MAX); y = ((double)rand()) / ((double)RAND_MAX); Your program will allow the user to specify the number of threads (range 1 to 10) and the total number of data points (range 10 to 1,000,000) used for the Monte Carlo simulation on the command line. Note, DO NOT assume the number of data points is always...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT