Hi, i'm creating a c++ program with a linked list of Employees, i'm running into issues as far as displaying programmers only portion and the average salary of all the employees. Please make any changes or comments !
Employee.h file:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
using namespace std;
enum Role {programmer, manager, director};
struct Employee
{
std::string firstName;
std::string lastName;
int SSN;
std::string department;
double salary;
Role role;
};
#endif
#ifndef NODE_H
#define NODE_H
Node.h file:
#include "Employee.h"
typedef Employee EMP;
struct Node
{
EMP e;
Node * next;
Node();
Node(EMP);
Node(EMP,Node* next);
};
Node::Node()
{
next=NULL;
}
Node::Node(EMP e_data)
{
e=e_data;
}
Node::Node(EMP e_data, Node* next)
{
e=e_data;
this->next= next;
}
#endif
Main cpp file:
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Employee.h"
#include "Node.h"
using namespace std;
void setSalary (Employee& emp)
{
emp.salary= 45000+rand() %20000; // generates salary for employee
}
void setRoles(Employee& emp)
{
emp.role = static_cast(rand()%3); // gives employee job title
}
void setSSN (Employee& emp)
{
// int y = x;
emp.SSN =rand()%499999999+400000000; // sets employee SSN
}
void setFirst( Employee& emp, string* name)
{
int y = rand()%5;
emp.firstName = name[y]; //gives random first name
}
void setLast(Employee& emp, string* name)
{
int y = rand()%5;
emp.lastName = name[y]; // gives random last name
}
void setDepartment(Employee& emp, string * dep)
{
int y = rand()%3;
emp.department= dep[y]; //gives employee random department
}
int main()
{
srand(time(NULL)); // random number generator
double avgSalary; // initialize Average Salary
Node* head= NULL; // starting node
Node* prev= NULL; // node next to the last one
Employee e; // object instance
// array of names, roles(job titles), and departments
string roleType [3] = {"programmer", "manager", "director"};
string firstName[5] = {"John", "James", "Joe", "Jessica", "Juno" };
string lastName[5] = {"Smith", "Williams", "Jackson", "Jones", "Johnson" };
string department[5]= {"Accounting", "IT", "Sales" };
// Create linked list of employees
for (int i = 0; i<10; i++)
{
Employee e;
// function calls (roles, salary ...etc)
setFirst(e, firstName);
setLast(e, lastName);
setSSN(e);
setSalary(e);
setRoles(e);
setDepartment(e, department);
// creates nodes for employees
Node*temp = new Node(e);
if (i ==0)
{
head=temp;
prev= temp;
}
else
{
prev->next= temp;
prev = temp; // links the nodes together
}
}
// Display information of all Employees
cout<<"======== Employee Data======="<
prev = head; // starting at the first node
while(prev !=NULL)
{
cout<<(prev->e).firstName<< " ";
cout<<(prev->e).lastName<< " ";
cout<<(prev->e).SSN<< " ";
cout<<(prev->e).salary<< " ";
cout<<(prev->e).department<< " ";
cout
prev= prev->next;
}
cout<<" \n \n";
//
cout<<"======== Programmer Only Data======="<
prev = head; // starts at beginning of linked list
while(prev !=NULL)
{
if (prev->e.role == 0) // checks to see if role is 0 or programmer
cout<<(prev->e).firstName<< " ";
cout<<(prev->e).lastName<< " ";
cout<<(prev->e).SSN<< " ";
cout<<(prev->e).salary<< " ";
cout<<(prev->e).department<< " ";
cout
prev= prev->next; // moves on to next node
// else {
// break;
// }
}
//Computes Average Salary
prev = head; // starts at the first node
while ( prev !=NULL)
{
avgSalary += (prev->e).salary;
prev = prev->next;
}
// Display Average Salary
cout<< "Average Salary: "<< (avgSalary)/5 << "\n";
// Deallocate memory
Node* temp = head;
Node* tail;
while (temp !=NULL)
{
tail=temp->next;
delete temp;
temp = tail;
}
head=NULL;
if (head == NULL )
{
cout<<" List Deleted \n";
}
}
In: Computer Science
In: Economics
In: Economics
Suppose that the U.S. government decides to charge cola producers a tax. Before the tax, 50 million cases of cola were sold every month at a price of $7 per case. After the tax, 44 million cases of cola are sold every month; consumers pay $10 per case, and producers receive $4 per case (after paying the tax).
In: Economics
Determine the pH during the titration of 24.3 mL of 0.310 M formic acid (Ka = 1.8×10-4) by 0.442 M NaOH at the following points. (a) Before the addition of any NaOH (b) After the addition of 4.20 mL of NaOH (c) At the half-equivalence point (the titration midpoint) (d) At the equivalence point (e) After the addition of 25.6 mL of NaOH
In: Chemistry
Determine the pH during the titration of 65.9
mL of 0.410 M hypochlorous acid
(Ka = 3.5×10-8) by
0.410 M NaOHat the following
points.
(a) Before the addition of any NaOH-?
(b) After the addition of 16.0 mL of
NaOH-?
(c) At the half-equivalence point (the titration midpoint) -?
(d) At the equivalence point -?
(e) After the addition of 98.9 mL of
NaOH-?
In: Chemistry
1) 20.00 mL of a 0.3000 M lactic acid solution is titrated with 0.1500 M NaOH.
a. What is the pH of the initial solution (before any base is added)?
b. What is the pH of the solution after 20.00 mL of the base solution has been added?
c. What is the pH of the solution after 40.00 mL of the base solution has been added?
In: Chemistry
Determine the pH during the titration of 22.7
mL of 0.406 M hydrocyanic acid
(Ka = 4.0×10-10) by
0.492 M KOH at the following
points.
(a) Before the addition of any KOH
(b) After the addition of 4.60 mL of
KOH
(c) At the half-equivalence point (the titration midpoint)
(d) At the equivalence point
(e) After the addition of 28.1 mL of
KOH
In: Chemistry
Determine the pH during the titration of 24.3
mL of 0.310 M formic acid
(Ka = 1.8×10-4) by
0.442 M NaOH at the following
points.
(a) Before the addition of any NaOH
(b) After the addition of 4.20 mL of
NaOH
(c) At the half-equivalence point (the titration midpoint)
(d) At the equivalence point
(e) After the addition of 25.6 mL of
NaOH
In: Chemistry
Michaels Corporation expects earnings before interest and taxes to be $ 53,000 for this period. Assuming an ordinary tax rate of 40 %, compute the firm's earnings after taxes and earnings available for common stockholders (earnings after taxes and preferred stock dividends, if any) under the following conditions: a. The firm pays $ 11,900 in interest. b. The firm pays $ 11,900 in preferred stock dividends.
In: Finance