Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 11.4, Problem 24STE
Program Plan Intro
Destructor:
- Destructor is a member function of a class that is called automatically when an object of the class goes out of scope.
- This means that if the program has a local variable that is an object with a destructor, then when the function call ends, the destructor is called automatically.
- Destructors are used to remove any dynamic variables that have been generated by the object so that the memory occupied by these dynamic variables is returned to the freestore.
- Destructors may implement other cleanup tasks as well.
- The name of the destructor must contains a tilde symbol, “~” followed by the name of the class.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
1. Write a program that would resemble a power utility billing system. There will be an input window that would enter or input the meter number (5 numeric digits) and the present meter reading in kilowatt hours, the maximum would be 9999 kilowatts. A search from a 2d-arraylist would be made in order to get the previous meter reading of a particular meter number. The 2d- arraylist consists of meter number (5 numeric digits) and the previous meter reading in kilowatt hours (4 numeric digits with 9999 as maximum value). Provide at least 5 sample data or 5 rows with meter number and previous meter reading each row for the 2d-arraylist. When an input of meter number and present meter reading is made, search the 2d-arraylist for the equivalent meter number. If a match is found, get the kilowatt hour used (KWH) by subtracting the previous meter reading from the present meter reading. Note that if the present meter reading is less than previous meter reading, add 10000 first to the present…
Complete the implementation of scrabble.c, such that it determines the winner of a short scrabble-like game, where two players each enter their word, and the higher scoring player wins. Notice that we’ve stored the point values of each letter of the alphabet in an integer array named POINTS. For example, A or a is worth 1 point (represented by POINTS[0]), B or b is worth 3 points (represented by POINTS[1]), etc. Notice that we’ve created a prototype for a helper function called compute_score() that takes a string as input and returns an int. Whenever we would like to assign point values to a particular word, we can call this function. Note that this prototype is required for C to know that compute_score() exists later in the program. In main(), the program prompts the two players for their words using the get_string() function. These values are stored inside variables named word1 and word2. In compute_score(), your program should compute, using the POINTS array, and return the score…
1. Write a Java program that would resemble banking transactions of deposits, withdrawals, bank to bank transfers, and interest computations. A transaction input window is to be used in entering the account number, transaction code, and amount. Search a 2d-ArrayList containing the account number and the current balance, and then do the appropriate update on the 2d-ArrayList depending on the transaction code. If the transaction code is “D”, update the current balance by adding the amount; if “W”, update the current balance by subtracting the amount from the current balance provided that a withdrawal transaction is allowed (current balance must be greater than the amount to be withdrawn, and the resulting balance must not be less than 500). Display the updated 2d-ArrayList before exiting the program. (USE OOP CONCEPT JFRAME)
Chapter 11 Solutions
Problem Solving with C++ (10th Edition)
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...Ch. 11 - Do Programming Project 19 from Chapter 8 except...
Knowledge Booster
Similar questions
- Consider the IntArrayBag collection class that we discussed in class, Draw the data array after executing the following code and show the values that are stored in each cell of the array. Show the array four times at the points labelled A, B, C, and D IntArrayBag bag1 = new IntArrayBag(5); bag1.add(10); bag1.add(5); bag1.add(20); bag1.add(13); //Point A bag1.remove(5); //Point B bag1.add(8); bag1.remove(10); //Point C bag1.add(30); //Point D Exercise 4: search methodarrow_forwardGiven two ArrayLists: list1=[10,20,30], and list2=[40,50], what is the content of the list1 after executing the following statement: list1.addAll(list2) a. [40, 50] b. [10, 20, 30] c. [10, 40, 50, 20, 30] d. [10, 20, 30, 40, 50]arrow_forwardA) Consider the generic print() method, write a method that takes an array of E, where E must be Comparable or extend a type that is Comparable, and returns a reference to the greatest object in the array. In this case, the greatest value is one for which compareTo() would return 0 or more for any other object in the array. If there is more than one possible largest value (these would have to be equal to each other but greater than any other objects in the array), it does not matter which one you choose. B) Write a generic Java queue class (a plain queue, not a priority queue). Call it GenericQueue, because the JDK already has an interface called Queue. The class must be able to create a queue of objects of any reference type. Consider the GenericStack class shown in the lecture notes for some hints. Like the Stack, the GenericQueue should use an underlying ArrayList<E>. Write these methods and any others you find useful: enqueue() adds an E to the queue peek() returns a…arrow_forward
- Java In this assignment, you will practice using an ArrayList. Your class will support a sample program that demonstrates some of the kinds of operations a windowing system must perform. Instead of windows, you will be manipulating “tiles.” A tile consists of a position (specified by the upper-left corner x and y), a width, a height, and color. Positions and distances are specified in terms of pixels, with the upper-left corner being (0, 0) and the x and y coordinate increasing as you move left and down, respectively. You won’t have to understand a lot about tiles and coordinates. That code has been written for you. You are writing a small part of the overall system that keeps track of the list of tiles. You are required to implement this using an ArrayList. The only method you need to use from the Tile class is the following: // returns true if the given (x, y) point falls inside this tile public boolean inside(int x, int y) Your class is to be called TileList and must…arrow_forwardIn F3, students will be tasked with taking input from a file to create an *Array* of FeetInches (2 parameters). When all the FeetInches have been stored, any FeetInches at least 1 foot will be converted and added to an *ArrayList* of Circles (one parameter). Students will then complete the compareTo method found in the Circle class, sort the ArrayList of Circles, and then output the radius' of the new circle. The first integer in the file input will tell us how many FeetInches objects will be made using the fileInput, and the numbers after are the data for those Objects. Use this first integer in your for Loops. A template with main, Circle, and FeetInches class, as well as the file input, is attached below. Please follow along with comments and reach out if you have any questions. package f3_template; public class Circle implements Comparable <Circle>{//attribute private int radius; //constructorspublic Circle(){radius=0;}public Circle(int r){radius=r;}//accessorspublic…arrow_forwardIn Java Suppose your code fills an Animal[] array with objects instantiated from severaldifferent classes derived from the Animal class, like Dog, Cat, Human, Flea, etc.Write a Java statement that prints, “Tries to explain meaning of life” if and only ifAnimal[i] refers to a Human.arrow_forward
- Can help in java ? Define a two-dimensional array of names. For each row: • specify the name with the longest length • check for a name starting with "A" (save its index) Save the results in one-dimensional arrays (initialize all elements of the second result array with -1 initially). Display an array of names, the names with the longest length of each line, and the name starting with "A" from each line or a message that there is none.arrow_forwardIn java A supermarket wants to reward its best customer of each day, showing the customer’s name on a screen in the supermarket. For that purpose, the store keeps an ArrayList.Create a class customer having id, name, gender, and bill provide appropriate getters/setters and constructors also provide toString method.In the Store class, make an ArrayList of customers, store name, and address implement methods public void addSale(Customer c) that will add customers to the arraylist.public void RemoveCustomer(int id);public void UpdateCustomerRecord(int Id);public displayAll();public String nameOfBestCustomer() to record the sale and return the name of the customer with the largest sale. public ArrayList nameOfBestCustomers(int topN) so that it displays the top customers, that is, the topN customers with the largest sales, where topN is a value that the user of the program supplies. Write a program that prompts following menu and ============================================…arrow_forwardQ1: Write a program in Java that reads 10 integers and store them in AN ArrayList. Then, do the following : a) Print the ArrayList in the reverse order b) Sort the ArrayList, and display the data after sorting c) Print the largest and the smallest element in the ArrayListarrow_forward
- Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.Develop a class ResizingArrayQueueOfStrings that implements the queueabstraction with a fixed-size array, and then extend your implementation to use arrayresizing to remove the size restriction.arrow_forwardWrite a JAVA program Write a function inside ProblemSolution class whose return type is void, accepts an array and the length of the array as input parameters. The function should call a static method display of MyArray class by passing an array and length value. Input 5 1 5 8 2 0 Where, First line of input represents the size of an array. Second line represents array elements. Output 1 5 8 2 0 Assume that, N is an integer within the range [0 to 10000]. Array elements are integers within the range [-2147483648 to 2147483647].arrow_forwardTODO 1 Obtain all the indexes with labels equal 2 with np.where and the label array y. Keep the results in two_class_idx also index np.where() at 0 # TODO 1.1 two_class_idx = print(f"two_class_idx output: \n {two_class_idx}") try: print(f"two_class_idx shape: {two_class_idx.shape}") except Exception: pass todo_check([ (isinstance(two_class_idx, np.ndarray),f'two_class_idx is not an NumPy array! two_class_idx is currently a {type(two_class_idx)}'), (np.all(two_class_idx == np.array([3,9,11,12,16])),'two_class_idx does not contain the correct location values') ])arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education