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 ie not part of the PiggyBank class should also be added.Additions to the PiggyBank classConstructorsPiggyBankint int, int, intThe alternate constructor for the PiggyBank class is used to create an object with a specific number of coins.It takes 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 to initialize the object.PiggyBankconst PiggyBank &otherBankThis constructor is the copy constructor for the PiggyBank class. It is used to create an object that is a copyduplicate of an existing PiggyBank object.It takes 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 argument: a string that holds a labeltitle 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 to display the object.For example, if method is passed the string value "bank object contains", this method should display something similar to:bank object containsPennies Nickels Dimes Quarters $assuming the object that called the method contains pennies, nickels, dimes, and quarters.PiggyBank addBanksint int, int, intThis method combines the contents of two piggybanks.It takes 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 passedin 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 addBanksPiggyBank otherBankThis 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 isEqualint int, int, intThis method compares the contents of two piggybanks to determine if they are equal.It takes 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 to find the monetary value of a piggybank.bool isEqualPiggyBank otherBankThis 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 isLessThanint int, int, intThis method compares the contents of two piggybanks to determine if one is less than the other.It takes 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 to find the monetary value of a piggybank.bool isLessThanPiggyBank otherBankThis 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 getCoinint coinIndexThis method is an accessor method that can return the value of a single data member in a PiggyBank object.It takes 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 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 returnnumber of penniesnumber of nickelsnumber of dimesnumber of quartersFor any other coinIndex value, return Required Functionvoid printSectionTitlestring titleThis 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 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.mainFor this assignment, along with adding the methods to the PiggyBank class, int main must also be coded.Create PiggyBank objects. The first bank should use the alternate constructor to create an object that has pennies, nickels, dimes, and quarters. The second bank should use the alternate constructor to create an object that has pennies, nickels, dimes, and 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 arguments". Use the default constructor from Assignment to create a fourth PiggyBank object and display it with the print method. Use the addBanks method that takes integers to add a bank with pennies, nickels, dimes, and 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 arguments". Use the isEqual method that takes integers to compare a bank with pennies, nickels, dimes, and 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 integers a second time. This time compare a bank with pennies, nickels, dimes, and 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 arguments". Use the isLessThan method that takes integers to compare a bank with pennies, nickels, dimes, and 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 integers a second time. This time compare a bank with pennies, nickels, dimes, and 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 labelstitles 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 objectsbank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $Using the addBanks method with argumentsinitial bank valuePennies Nickels Dimes Quarters $bank values after using addBanks methodPennies Nickels Dimes Quarters $bank values after using addBanks methodPennies Nickels Dimes Quarters $Using the addBanks method with PiggyBank objectinitial bank valuePennies Nickels Dimes Quarters $initial bank valuePennies Nickels Dimes Quarters $initial bank valuePennies Nickels Dimes Quarters $bank values after using addBanks methodPennies Nickels Dimes Quarters $bank values after using addBanks methodPennies Nickels Dimes Quarters $bank values after using addBanks methodPennies Nickels Dimes Quarters $Using the isEqual method with argumentsTest : banks are equalTest : banks are not equalUsing the isEqual method with PiggyBank objectTest : banks are not equalTest : banks are equalCurrent values in the bank objectsbank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $bank objectPennies Nickels Dimes Quarters $Using the isLessThan method with argumentsTest : bank is less than other bankTest : bank is not less than other bank
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
