redo program 1(what I have type on bottom to meet the following requirements) it must not interact with the user to receive inputs for efficiency in testing programs, while meeting the following requirements. in c++
Before moving to b, make sure that each employee is unique. For this, you can manipulate data members of an employee with your choice.
Provide makefile to apply separate compilation
my program one was --
#define SIZE 5
enum Role
{
programmer = 0,
manager = 1,
director = 2
};
struct Employee
{
string firstName;
string lastName;
int SSN;
string department;
Role role;
double salary;
};
void setSalaries(Employee *em, int size)
{
for(int i = 0; i < size; i++)
{
em[i].salary = rand();
}
}
void setRoles(Employee *em, int size)
{
for(int i = 0; i < size; i++)
{
em[i].role = Role(rand()%3);
}
}
string getRole(Role role)
{
string ret;
switch(role)
{
case 0 : ret = "Programmer";
break;
case 1 : ret = "Manager";
break;
case 2 : ret = "Director";
break;
}
return ret;
}
void hardCoding(Employee *em)
{
em[0].firstName = "Bob";
em[0].lastName = "Marley";
em[0].department = "Acc.";
em[0].SSN = 3;
em[1].firstName = "Shas";
em[1].lastName = "Ivy";
em[1].department = "Audit";
em[1].SSN = 4;
em[2].firstName = "Margo";
em[2].lastName = "Kim";
em[2].department = "Mgmnt.";
em[2].SSN = 5;
em[3].firstName = "Milly";
em[3].lastName = "Pink";
em[3].department = "IT";
em[3].SSN = 6;
em[4].firstName = "Sia";
em[4].lastName = "Miskel";
em[4].department = "IT";
em[4].SSN = 7;
}
int main()
{
Employee *emp = new Employee[SIZE];
srand(time(NULL));
double avgSal = 0.0;
hardCoding(emp);
setSalaries(emp, SIZE);
setRoles(emp, SIZE);
cout<<"Employee Database\n\n";
cout<<"Name\t\tSSN\tDapartment\tRole\t\tSalary\n";
for(int i = 0; i < SIZE; i++)
{
cout<<" Average Salary: " << avgSal/size; return 0; }//Employee.h
#pragma once
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define SIZE 5
enum Role
{
programmer = 0,
manager = 1,
director = 2
};
class Employee
{
string firstName;
string lastName;
int SSN;
string department;
Role role;
double salary;
public:
Employee();
void setSalary(double sala);
void setRoles(Role r);
Role getRole();
//Added by CHEGGEA
//add mutator function to set private variables
void setFirstName(string str);
void setLastName(string str);
void setSSN(int ss);
void setDepartment(string dept);
//add accessor functions to access private
variable
string getFirstName();
string getLastName();
int getSSN();
string getDepartment();
double getSalary();
};
================================================
//Employee.cpp
#include"Employee.h"
//Added constructor without which you cannot create an
object,CHEGGEA
Employee::Employee()
{
firstName = "";
lastName = "";
SSN = 0;
department = "";
role = Role(programmer);
salary = 0;
}
//Added new function by CHEGGEA
//add mutator function to set private variables
void Employee::setFirstName(string str)
{
firstName = str;
}
void Employee::setLastName(string str)
{
lastName = str;
}
void Employee::setSSN(int ss)
{
SSN = ss;
}
void Employee::setDepartment(string dept)
{
department = dept;
}
//add accessor functions to access private variable
string Employee::getFirstName()
{
return firstName;
}
string Employee::getLastName()
{
return lastName;
}
int Employee::getSSN()
{
return SSN;
}
string Employee::getDepartment()
{
return department;
}
void Employee::setSalary(double sala)
{
salary = sala;
}
void Employee::setRoles(Role r)
{
role = r;
}
Role Employee::getRole()
{
return role;
}
double Employee::getSalary()
{
return salary;
}
==============================================
//Main.cpp
#include<iostream>
#include<string>
#include"Employee .h"
using namespace std;
void hardCoding(Employee *em)
{
em[0].setFirstName("Bob");
em[0].setLastName("Marley");
em[0].setDepartment("Acc.");
em[0].setSSN(3);
em[1].setFirstName("Shas");
em[1].setLastName("Ivy");
em[1].setDepartment("Audit");
em[1].setSSN(4);
em[2].setFirstName("Margo");
em[2].setLastName("Kim");
em[2].setDepartment("Mgmnt.");
em[2].setSSN(5);
em[3].setFirstName("Milly");
em[3].setLastName("Pink");
em[3].setDepartment("IT");
em[3].setSSN(6);
em[4].setFirstName("Sia");
em[4].setLastName("Miskel");
em[4].setDepartment("IT");
em[4].setSSN(7);
}
//Modified functions by CHEGGEA
void setSalaries(Employee *em, int size)
{
for (int i = 0; i < size; i++)
{
em[i].setSalary(rand());
}
}
void setRoles(Employee *em, int size)
{
for (int i = 0; i < size; i++)
{
em[i].setRoles(Role(rand() %
3));
}
}
string getRole(Role role)
{
string ret;
switch (role)
{
case 0: ret = "Programmer";
break;
case 1: ret = "Manager";
break;
case 2: ret = "Director";
break;
}
return ret;
}
int main()
{
Employee *emp = new Employee[SIZE];
srand((unsigned)time(NULL));
double avgSal = 0.0;
hardCoding(emp);
setSalaries(emp, SIZE);
setRoles(emp, SIZE);
cout << "Employee Database\n\n";
cout << "Name\t\tSSN\tDapartment\tRole\t\tSalary\n";
for (int i = 0; i < SIZE; i++)
{
cout << emp[i].getFirstName()
<< " " << emp[i].getLastName() << "\t";
cout << emp[i].getSSN()
<< "\t";
cout <<
emp[i].getDepartment() << "\t\t";
cout <<
getRole(emp[i].getRole()) << "\t";
cout << emp[i].getSalary()
<< "\n";
avgSal +=
emp[i].getSalary();
}
cout << "\nAverage Salary: " << avgSal / SIZE;
return 0;
}
==========================
//Makefile
Main: Main.cpp Employee.cpp
g++ -o exe Main.cpp Employee.cpp
clean:
rm -rf Main.o Employee.o Main
=====================
//after that execute below command to get exe Main
$ make Main
//you get Main executable in current directory
type in
$./Main
This will execute the program.
make clean
above command clears the object files and Main executable
/*Output
Employee Database
Name SSN Dapartment Role Salary
Bob Marley 3 Acc. Programmer 26163
Shas Ivy 4 Audit Programmer 228
Margo Kim 5 Mgmnt. Programmer 23061
Milly Pink 6 IT Director 7207
Sia Miskel 7 IT Programmer 20657
Average Salary: 15463.2
*/
==================================
redo program 1(what I have type on bottom to meet the following requirements) it must not...
Main:This is my code for my main, employee.h, and node.h files. I'm trying to rewrite my main to use the node.h to were it is a singly linked list and am failing. Can someone show me how to actually obtain this? #include <iostream> #include <string> #include <stdlib.h> #include <cstdlib> #include <ctime> #include "Employee.h" #include "Node.h" using namespace std; void deleteList(Node** head_ref) { Node* current = *head_ref; Node* next; while (current != NULL) { next = current->next; free(current); current = next; } ...
"Function does not take 0 arguments". I keep getting this error for my last line of code: cout << "First Name: " << employee1.getfirstName() << endl; I do not understand why. I am trying to put the name "Mike" into the firstName string. Why is my constructor not working? In main it should be set to string firstName, string lastName, int salary. Yet nothing is being put into the string. #include<iostream> #include<string> using namespace std; class Employee { int...
How could I separate the following code to where I have a gradebook.cpp and gradebook.h file? #include <iostream> #include <stdio.h> #include <string> using namespace std; class Gradebook { public : int homework[5] = {-1, -1, -1, -1, -1}; int quiz[5] = {-1, -1, -1, -1, -1}; int exam[3] = {-1, -1, -1}; string name; int printMenu() { int selection; cout << "-=| MAIN MENU |=-" << endl; cout << "1. Add a student" << endl; cout << "2. Remove a...
Expand the payroll program to combine two sorting techniques
(Selection and Exchange sorts) for better efficiency in sorting the
employee’s net pay.
//I need to use an EXSEL sort in order to
combine the selection and Exchange sorts for my program. I
currently have a selection sort in there. Please help me with
replacing this with the EXSEL sort.
//My input files:
//My current code with the sel sort. Please help me replace this
with an EXSEL sort.
#include <fstream>...
JAVA: How do I output all the data included for each employee? I can only get it to output the name, monthly salary and annual salary, but only from the Employee.java file, not Salesman.java or Executive.java. Employee.java package project1; public class Employee { private String name; private int monthlySalary; public Employee(String name, int monthlySalary) { this.name = name; this.monthlySalary = monthlySalary; } public int getAnnualSalary() { int totalPay = 0; totalPay = 12 * monthlySalary; return totalPay; } public String...
In Java: Executable Class create an array of Employee objects. You can copy the array you made for Chapter 20. create an ArrayList of Employee objects from that array. use an enhanced for loop to print all employees as shown in the sample output. create a TreeMap that uses Strings for keys and Employees as values. this TreeMap should map Employee ID numbers to their associated Employees. process the ArrayList to add elements to this map. print all employees in...
The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...
I have written my code for an employee management system that stores Employee class objects into a vector, I am getting no errors until I try and compile, I am getting the error: C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion). But I am not sure why any help would be great, Thank you! 1 2 3 4 5 6 7 8 9 10 11 12 13...
Hello, I need to implement these small things in my C++ code. Thanks. 1- 10 characters student first name, 10 characters middle name, 20 characters last name, 9 characters student ID, 3 characters age, in years (3 digits) 2- Open the input file. Check for successful open. If the open failed, display an error message and return with value 1. 3- Use a pointer array to manage all the created student variables.Assume that there will not be more than 99...