Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Language is: c++ // Employee.h #ifndef EMPLOYEE_H #define EMPLOYEE_H

ID: 666516 • Letter: P

Question

Programming Language is: c++

// Employee.h

#ifndef EMPLOYEE_H
#define EMPLOYEE_H
using namespace std;

class Employee{
private:
   string name;
   int idNumber;
   string department;
   string position;
public:
   Employee(string n, int id, string d, string p);
   Employee(string n, int id);
   Employee();
   void setName(string n);
   void setId(int id);
   void setDepartment(string d);
   void setPosition(string p);
   string getName();
   int getId();
   string getDepartment();
   string getPosition();
};
#endif

// Employee.cpp

#include <iostream>
#include "Employee.h"
using namespace std;

Employee::Employee(string n, int id, string d, string p){
   name = n;
   idNumber = id;
   department = d;
   position = p;
}
Employee::Employee(string n, int id){
   name = n;
   idNumber = id;
   department = "";
   position = "";
}
Employee::Employee(){
   name = "";
   idNumber = 0;
   department = "";
   position = "";
}
void Employee::setName(string n){
   name = n;
}
void Employee::setId(int id){
   idNumber = id;
}
void Employee::setDepartment(string d){
   department = d;
}
void Employee::setPosition(string p){
   position = p;
}
string Employee::getName(){
   return name;
}
int Employee::getId(){
   return idNumber;
}
string Employee::getDepartment(){
   return department;
}
string Employee::getPosition(){
   return position;
}

void display(Employee e){
   cout << "Name: " << e.getName() << ", ID: " << e.getId() << ", Department: " << e.getDepartment() << ", Position: " << e.getPosition() << " ";
}

int main(){
   Employee object1("Susan Meyers", 47899, "Accounting", "Vice President");
   Employee object2("Mark Jones", 39119, "IT", "Programmer");
   Employee object3("Joy Rogers", 81774, "Manufacturing", "Engineer");
   cout << "Employee 1: ";
   display(object1);
   cout << "Employee 2: ";
   display(object2);
   cout << "Employee 2: ";
   display(object3);
}

Augment this assignment, with an array of [SIZE] employees whereby ALL the employees are first initialized with random id numbers (for example, rand() % SOMECONSTANTOFYOURCHOICE), a distinguishing name of your choice (for example, "Emp #i") . . plus department and position as you want (for example, "Some department", "Some Position"), THEN using selection sort, sort them by ID and print them in sorted order

Explanation / Answer

Hi,

Answer to the above question:

// Employee.h
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
using namespace std;
class Employee{
private:
string name;
int idNumber;
string department;
string position;
public:
Employee(string n, int id, string d, string p);
Employee(string n, int id);
Employee();
void setName(string n);
void setId(int id);
void setDepartment(string d);
void setPosition(string p);
string getName();
int getId();
string getDepartment();
string getPosition();
};
#endif
// Employee.cpp
#include <iostream>
#include "Employee.h"
using namespace std;
Employee::Employee(string n, int id, string d, string p){
name = n;
idNumber = id;
department = d;
position = p;
}
Employee::Employee(string n, int id){
name = n;
idNumber = id;
department = "";
position = "";
}
Employee::Employee(){
name = "";
idNumber = 0;
department = "";
position = "";
}
void Employee::setName(string n){
count<<"Enter the name of the employee: ";
   cin>>name;
   name=n;
}
void Employee::setId(int id){
   srand(time(NULL));
   idNumber=(rand()%1001);//Generating random id for every employee
idNumber = id;
}
void Employee::setDepartment(string d){
   cout<<"Enter the department for the employee : ";
   cin>>>department;
department = d;
}
void Employee::setPosition(string p){
cout<<"Enter the position of the employee : ";
cin>>position;
position = p;
}
string Employee::getName(){
return name;
}
int Employee::getId(){
return idNumber;
}
string Employee::getDepartment(){
return department;
}
string Employee::getPosition(){
return position;
}
void display(Employee e){
cout << "Name: " << e.getName() << ", ID: " << e.getId() << ", Department: " << e.getDepartment() << ", Position: " << e.getPosition() << " ";
}
int main(){
Employee emp[100];//Initialising the array for 100 employess
int num,i;
cout<<" Enter number of employee details ";
cin>>num;
for(i=0;i<num;i++){
       emp[i].setName();//Setting emp name
       emp[i].setId();//Setting employee id
       emp[i].setDepartment();//setting employee department
       emp[i].setPosition();//setting employee position
       emp[i].getName();//Displaying emp name
       emp[i].getId();//Displaying employee id
       emp[i].getDepartment();//Displaying employee department
       emp[i].getPosition();//Displaying employee position      
       int emp_arr=[100];
       emp_arr=emp[i].setId();//Getting all the employee id's and saving them in an array
       cout<<"Printing employee id's of all the employess: ";
}
int min_ele_loc;
for (int j = 0; i < sizeof(emp_arr); ++j)
{
//Find minimum element in the unsorted array
//Assume it's the first element
min_ele_loc = i;

//Loop through the array to find it
for (int k = j + 1; k < sizeof(emp_arr); ++k)
{
if (ar[k] < ar[min_ele_loc])
{
//Found new minimum position, if present
min_ele_loc = k;
}
}

//Swap the values
swap (ar[j], ar[min_ele_loc]);
}  
cout<<"Printing employee id's of all the employees after sorting: "<<ar[j];
  
}

Hope that helps.HAPPY ANSWERING!!!!!!!!!!!