bartleby

Concept explainers

Question
Book Icon
Chapter 17, Problem 13PC
Program Plan Intro

Rainfall Statistics Modification #2

Program Plan:

“IntList.h”:

  • Include the required specifications into the program.
  • Define a class template named “IntList”.
    • Declare the member variables “value” and “*next” in structure named “ListNode”.
    • 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 “dataPtr” for the structure named “ListNode”.
    • Assign the value “num” 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 “dataPtr” into the variable “newNode”.
  • Declare a class template and define a function named “print()” to print the values in the list.
    • Declare the structure pointer “dataPtr” for the structure named “ListNode”.
    • Initialize the variable “dataPtr” 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”, “dataPtr”, and “prev” for the structure named “ListNode”.
    • Make a “newNode” value into the received variable value “num”.
    • 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 “num” 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 “dataPtr”, and “prev” for the structure named “ListNode”.
    • Using “if…else” condition to check whether the “head” value is equal to “num” or not.
      • Initialize the variable “dataPtr” with the value of the variable “head”.
      • Remove the value using “delete” operator and reassign the “head” value into the “dataPtr”.
      • If the “num” value not equal to the “head” value, then define the “while” loop to assign the “dataPtr” into “prev”.
      • Use “if” condition to delete the “prev” pointer.
  • Declare a class template and define a function named “getTotal()” to calculate total value in a list.
    • Define a variable named “total” and initialize it to “0” in type of template.
    • Define a pointer variable “nodePtr” for the structure “ListNode” and initialize it to be “NULL”.
    • Assign the value of “head” pointer into “nodePtr”.
    • Define a “while” loop to calculate “total” value of the list.
    • Return a value of “total” to the called function.
  • Declare a class template and define a function named “numNodes()” to find the number of values that are presented in the list.
    • Declare a variable named “count” in type of “integer”.
    • Define a pointer variable “nodePtr” and initialize it to be “NULL”.
    • Assign a pointer variable “head” to the “nodePtr”.
    • Define a “while” loop to traverse and count the number of elements in the list.
  • Declare a class template and define a function named “getAverage()”to find an average value of elements that are presented in list.
  • Declare a class template and define a function named “getLargest()”to find largest element in the list.
    • Declare a template variable “largest” and pointer variable “nodePtr” for the structure.
    • Using “if” condition, assign the value of “head” into “largest” variable.
    • Using “while” loop, traverse the list until list will be empty.
      • Using “if” condition, check whether the value of “nodePtr” is greater than the value of “largest” or not.
      • Assign address of “nodePtr” into “nodePtr”.
    • Return a value of “largest” variable to the called function.
  • Declare a class template and define a function named “getSmallest()” to find smallest element in the list.
    • Declare a template variable “smallest” and pointer variable “nodePtr” for the structure.
    • Using “if” condition, assign the value of “head” into “smallest” variable.
    • Using “while” loop, traverse the list until list will be empty.
      • Using “if” condition, check the value of “nodePtr” is smaller than the value of “smallest”.
      • Assign address of “nodePtr” into “nodePtr”.
    • Return a value of “smallest” variable to the called function.
  • Declare a class template and define a function named “getSmallestPosition()” to find the position of smallest value in the list.
    • Declare a template variable “smallest” and pointer variable “nodePtr” for the structure.
    • Using “while” loop traverses the list until the list will be empty.
      • Using “if” condition, find the position of “smallest” value in the list.
    • Return the value of “position” to the called function.
  • Declare a class template and define a function named “getLargestPosition()” to find the position of largest value in the list.
    • Declare a template variable “largest” and pointer variable “nodePtr” for the structure.
    • Using “while” loop traverses the list until the list will be empty.
      • Using “if” condition, find the position of “largest” value in the list.
    • Return the value of “position” to the called function.
  • Define the destructor to destroy the values in the list.
    • Declare the structure pointer variables “dataPtr”, and “nextNode” for the structure named “ListNode”.
    • Initialize the “head” value into the “dataPtr”.
    • 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 “storeToFile()” to save the list values into file.
    • Declare a pointer variable “nodePtr” for a structure “ListNode” and assign it’s to be null.
    • Make a call to create a file object “outFile()” and initialize the value of variable “head” pointer into “nodePtr”.
    • Using “while” loop save the values of list into file and assign the next node into “nodePtr”.
    • Close the file using “close()” method.
  • Declare a class template and define a function named “getFromFile()” to get the data from file into list.
    • Declare a pointer variable “nodePtr” for a structure “ListNode” and assign it’s to be null.
    • Declare a template variable “newValue” and create an object for file.
    • Using “while” loop, get the values from file into list.
    • Close the file using “close()” method.

Program #1 “Main.cpp”:

  • Include the required header files into the program.
  • Declare a variable “n” in type of integer.
  • Read the value of “n” from user and using “while” loop to validate the data entered by user.
  • Declare an object named “rainfall” for the class “IntList”.
  • Using “for” loop, read an input for every month from user.
    • Append the value entered from user into the list.
  • Make a call to the function “storeToFile()” to write the list values into file.

Program #2 “Main.cpp”:

  • Include the required header files into the program.
  • Declare an object named “rainfall” for the class “IntList”.
  • Make a call to the function “getFromFile()” to read a file into list using “rainfall” object.
  • Make a call to “getTotal()”, “getAverage()”, “getLargest()”, “getSmallest()”, “getLargestPosition()”, and “getSmallestPosition()” function and display the values on the screen.

Blurred answer
Students have asked these similar questions
Problem Statement You are working as a Devops Administrator. Y ou’ve been t asked to deploy a multi - tier application on Kubernetes Cluster. The application is a NodeJS application available on Docker Hub with the following name: d evopsedu/emp loyee This Node JS application works with a mongo database. MongoDB image is available on D ockerHub with the following name: m ongo You are required to deploy this application on Kubernetes: • NodeJS is available on port 8888 in the container and will be reaching out to por t 27017 for mongo database connection • MongoDB will be accepting connections on port 27017 You must deploy this application using the CL I . Once your application is up and running, ensure you can add an employee from the NodeJS application and verify by going to Get Employee page and retrieving your input. Hint: Name the Mongo DB Service and deployment, specifically as “mongo”.
I need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergent
I need help in my server client in C language

Chapter 17 Solutions

Starting Out with C++ from Control Structures to Objects, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (8th Edition)

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
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT