Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to be done in c++ A PiggyBank object encapsulates the contents of a piggy bank with messages associated with real world actions. It knowns

Need to be done in c++

A PiggyBank object encapsulates the contents of a piggy bank with messages associated with real world actions. It knowns how many of each coin--pennies,nickles,dims,and quarters---are in it along with total cash value.A PiggyBank object can also be empties with drainTheBank message,Which also returns the amount of money at that moment.Here is the class definition.

First part of the code

/* * This class model a piggy bank to which pennies, nickels, dimes, * and quarters can be added. A PiggyBank object maintains how many * of each coin it holds and can tell you the total money in it. * * File name: PiggyBank.h (available on this book's website) */ class PiggyBank { public: PiggyBank(); // post: An PiggyBank is built with no coins void addPennies(int penniesAdded); // pre: penniesAdded > 0 // post: This PiggyBank has penniesAdded more pennies void addNickels(int nickelsAdded); // pre: nickelsAdded > 0 // post: This PiggyBank has nickelsAdded more nickels void addDimes(int dimesAdded); // pre: dimesAdded > 0 // post: This PiggyBank has dimesAdded more dimes void addQuarters(int quartersAdded); // pre: quartersAdded > 0 // post: This PiggyBank has quartersAdded more quarters double drainTheBank(); // post: Remove all of the coins from this PiggyBank // and returns how much there was before it was emptied //-- Accessors int getPennies(); // post: Return the total number of pennies in this bank int getNickels(); // post: Return the total number of nickels in this bank int getDimes(); // post: Return the total number of dimes in this bank int getQuarters(); // post: Return the total number of quarters in this bank double getTotalCashInBank(); // post: return the total cash in the bank. Pennies are // $0.01, nickels are $0.05, dimes are $0.10, and quarters // are $0.25 (no half or one dollar coins). private: int pennies, nickels, dimes, quarters; }; 

The test driver should generate the expected output below;

#include  using namespace std; #include "PiggyBank.h" int main() { PiggyBank pb; cout << "Student Name, CIS127, Assignment 2.1" << endl; cout.setf(ios::fixed, ios::floatfield); // stops scientific notation cout.setf(ios::showpoint); // forces decimal points cout.precision(2); // sets the number of decimal to 2 cout << "Cash in the pig: " << pb.getTotalCashInBank() << endl; pb.addPennies(4); pb.addNickels(3); pb.addDimes(2); pb.addQuarters(1); cout << "Number of pennies: " << pb.getPennies() << endl; cout << "Number of nickles: " << pb.getNickels() << endl; cout << "Number of dimes: " << pb.getDimes() << endl; cout << "Number of quarters: " << pb.getQuarters() << endl; cout << "Cash in the pig: " << pb.getTotalCashInBank() << endl; cout << "Cash before draining: " << pb.drainTheBank() << endl; cout << "Cash after draining: " << pb.getTotalCashInBank() << endl; system("pause"); return 0; } Expected Output... 

Student Name, CIS127, Assignment 2.1 Cash in the pig : 0.00 Number of pennies : 4 Number of nickles : 3 Number of dimes : 2 Number of quarters : 1 Cash in the pig : 0.64 Cash before draining : 0.64 Cash after draining : 0.00 Press any key to continue . . .*/

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago