The program can be tested using this file httppastebincomGi4

The program can be tested using this file. http://pastebin.com/Gi4BaxWX

Write a class called PiggyBank that contains the following private member variables: e isBroken o a bool indicating whether or not the piggy bank is broken e savings a double that holds the value stored in your piggy bank In addition, the class should contain the following public member functions: e A default constructor o This constructor should set isBroken to false and savings to 0.0. e A parameterized constructor o This constructor should one parameter, the initial savings value for your piggy bank, as well as initialize isBroken to false. e A destructor o The destructor should check if the piggy bank is broken and output the message if it is broken: Poor Broken Pig! o This is an accessor function that should return you the amount stored in the savings variable o This function should accept a double and add that value to what is stored in the piggy\'s savings getSavings e depositMoney o But. You can\'t put money into a broken piggy bank. Negative money deposits are not allowed o Return a bool showing if the money was deposited or not smash o smash should change the broken bool so it indicates the piggy bank is broken, reduce the savings in the piggy bank to 0.0, and return the money in the piggy bank (before it was reduced to 0.0

Solution

#include <iostream>
#include <cstdlib>
#include \"PiggyBank.h\"
#include \"Coins.h\"
using namespace std;

//piggybank
PiggyBank::PiggyBank()
{
   noPennies = 0;
noNickls = 0;
noDims = 0;
noQrtrs = 0;
val = 0.0;
wght = 0.0;
}

void PiggyBank::depositMoney (Coins& c)
{

   if(wght < thna_labs)
   {
   }
   else
   {
       cout << \"Piggy bank\" << endl;
   }
}

void PiggyBank::withdraw (int amnt)
{
   if(amnt < val)
   {
       if (amnt > QUARTER)
       {
           noQrtrs = 0;
           wght = wght - Quarters::WEIGHT;
           val = val - Quarters::VALUE;
      
           if(amnt > DIME)
           {
               noDims = 0;
               wght = wght - Dimes::WEIGHT;
               val = val - Dimes::VALUE;

               if(amnt > NICKEL)
               {
                       noNickls = 0;
                       wght = wght - Nickels::WEIGHT;
                       val = val - Nickels::VALUE;
                      
                           if(amnt > PENNY)
                           {
                               noPennies = 0;
                               wght = wght - Pennies::WEIGHT;
                               val = val -   Pennies::VALUE;
                           }
                           else
                           {  
                               noPennies = noPennies -   amnt;
                           }
                   }
                   else
                   {
                       noNickls = noNickls -   amnt;
                   }
           }
           else
           {
               noDims = noDims -   amnt;
           }
       }  

       else
       {
           noQrtrs = noQrtrs -   amnt;
       }
   }
   else
   {
       cout << \"Piggy bank has insufficient funds to honor this request.\" << endl;
   }
}
double PiggyBank::getsavings()
{
   return val;
}
double PiggyBank::getWeight()
{
   return wght;
}
void PiggyBank::print()
{
   cout << \"Piggy bank now has:\" << endl;
   cout << noPennies << \" pennies, \" << noNickls << \" nickels, \"
       << noDims << \" dimes, and \" << noQrtrs << \" quarters.\" << endl;
   cout << \"The total worth is $\" << val << endl;
   cout << \"with the coins weighing \" << wght << endl;
}

The program can be tested using this file. http://pastebin.com/Gi4BaxWX Write a class called PiggyBank that contains the following private member variables: e i
The program can be tested using this file. http://pastebin.com/Gi4BaxWX Write a class called PiggyBank that contains the following private member variables: e i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site