Question: / / PiggyBank.cpp #include #include PiggyBank.hpp / / Default constructor definition PiggyBank::PiggyBank ( ) : savings ( 0 . 0 ) , isSmashed (

// PiggyBank.cpp
#include
#include "PiggyBank.hpp"
// Default constructor definition
PiggyBank::PiggyBank() : savings(0.0), isSmashed(false){}
// Parameterized constructor definition
PiggyBank::PiggyBank(double initialAmount)
: savings(initialAmount), isSmashed(false)
{
}
// Destructor definition
PiggyBank::~PiggyBank()
{
// Add any necessary cleanup code here
}
// Member function to deposit money
void PiggyBank::deposit(double amount)
{
if (!isSmashed)
{
savings += amount;
}
else
{
std::cout << "A smashed piggy bank can't hold any money." << std::endl;
}
}
// Member function to withdraw money
void PiggyBank::withdraw(double amount)
{
if (!isSmashed && amount <= savings)
{
savings -= amount;
}
else if (isSmashed)
{
std::cout << "A smashed piggy bank can't hold any money." << std::endl;
}
else
{
std::cout << "Insufficient funds for withdrawal." << std::endl;
}
}
// Member function to get the current balance
double PiggyBank::getBalance() const
{
return savings;
}
// Member function to print savings
void PiggyBank::printSavings() const
{
if (isSmashed)
{
std::cout << "A smashed piggy bank can't hold any money." << std::endl;
}
else
{
std::cout << "Current savings: $"<< savings << std::endl;
}
}
// Function to check if the piggy bank is smashed
bool PiggyBank::isPiggyBankSmashed() const
{
return isSmashed;
}#include
#include "PiggyBank.hpp"
int main()
{
PiggyBank piggyBank;
piggyBank.printSavings()#ifndef PIGGYBANK_HPP
#define PIGGYBANK_HPP
class PiggyBank
{
private:
double savings; // Private member variable to store savings
bool isSmashed; // Private member variable to indicate if the piggy bank is
// smashed
public:
PiggyBank(); // Default constructor declaration
PiggyBank(double initialAmount); // Parameterized constructor declaration
~PiggyBank(); // Destructor declaration
void deposit(double amount); // Member function to deposit money
void withdraw(double amount); // Member function to withdraw money
double getBalance() const; // Member function to get the current balance
void printSavings() const; // Member function to print savings
// Function to check if the piggy bank is smashed
bool isPiggyBankSmashed() const;
};
#endif

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 Databases Questions!