Question: OverviewFor this assignment, build on the PiggyBank class by adding some additional methods and constructors. A regular function ( i . e . not part

OverviewFor this assignment, build on the PiggyBank class by adding some additional methods and constructors. A regular function (i.e. not part of the PiggyBank class) should also be added.Additions to the PiggyBank classConstructorsPiggyBank(int, int, int, int)The alternate constructor for the PiggyBank class is used to create an object with a specific number of coins.It takes 4 arguments: an integer that holds the initial number of pennies, an integer that holds the initial number of nickels, an integer that holds the initial number of dimes, and an integer that holds the initial number of quarters.This version of the constructor should call the emptyTheBank and addCoins methods that were originally coded in Assignment 8 to initialize the object.PiggyBank(const PiggyBank &otherBank)This constructor is the copy constructor for the PiggyBank class. It is used to create an object that is a copy/duplicate of an existing PiggyBank object.It takes 1 argument: a reference to a constant PiggyBank object that holds the values to copy into the object being created.This version of the constructor should copy the data members from the passed in PiggyBank object (otherBank in the header above) into the corresponding data members of the object being created.Additional Methodsvoid print( string )This method prints the contents and value of a PiggyBank object.It takes 1 argument: a string that holds a label/title. It returns nothing.This method should display the passed in string argument and then call the printBank and printBankValue methods that were originally coded in Assignment 8 to display the object.For example, if method is passed the string value "bank1 object contains", this method should display something similar to:bank1 object containsPennies 7 Nickels 9 Dimes 3 Quarters 4$1.82assuming the object that called the method contains 7 pennies, 9 nickels, 3 dimes, and 4 quarters.PiggyBank addBanks(int, int, int, int)This method combines the contents of two piggybanks.It takes 4 arguments: an integer that holds the number of pennies in the piggybank to combine with the current instance, an integer that holds the number of nickels in the piggybank to combine with the current instance, an integer that holds the number of dimes in the piggybank to combine with the current instance, and an integer that holds the number of quarters in the piggybank to combine with the current instance.It returns a PiggyBank object: an object that holds the combined contents of the two piggybanks.The two piggybanks that are being added are the "current instance", which is the PiggyBank object that calls the addBanks method. This means that the "current instance" can be accessed by using the data members that hold the number of pennies, nickels, dimes, and quarters.The other piggybank is represented by the four passed-in arguments.The method should create a PiggyBank object to hold the combined piggybanks. The four data members of this object should be set by adding corresponding values from the current instance and passed in arguments. Once the banks have been combined, the object should be returned.Make sure the current instance is NOT CHANGED when the banks are combined.PiggyBank addBanks(PiggyBank otherBank)This method does the same thing as the other addBanks method. The difference is that the second piggy bank is passed in as a PiggyBank object rather than four separate integer values.It is strongly recommended to only formally implement one of the two addBanks methods and to then call that method in the other version of addBanks.bool isEqual(int, int, int, int)This method compares the contents of two piggybanks to determine if they are equal.It takes 4 arguments: an integer that holds the number of pennies in the piggybank to compare with the current instance, an integer that holds the number of nickels in the piggybank to compare with the current instance, an integer that holds the number of dimes in the piggybank to compare with the current instance, and an integer that holds the number of quarters in the piggybank to compare with the current instance.It returns a bool: true if the piggybanks are equal, false if the piggybanks are not equal.Two piggybanks are considered to be equal if the monetary values of the piggybanks are equal. Use the calcBankValue method that was originally coded in Assignment 8 to find the monetary value of a piggybank.bool isEqual(PiggyBank otherBank)This method does the same thing as the other isEqual method. The difference is that the second piggy bank is passed in as a PiggyBank object rather than four separate integer values.It is strongly recommended to only formally implement one of the two isEqual methods and to then call that method in the other version of isEqual.bool isLessThan(int, int, int, int)This method compares the contents of two piggybanks to determine if one is less than the other.It takes 4 arguments: an integer that holds the number of pennies in the piggybank to compare with the current instance, an integer that holds the number of nickels in the piggybank to compare with the current instance, an integer that holds the number of dimes in the piggybank to compare with the current instance, and an integer that holds the number of quarters in the piggybank to compare with the current instance.It returns a bool: true if the current instance piggybank is less than the piggybank represented by the passed in arguments, false if the current instance piggybank is not less than the piggybank represented by the passed in arguments.A piggybank is considered to be less than another piggybank if the monetary value of the piggybank is less than the monetary value of the other piggybank. Use the calcBankValue method that was originally coded in Assignment 8 to find the monetary value of a piggybank.bool isLessThan(PiggyBank otherBank)This method does the same thing as the other isLessThan method. The difference is that the second piggy bank is passed in as a PiggyBank object rather than four separate integer values.It is strongly recommended to only formally implement one of the two isLessThan methods and to then call that method in the other version of isLessThan.int getCoin(int coinIndex)This method is an accessor method that can return the value of a single data member in a PiggyBank object.It takes 1 argument: an integer that represents the data member thats value shoule be returned.It returns an integer: the value of the data member specified by the passed in index or -1 if the passed in value is invalid.The following table describes the correspondence between the passed in integer value and the data members.coinIndex valueValue to return0number of pennies1number of nickels2number of dimes3number of quartersFor any other coinIndex value, return -1.Required Functionvoid printSectionTitle(string title)This function displays a title. It is used to help separate the output that is produced by the program. It is NOT a member of the PiggyBank class.It takes 1 argument: a string that holds the title that should be displayed. It returns nothing.As mentioned, the goal is to try to separate the output that is produced by the program so that it is a little easier to read. Display a line of dashes (or whatever dividing cahracter you want to use) followed on the next line by The passed in title. The output in the Output section was created by displaying two newline characters before the line of dashes and after the passed in title.Feel free to do the display as you wish, just make sure the output is separated and easy to read.main()For this assignment, along with adding the methods to the PiggyBank class, int main() must also be coded.Create 3 PiggyBank objects. The first bank should use the alternate constructor to create an object that has 12 pennies, 34 nickels, 56 dimes, and 78 quarters. The second bank should use the alternate constructor to create an object that has 23 pennies, -5 nickels, -10 dimes, and 31 quarters. The third object should use the copy constructor to create a copy of the first object.The rest of main() will test the various methods that have been added to the class.Call the printSectionTitle function to display a title such as "Initial values in the bank objects". Use the print method to display the three PiggyBank objects.Call the printSectionTitle function to display a title such as "Using the addBanks method with 4 arguments". Use the default constructor from Assignment 8 to create a fourth PiggyBank object and display it with the print method. Use the addBanks method that takes 4 integers to add a bank with 4 pennies, 27 nickels, 45 dimes, and 7 quarters to the second PiggyBank object. The result should be saved in The fourth PiggyBank object that was created above. Use the print method to display the second and fourth PiggyBank objects.Call the printSectionTitle function to display a title such as "Using the addBanks method with PiggyBank object". Use the default constructor to create a fifth PiggyBank object. Use the print method to display the first, second, and fifth PiggyBank objects. Use the addBanks method that takes a single PiggyBank object to add the second PiggyBank object the first PiggyBank object. The result should be saved in the fifth PiggyBank object. Use the print method to display the three PiggyBank objects again.Call the printSectionTitle function to display a title such as "Using the isEqual method with 4 arguments". Use the isEqual method that takes 4 integers to compare a bank with 27 pennies, 27 nickels, 45 dimes, and 38 quarters to the fourth PiggyBank object. If the banks are equal, display a message that they are equal. Otherwise, display a message that they are not equal.Use the isEqual method that takes 4 integers a second time. This time compare a bank with 35 pennies, 34 nickels, 15 dimes, and 7 quarters to the fifth PiggyBank object. If the banks are equal, display a message that they are equal. Otherwise, display a message that they are not equal.Call the printSectionTitle function to display a title such as "Using the isEqual method with PiggyBank object". Use the isEqual method that takes a single PiggyBank object to compare the second PiggyBank object to the fifth PiggyBank object. If the banks are equal, display a message that they are equal. Otherwise, display a message that they are not equal.Use the isEqual method that takes a single PiggyBank object a second time. This time compare the first PiggyBank object to the third PiggyBank object. If the banks are equal, display a message that they are equal. Otherwise, display a message that they are not equal.Call the printSectionTitle function to display a title such as "Current values in the bank objects". Use the print method to display the five PiggyBank objects.Call the printSectionTitle function to display a title such as "Using the isLessThan method with 4 arguments". Use the isLessThan method that takes 4 integers to compare a bank with 12 pennies, 33 nickels, 42 dimes, and 108 quarters to the first PiggyBank object. If the first PiggyBank object is less than the other, display a message that the first bank is less than the other. Otherwise, display a message that the first bank is not less than the other.Use the isLessThan method that takes 4 integers a second time. This time compare a bank with 3 pennies, 4 nickels, 70 dimes, and 3 quarters to the second PiggyBank object. If the second PiggyBank object is less than the other, display a message that the second bank is less than the other. Otherwise, display a message that the second bank is not less than the other.Call the printSectionTitle function to display a title such as "Using the isLessThan method with PiggyBank object". Use the isLessThan method that takes a single PiggyBank object to compare the third PiggyBank object to the fifth PiggyBank object. If the third object is less than the fifth object, display a message that the third bank is less than the fifth. Otherwise, display a message that the third bank is not less than the fifth.Use the isLessThan method that takes a single PiggyBank object a second time. This time compare the fourth PiggyBank object to the second PiggyBank object. If the fourth object is less than the second object, display a message that the fourth bank is less than the second. Otherwise, display a message that the fourth bank is not less than the second.Finally, call the printSectionTitle function to display a title such as "Using the getCoin method". Use the getCoin method five times to get the number of pennies in the first PiggyBank object, the number of nickels in the second PiggyBank object, the number of dimes in the third PiggyBank object, the number of quarters in the fourth PiggyBank object, and pass an invalid index value to getCoin for the fifth PiggyBank object. Display all the values returned from the getCoins calls with labels.Programming RequirementsEach constructor and method must have a documentation box like a function. However, it is okay to use a single documentation box to describe the overloaded method pairs, but it must include the name of both methods that it describes.For example, one documentation box can cover the two isEqual methods.Hand in a copy of the source code using Blackboard.OutputThe labels/titles do not have to match this output exactly. However, they should convey the same basic message.*** Error: cannot add a negative number of nickels ****** Error: cannot add a negative number of dimes ***---------------------------------------------------------------Initial values in the bank objectsbank1 objectPennies 12 Nickels 34 Dimes 56 Quarters 78$26.92bank2 objectPennies 23 Nickels 0 Dimes 0 Quarters 31$7.98bank3 objectPennies 12 Nickels 34 Dimes 56 Quarters 78$26.92---------------------------------------------------------------Using the addBanks method with 4 argumentsinitial bank4 valuePennies 0 Nickels 0 Dimes 0 Quarters 0$0.00bank2 values after using addBanks methodPennies 23 Nickels 0 Dimes 0 Quarters 31$7.98bank4 values after using addBanks methodPennies 27 Nickels 27 Dimes 45 Quarters 38$15.62---------------------------------------------------------------Using the addBanks method with PiggyBank objectinitial bank1 valuePennies 12 Nickels 34 Dimes 56 Quarters 78$26.92initial bank2 valuePennies 23 Nickels 0 Dimes 0 Quarters 31$7.98initial bank5 valuePennies 0 Nickels 0 Dimes 0 Quarters 0$0.00bank1 values after using addBanks methodPennies 12 Nickels 34 Dimes 56 Quarters 78$26.92bank2 values after using addBanks methodPennies 23 Nickels 0 Dimes 0 Quarters 31$7.98bank5 values after using addBanks methodPennies 35 Nickels 34 Dimes 56 Quarters 109$34.90---------------------------------------------------------------Using the isEqual method with 4 argumentsTest 1: banks are equalTest 2: banks are not equal---------------------------------------------------------------Using the isEqual method with PiggyBank objectTest 1: banks are not equalTest 2: banks are equal---------------------------------------------------------------Current values in the bank objectsbank1 objectPennies 12 Nickels 34 Dimes 56 Quarters 78$26.92bank2 objectPennies 23 Nickels 0 Dimes 0 Quarters 31$7.98bank3 objectPennies 12 Nickels 34 Dimes 56 Quarters 78$26.92bank4 objectPennies 27 Nickels 27 Dimes 45 Quarters 38$15.62bank5 objectPennies 35 Nickels 34 Dimes 56 Quarters 109$34.90---------------------------------------------------------------Using the isLessThan method with 4 argumentsTest 1: bank1 is less than other bankTest 2: bank2 is not less than other bank

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!