EBK STARTING OUT WITH C++
EBK STARTING OUT WITH C++
9th Edition
ISBN: 9780134996066
Author: GADDIS
Publisher: PEARSON CUSTOM PUB.(CONSIGNMENT)
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
8. Grade Book A teacher has five students who have taken four tests. The teacher uses the following grading scale to assign a letter grade to a student, based on the average of his or her four test scores: Test Score Letter Grade 90–100 A 80-89 B 70-79 C 60-69 D 0-59 Write a class that uses a String array or an ArrayList object to hold the five students' names, an array of five characters to hold the five students' letter grades, and five arrays of four doubles each to hold each student's set of test scores. The class should have methods that return a specific student's name, the average test score, and a letter grade based on the average. Demonstrate the class in a program that allows the user to enter each student's name and his or her four test scores. It should then display each student's average test score and letter grade. Input Validation: Do not accept test scores less than zero or greater than 100.
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…
Java code Lab 3 Problem Statement Write a program that reads in ten integers and displays the number of distinct numbers and the list of distinct numbers. (Note: distinct means unique or different. So if the user enters ten 5s, there is only one distinct number, which is 5.) You may use arrays and/or ArrayLists. All ten integers should be read from the user with one prompt. The integers entered should not be limited to any particular range. You may assume that the user will enter only valid integers. You must break the problem down into these separate methods that are each called from the main method: getUserInput findDistinctNumbers outputResults No global variables are allowed. Following is a sample run of the program: Enter ten integers separated by spaces: 1 2 -3 2 1 6 -3 -4 2 The number of distinct numbers is 5 The distinct numbers are 1 2 -3 6 -4
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