Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 18, Problem 10PC
Program Plan Intro

Payroll Modification

Program Plan:

LinkedList.h:

  • Include the required specifications into the program.
  • Define a class template named “LinkedList”.
    • Declare the member variables “value” and “*next” in structure named “ListNode”.
    • Declare the pointer variables “head” and “placeHolder” for the structure.
    • Declare the constructor, copy constructor, destructor, and member functions in the class.
  • Declare a class template and define a function named “appendNode()” to insert the node at end of the list.
    • Declare the structure pointer variables “newNode” and “nodePtr” for the structure named “ListNode”.
    • Assign the value “newValue” to the variable “newNode” and assign null to the variable “newNode”.
    • Using “if…else” condition check whether the list to be empty or not, if the “head” is empty and make a new node into “head” pointer. Otherwise, make a loop find last node in the loop.
    • Assign the value of “nodePtr” into the variable “newNode”.
  • Declare a class template and define a function named “displayList()” to print the values in the list.
    • Declare the structure pointer “nodePtr” for the structure named “ListNode”.
    • Initialize the variable “nodePtr” with the “head” pointer.
    • Make a loop “while” to display the values of the list.
  • Declare a class template and define a function named “insertNode()” used to insert a value into the list.
    • Declare the structure pointer variables “newNode”, “nodePtr”, and “previousNode” for the structure named “ListNode”.
    • Make a “newNode” value into the received variable value “newValue”.
    • Using “if…else” condition to check whether the list is empty or not.
      • If the list is empty then initialize “head” pointer with the value of “newNode” variable.
      • Otherwise, make a “while” loop to test whether the “newValue” value is less than the list values or not.
      • Use “if…else” condition to initialize the value into list.
  • Declare a class template and define a function named “deleteNode()” to delete a value from the list.
    • Declare the pointer variables “nodePtr”, and “previousNode” for the structure named “ListNode”.
    • Using “if…else” condition to check whether the “head” value is equal to “newValue” or not.
      • Initialize the variable “nodePtr” with the value of the variable “head”.
      • Remove the value using “delete” operator and reassign the “head” value into the “nodePtr”.
      • If the “newValue” value not equal to the “head” value, then define the “while” loop to assign the “nodePtr” into “previousNode”.
      • By using “if” condition, delete the “previousNode” pointer.
  • Define the destructor to destroy the values in the list.
    • Declare the structure pointer variables “nodePtr”, and “nextNode” for the structure named “ListNode”.
    • Initialize the “head” value into the “nodePtr”.
    • Define a “while” loop to make the links of node into “nextNode” and remove the node using “delete” operator.
  • Declare a class template and define a function named “getFirst()” to get a  first value from the list.
    • Declare a variable “status” in type of “boolean” and initialize the “head” value into the “placeHolder”.
    • Change the value of “status” into “true”, if the value available in “placeHolder”.
    • Return the value of “status” into called function.
  • Declare a class template and define a function named “getNext()” to get a  another value from the list.
    • Declare a variable “status” in type of “boolean”.
    • Initialize the next node value of “placeHolder” into “placeHolder”.
    • Change the value of “status” into “true”, if the next node value available in “placeHolder”.
    • Return the value of “status” into called function.

main.cpp:

  • Include the required header files into the program.
  • Declare the function prototypes to get employee information from user.
  • In “main()” function, create a object for “LinkedList” template class.
  • Define the function named “getEmployeeIds()” with an object of “LinkedList” class.
    • Declare the variable named “anotherOne” and initialize it as “y”.
    • Declare the variable named “id” in type of “long”.
    • Make a call to the function “appendNode()” with value of “id”.
    • Prompt the user to get another value from user.
  • Define the function named “getEmployeeInfo()” with an object of “LinkedList” class.
    • Declare the variables named “idNum”, “hours”, “payRate”, and “grossPay”.
    • Using “if…else” condition check whether the list is empty or not.
      • If list contains data, make a call to a function “getData()” to get the values from user.
        • Make a call to “appendNode” using objects; insert the values into the list.
      • Otherwise, display appropriate message on the screen.
  • Define the function named “getData()” with an arguments.
    • Prompt and get the values of “hours” and “payRate” from user to calculate the value of “grossPay”.
  • Define the function named “displayWages()” with an objects for linked list.
    • Declare the variables for the method.
    • Using “while” loop to display all values from the list.

Blurred answer
Students have asked these similar questions
Median Function – In statistics, the median of a set of values is the value that lies in the middle when the values are arranged in sorted order.   If the set has an even number of values, the median is the average of the two middle values.  Your program should start with two arrays of integers containing the following values: Even numbered array:  17 32 45 68 99 101 67 89 22 27 Odd numbered array:   17 32 45 68 99 101 67 89 22 Using a sort function of your choice, first sort the arrays.  NOTE:  you may use the Standard Template Library sort function or your own sort function. Then, write a function that determines the median of a sorted array.   The function should take an array of numbers and an integer indicating the size of the array and return the median of the values in the array.   The same function should be called twice – once for the even array and once for the odd array. Your program should also have a printArray function that can be used to print the sorted array. (It…
Computer Science C# Programming   Object Orientation   Please use Arrays or ArrayLists where appropriate   Implement a menu driven program that has some operations for a food truck. A food truck has multiple food items as well as a menu which contains a selection of the food items which will be sold for that day. A maximum of 10 food items can appear on the menu for any day. For each food item keep a code, description, category, price and quantity in stock (code, description and category are not usually changed).   Create a comma delimited text file called "items.txt" for 15 or more food items, indicating the item's description, category, price and quantity in stock.   Read all the food items from the text file “Items.txt”   Display all the food items available for this food truck.   Continuously prompt the user for a food item’s code to be placed on the menu until the menu is full or the user enters -1. Note that only food items which have a positive quantity in stock may be added to…
Task 3: Statistics using arrays: by java programming With the spread of COVID 19, the HR department in a company has decided to conduct some statistics among the employees in order to determine the number of infections according to some conditions. For each employee, they have to record the code, name, age, whether he/she was infected or no and the remaining days of leaves for him/her. You are requested to write the program that maintains the lists of details for the employees as mentioned above using the concept of arrays. The program repeats the display of a menu of services until the user decides to exit. 1. Start by initializing the employee details by reading them from the keyboard. 2. Repeat the display of a menu of 4 services, perform the required task according to the user’s choice and asks the user whether he/she wants to repeat or no. You need to choose one service from each category (‘A’,’B’,’C’,’D’) a. A. Display the total number of employees that were infected b. B.…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr