Question
I need to add a simple menu driven linked list. All the code is already below. Need to add: 1. Linked list (need to read
I need to add a simple menu driven linked list. All the code is already below.
Need to add:
1. Linked list (need to read "MyInFile.txt" to create the list) ***data that needs to be in .txt is below***
2. Modify data of the linked list
3. Insert a new node to the linked list
4. Delete a node from the linked list
5. Sort the Linked List
6. Exit
To test if it works:
Click 1 to create a linked list by adding a new field, amount, and display the last two nodes on the screen
Click 2 to modify all lastName to upper case and display the first three nodes
Click 2 to increase the rate by 10 for all computer science majors and display the first three nodes
Click 4 to delete nodes whose NumofHours are greater than 40 and display the deleting nodes
Click 5 to sort the linked list based on ascending order of amount.
Click 3 to add a new node with (Donky, Kong, 40, 50, Y, N ____) based on Amount sequence, and display the linked list.
Click 6 to exit
MyInFile.txt
***********************************
Computer Science 40 15.0 Y N Science Computer 30 12.0 Y Y Kompter Cience 40 20.0 Y Y Security Computer 30 30.0 N Y Computer Secrity 40 25.0 Y N John Doe 30 32.0 Y Y Mary Doe 40 40.0 Y Y Mary Jane 30 50.0 N Y Nina Fighter 40 25.0 Y N Hwarang Fighter 40 12.0 Y Y Squid Gaim 40 30.0 Y Y Dori Curier 45 30.0 N Y John Columbus 45 15.0 Y N Ch0ris Seville 35 22.0 Y Y Sunset Granada 30 20.0 Y Y Ronda HighBridge 40 30.0 N Y Pascal Malaga 40 50.0 Y N Michael Angelo 30 32.0 Y Y Osso Frienze 30 40.0 Y Y Marco Plaza 40 25.0 N Y
#include#include using namespace std; struct Worker { string lastName, firstName; int hours, major; double rate, amount; char compSci, compSec; Worker *next; }; void printTitle() { cout << " ESU-CPSC Weekly Payroll "; cout << "Fall 2022 "; cout << "Joe Smith "; return; } string readName() { string name; cin >> name; return name; } int readHours() { int hours; cin >> hours; return hours; } double readRate() { double payRate; cin >> payRate; return payRate; } int readMajor() { char status; cin >> status; if (status == 'Y' || status == 'y') { return 1; } else { return 0; } } double computeAmount(Worker *data) { double amount; amount = data->hours * data->rate; switch (data->major) { case 1: amount += 1000; break; case 2: amount += 2000; default: break; } return amount; } void printRecord(Worker *record, int size) { printTitle(); Worker *newNode = record; cout << left << setw(15) << "Last Name" << setw(15) << "First Name" << setw(15) << "# of Hours" << setw(15) << "Hourly Rate" << setw(15) << "Amount" << setw(15) << "Comp Sci" << setw(15) << "Comp Sec" << endl; for (int i = 0; i < size; i++) { cout << left << setw(15) << newNode->lastName << setw(15) << newNode->firstName << setw(15) << newNode->hours << setw(15) << newNode->rate << setw(15) << newNode->amount << setw(15) << newNode->compSci << setw(15) << newNode->compSec << endl; newNode = newNode->next; } } int main() { int size = 3; Worker *record = NULL, *head = NULL; for (int i = 0; i < size; i++) { cout << " Enter first name, last name, number of hours worked, hourly pay, Comp Sci(Y/N), and Comp Sec(Y/N) "; Worker *newNode = new Worker; newNode ->firstName = readName(); newNode ->lastName = readName(); newNode ->hours = readHours(); newNode ->rate = readRate(); newNode ->major = readMajor(); if (newNode ->major == 1) { newNode ->compSci = 'Y'; } else { newNode ->compSci = 'N'; } newNode ->major += readMajor(); if ((newNode ->major == 1 && newNode ->compSci == 'N') || newNode ->major == 2) { newNode ->compSec = 'Y'; } else { newNode ->compSec = 'N'; } newNode->amount = computeAmount(newNode); newNode->next = nullptr; if (head == NULL) { head = newNode; record = head; } else { record->next = newNode; record = newNode; } } printRecord(head, size); return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started