Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134443829
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18, 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.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Please original work
select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project
Please cite in text references and add weblinks
Please original work
What topic would be related to architectures or infrastructures.
How you would implement your chosen topic in a data warehouse project.
Please cite in text references and add weblinks
What is cloud computing and why do we use it? Give one of your friends with your answer.
Chapter 18 Solutions
Starting Out with C++ from Control Structures to Objects, Student Value Edition (9th Edition)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - Prob. 18.2CPCh. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.2 - Prob. 18.5CPCh. 18.2 - Prob. 18.6CPCh. 18.2 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18 - Prob. 1RQECh. 18 - Prob. 2RQECh. 18 - Prob. 3RQECh. 18 - Prob. 4RQECh. 18 - Prob. 5RQECh. 18 - Prob. 6RQECh. 18 - Prob. 7RQECh. 18 - Prob. 8RQECh. 18 - Prob. 9RQECh. 18 - Prob. 10RQECh. 18 - Prob. 11RQECh. 18 - Prob. 12RQECh. 18 - Prob. 13RQECh. 18 - Prob. 14RQECh. 18 - Prob. 15RQECh. 18 - Prob. 16RQECh. 18 - Prob. 17RQECh. 18 - Prob. 18RQECh. 18 - Prob. 19RQECh. 18 - Prob. 20RQECh. 18 - Prob. 21RQECh. 18 - Prob. 22RQECh. 18 - Prob. 23RQECh. 18 - Prob. 24RQECh. 18 - Prob. 25RQECh. 18 - T F The programmer must know in advance how many...Ch. 18 - T F It is not necessary for each node in a linked...Ch. 18 - Prob. 28RQECh. 18 - Prob. 29RQECh. 18 - Prob. 30RQECh. 18 - Prob. 31RQECh. 18 - Prob. 32RQECh. 18 - Prob. 33RQECh. 18 - Prob. 34RQECh. 18 - Prob. 35RQECh. 18 - Prob. 1PCCh. 18 - Prob. 2PCCh. 18 - Prob. 3PCCh. 18 - Prob. 4PCCh. 18 - Prob. 5PCCh. 18 - Prob. 6PCCh. 18 - Prob. 7PCCh. 18 - List Template Create a list class template based...Ch. 18 - Prob. 9PCCh. 18 - Prob. 10PCCh. 18 - Prob. 11PCCh. 18 - Prob. 12PCCh. 18 - Prob. 13PCCh. 18 - Prob. 14PCCh. 18 - Prob. 15PC
Knowledge Booster
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
- What are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_forwardDiscuss with appropriate examples the types of relationships in a database. Give one reference with your answer.arrow_forwardDetermine the velocity error constant (k,) for the system shown. + R(s)- K G(s) where: K=1.6 A(s+B) G(s) = as²+bs C(s) where: A 14, B =3, a =6. and b =10arrow_forward
- • Solve the problem (pls refer to the inserted image)arrow_forwardWrite .php file that saves car booking and displays feedback. There are 2 buttons, which are <Book it> <Select a date>. <Select a date> button gets an input from the user, start date and an end date. Book it button can be pressed only if the start date and ending date are chosen by the user. If successful, it books cars for specific dates, with bookings saved. Booking should be in the .json file which contains all the bookings, and have the following information: Start Date. End Date. User Email. Car ID. If the car is already booked for the selected period, a failure message should be displayed, along with a button to return to the homepage. In the booking.json file, if the Car ID and start date and end date matches, it fails Use AJAX: Save bookings and display feedback without page refresh, using a custom modal (not alert).arrow_forwardWrite .php file with the html that saves car booking and displays feedback. Booking should be in the .json file which contains all the bookings, and have the following information: Start Date. End Date. User Email. Car ID. There are 2 buttons, which are <Book it> <Select a date> Book it button can be pressed only if the start date and ending date are chosen by the user. If successful, book cars for specific dates, with bookings saved. If the car is already booked for the selected period, a failure message should be displayed, along with a button to return to the homepage. Use AJAX: Save bookings and display feedback without page refresh, using a custom modal (not alert). And then add an additional feature that only free dates are selectable (e.g., calendar view).arrow_forward
- • Solve the problem (pls refer to the inserted image) and create line graph.arrow_forwardwho started the world wide webarrow_forwardQuestion No 1: (Topic: Systems for collaboration and social business The information systems function in business) How does Porter's competitive forces model help companies develop competitive strategies using information systems? • List and describe four competitive strategies enabled by information systems that firms can pursue. • Describe how information systems can support each of these competitive strategies and give examples.arrow_forward
- Data communıcatıon digital data is transmitted via analog ASK and PSK are used together to increase the number of bits transmitted a)For m=8,suggest a solution and define signal elements , and then draw signals for the following sent data data = 0 1 0 1 1 0 0 0 1 0 1 1arrow_forwardDatacommunicationData = 1 1 0 0 1 0 0 1 0 1 1 1 1 0 0a) how many bıts can be detected and corrected by this coding why prove?b)what wıll be the decision of the reciever if it recieve the following codewords why?arrow_forwardpattern recognitionPCA algor'thmarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT