Osman 42 21.0 Y N Nick Miller 20 20.0 Y N Jeff Schitte 33 25.0 N N John King 20 32.0 Y N Brian Nguyen 42 40.0 N Y Cheryl Ray 23 40.0 N N Chelsea Smith 39 25.0 Y Y Matt Brighter 50 12.0 N
“LinkedList.txt” listed below
John Wills 45 18.0 N Y
Hank Tom 20 12.0 Y Y
Willam Osman 42 21.0 Y N
Nick Miller 20 20.0 Y N
Jeff Schitte 33 25.0 N N
John King 20 32.0 Y N
Brian Nguyen 42 40.0 N Y
Cheryl Ray 23 40.0 N N
Chelsea Smith 39 25.0 Y Y
Matt Brighter 50 12.0 N Y
Victor Zhang 29 30.0 Y Y
Sean Kingston 30 31.0 N Y
John Wallace 29 15.0 Y N
Natalie Murphy 35 22.0 N Y
Russel Green 37 20.0 Y N
Derek Jeter 32 20.0 N N
Pascal Pedro 39 50.0 Y N
Kenneth Grant 29 32.0 N N
Stefanie Barajas 35 30.0 Y N
Kimberyl Allen 15 15.0 N Y
A reference of the program used in class is provided below
#include<bits/stdc++.h>
using namespace std;
struct Employee {
string firstName;
string lastName;
int numOfHours;
float hourlyRate;
char major[2];
float amount;
Employee* next;
};
void printRecord(Employee*);
void appendNode(Employee*&, Employee*);
int main() {
int NumOfEmp = 10;
Employee* head = nullptr;
Employee* newNode;
string firstNames[10];
string lastNames[10];
int numOfHours[10];
float hourlyRate[10];
char comp_sci[10];
char comp_sec[10];
cout << "Enter no.of records you want to enter: ";
cin >> NumOfEmp;
for (int i = 0; i < NumOfEmp; i++) {
cout << "Enter the first name of employee " << i+1 << ": ";
cin >> firstNames[i];
cout << "Enter the last name of employee " << i+1 << ": ";
cin >> lastNames[i];
cout << "Enter the number of hours worked by employee " << i+1 << ": ";
cin >> numOfHours[i];
cout << "Enter the hourly rate of employee " << i+1 << ": ";
cin >> hourlyRate[i];
cout << "Does employee " << i+1 << " have a background in computer science? (Y/N): ";
cin >> comp_sci[i];
cout << "Does employee " << i+1 << " have a security clearance? (Y/N): ";
cin >> comp_sec[i];
}
cout<<left<<setw(15) <<"Last Name"<<setw(15) <<"First Name"<<setw(12) <<"# of Hours"<<setw(12) <<"Hourly Rate"
<< setw(10) << "Amount"<< setw(10)<<"Comp Sci" << setw(20) << "Comp Sec" << endl;
for (int i = 0; i < NumOfEmp; i++) {
newNode = new Employee;
newNode->firstName = firstNames[i];
newNode->lastName = lastNames[i];
newNode->numOfHours = numOfHours[i];
newNode->hourlyRate = hourlyRate[i];
newNode->major[0] = comp_sci[i];
newNode->major[1] = comp_sec[i];
newNode->amount = newNode->numOfHours * newNode->hourlyRate;
if (newNode->major[0] == 'Y' || newNode->major[1] == 'Y') {
newNode->amount = newNode->amount + 1000;
}
if (newNode->major[0] == 'Y' && newNode->major[1] == 'Y') {
newNode->amount = newNode->amount + 2000;
}
newNode->next = nullptr;
appendNode(head, newNode);
printRecord(newNode);
}
ofstream outfile("Employee.txt");
if (!outfile) {
cerr << "Error: Output file could not be opened." << endl;
return 1;
}
outfile<<left<<setw(15) <<"Last Name"<<setw(15) <<"First Name"<<setw(12) <<"# of Hours"<<setw(20) <<"Hourly Rate"
<< setw(20) << "Amount"<< setw(20)<<"Comp Sci" << setw(20) << "Comp Sec" << endl;
Employee* current = head;
while (current != nullptr) {
outfile << left << setw(15) << current->lastName << setw(15) << current->firstName << setw(12) << current->numOfHours << setw(20)
<< current->hourlyRate << setw(20) << current->amount << setw(20) << current->major[0]<<setw(25)<< setw(25) << current->major[1] << endl;
current = current->next;
}
outfile.close();
return 0;
}
void printRecord(Employee* e) {
cout << left << setw(15) << e->lastName << setw(15) << e->firstName << setw(12)
<<e->numOfHours<<setw(12) <<e->hourlyRate<<setw(10) <<e->amount
<< setw(10) << e->major[0] << setw(10) << e->major[1]<< endl;
}
void appendNode(Employee*& head, Employee* newNode) {
if (head == nullptr) {
head = newNode;
}
else {
Employee* current = head;
while (current->next != nullptr) {
current = current->next;
}
current->next = newNode;
}
}
Step by step
Solved in 3 steps