In this assignment implement a class called Purse that will
In this assignment, implement a class called Purse that will be used to represent a collection of coins. Functionality will be added to the class so that arithmetic, relational, and output operations can be performed. A driver program is provided to test the methods.
The Purse class definition should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace for main().
The Purse class should contain four private data members. They are:
The first constructor for the Purse class (the default constructor) takes no arguments. It simply initializes the 4 data members to 0.
The second constructor for the Purse class should take four integer arguments: the number of pennies, nickels, dimes, and quarters respectively. For each argument, if the passed in value is nonnegative, it should be used to initialize the appropriate data member. If the passed in value is negative, initialize the corresponding data member to 0 and print an informative error message.
This method prints the contents of a Purse object. It takes no arguments and returns nothing. It should print the contents of the object on 4 lines in the format:
This method prints the value of a Purse object. It takes no arguments and returns nothing. It should print the contents of the object in the format:
This method will add coins to a Purse object. It takes four integer arguments and returns nothing. The arguments passed to this method are: the number of pennies, nickels, dimes, and quarters, respectively, to add to the Purse object.
Before adding a value to a data member, verify that that the value is nonnegative. If it is nonnegative, add the value to the appropriate data member. If the value is negative, print an informative error message. Think about calling the add methods described below.
This method will add pennies to a Purse object. It takes one integer argument and returns nothing. The argument passed to this method is the number of pennies to add to the Purse object.
Before adding a value to the pennies data member, verify that that the passed in value is nonnegative. If it is nonnegative, add the value to the pennies data member. If the value is negative, print an informative error message and do not change the pennies data member.
This method will add nickels to a Purse object. It takes one integer argument and returns nothing. The argument passed to this method is the number of nickels to add to the Purse object.
Before adding a value to the nickels data member, verify that that the passed in value is nonnegative. If it is nonnegative, add the value to the nickels data member. If the value is negative, print an informative error message and do not change the nickels data member.
This method will add dimes to a Purse object. It takes one integer argument and returns nothing. The argument passed to this method is the number of dimes to add to the Purse object.
Before adding a value to the dimes data member, verify that that the passed in value is nonnegative. If it is nonnegative, add the value to the dimes data member. If the value is negative, print an informative error message and do not change the dimes data member.
This method will add quarters to a Purse object. It takes one integer argument and returns nothing. The argument passed to this method is the number of quarters to add to the Purse object.
Before adding a value to the quarters data member, verify that that the passed in value is nonnegative. If it is nonnegative, add the value to the quarters data member. If the value is negative, print an informative error message and do not change the quarter data member.
This method will determine if two Purse objects are equal. It takes one argument: a Purse object and returns a boolean value. The argument passed to this method is the second Purse object that will be used in the comparison.
Two Purse objects are considered equal if their values are equal.
This method will determine if one Purse object is less than another Purse object. It takes one argument: a Purse object and returns a boolean value. The argument passed to this method is the second Purse object that will be used in the comparison.
The current Purse object is considered less than the passed in Purse object if its value is less than the value of the passed in Purse object.
This method will determine if one Purse object is greater than another Purse object. It takes one argument: a Purse object and returns a boolean value. The argument passed to this method is the second Purse object that will be used in the comparison.
The current Purse object is considered greater than the passed in Purse object if its value is greater than the value of the passed in Purse object.
This method will combine the contents of two Purse objects. For example, if the current Purse object contains 1 penny, 2 nickels, 3 dimes and 4 quarters, and a second Purse object contains 6 pennies, 7 nickels, 8 dimes and 9 quarters, then this method should produce a Purse object that contains 7 pennies, 9 nickels, 11 dimes and 13 quarters.
This method takes one argument: a Purse object and returns a Purse object. The argument passed to this method should be added to the currect Purse object. Note: the current Purse object should not be changed by this method.
This method calculates and returns the value (in dollars and cents) of a Purse object. It takes no arguments and returns a float.
For example, if the current Purse object contains 3 pennies, 4 nickels, 5 dimes, and 6 quarters, then this method should return the value 2.23.
This method will be used to help in the coding of the isEqual, isLessThan, isGreaterThan, and printPurseValue methods, therefore it should be implemented as a private method.
The driver program can be found at:
http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240pgm8.cpp
The output produced when using the driver program above can be found at:
http://faculty.cs.niu.edu/~byrnes/csci240/pgms/240out8.txt
Each method must have a documentation box like a function. However, since a lot of the methods perform similar tasks, one documentation box that gives a brief explanation for all of the related methods will suffice.
For example, one documentation box can cover the addCoins, addPennies, addNickels, addDimes, and addQuarters; printPurse and printPurseValue can be combined into one documentation box; isEqual, isLessThan, and isGreaterThan can be combined into one box; the constructors can be combined into one box.
Hand in a copy of your source code using Blackboard.
Solution
u need more ?