Need help coding this question in C++- Design a system to keep track of employee
ID: 3908961 • Letter: N
Question
Need help coding this question in 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 will is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example):
11 5.25 Lucas Da
12 6.75 Craig Johnson
Additionally we would like to be able to print payroll information from data in a different file. The data is the employee’s id number and a number of hours that they worked (example):
11 40
12 20
12 20
As you see we can have the same number listed twice in which case that person should be paid the sum of the numbers (Craig Johnson did 40 hours work, but it’s listed as 20+20). You should start by reading in the first file and storing the data as objects in a linked list. You will need to create the linked list class and the Employee data class. You may choose to use the Linked List class we created, or you may opt to create your own doubly linked list class. (Note: if you cannot get either working, you can use the STL list class but points will be deducted). The Linked list could be templated or not, it’s up to you, however templating it would allow it to be used for other projects, so it might be a good idea. Once you have read in the information from the first file, read in the second file. Ultimately we would like to print payroll information based on the hourly wage from the first file multiplied by the number of times an employee worked in the second file. How you do this is entirely up to you. The output must be in sorted (descending; so the person who gets paid most prints first) order in the form of:
*********Payroll Information********
Lucas Da, $270
Craig Johnson, $210
*********End payroll**************
Explanation / Answer
Solution:
code:
#include<iostream>
#include<string>
#include <fstream>
using namespace std;
class Employee{
private:
int id;
string name;
double payRate;
public:
Employee(int i, string n, double p){
id = i;
name = n;
payRate = p;
}
int getId(){
return id;
}
string getName(){
return name;
}
double getPayRate(){
return payRate;
}
};
struct Node {
Employee *data;
Node *next;
Node *prev;
};
class LinkedList{
private:
Node *start;
public:
LinkedList(){
start = NULL;
}
void add(int i, string n, double p){
Employee *e = new Employee(i,n,p);
Node *q = new Node;
q->data = e;
q->next = NULL;
q->prev = NULL;
if (start == NULL){
start = q;
return;
}
else {
Node *p = start;
while(p->next != NULL)
p = p->next;
p->next = q;
q->prev = p;
}
}
Node *getStart(){
return start;
}
};
int main(){
ifstream fin("input193.txt");
int iddata[100];
int hours[100];
if (!fin){
cout << "Error opening file ";
return 0;
}
int id;
string fname;
string lname;
double payRate;
LinkedList l;
while(fin >> id >> payRate >> fname >> lname){
string name = fname + " " + lname;
l.add(id,name,payRate);
}
fin.close();
ifstream fin2("input194.txt");
if (!fin2){
cout << "Error opening file ";
return 0;
}
int count = 0;
while(fin2 >> iddata[count] >> hours[count])
count++;
Node *p = l.getStart();
cout << "***********Payroll Information **************** ";
while(p!= NULL){
double pay = 0;
for (int i = 0; i<count; i++){
//cout <<p->data->getId() << " " << p->data->getId() << endl;
if (p->data->getId() == iddata[i]){
//cout << "----------------------- ";
pay = p->data->getPayRate() * hours[i];
}
}
cout << p->data->getName() << " $" << pay << endl;
p= p->next;
}
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.