In: Computer Science
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 method by asking the user the name of the file to open.
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):
17 40
18 20
18 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 (John Jones 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. Do not use STL linked class.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********
Daniel Katz, $210
John F. Jones, $270
*********End payroll**************
The basic flow of the program is as follows:
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<cstring>
using namespace std;
class Employee
{
string name[500];
int id[500];
float payrate[500];
float payroll[500];
int count;
public:
Employee()
{
count=0;
}
void readData(ifstream &f1,ifstream &f2)
{
string str;
while(getline(f1,str))
{
int i=1;
string s;
s=str[i-1];
while(str[i]!=' ')
{
s=s+str[i];i++;
}
id[count]=atoi(s.c_str());
i=i+2;
string s1;
s1=str[i-1];
while(str[i]!=' ')
{
s1=s1+str[i];
i++;
}
payrate[count]=atof(s1.c_str());
i=i+2;
name[count]=str[i-1];
while(str[i]!='\0')
{
name[count]=name[count]+str[i];
i++;
}
//char x;
payroll[count]=0;
count++;
}
int tid,temp;
while(!f2.eof())
{
f2>>tid>>temp;
for(int i=0;i<count;i++)
{
if(tid==id[i])
{
payroll[i]=payroll[i]+temp*payrate[i];
}
}
}
}
void printInfo()
{
cout<<endl;
for(int i=0;i<count;i++)
{
cout<<name[i]<<","<<payroll[i]<<endl;
}
}
};
int main()
{
Employee obj;
char fname[100];
cout<<"Enter file name:";
ifstream f1;
cin>>fname;
f1.open(fname);
if(!f1)
{
cout<<"File opening error";
return 0;
}
cout<<"Enter file name:";
ifstream f2;
cin>>fname;
f2.open(fname);
if(!f2)
{
cout<<"File opening error";
return 0;
}
obj.readData(f1,f2);
obj.printInfo();
return 0;
}