Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / 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 isSmashedfalse
Parameterized constructor definition
PiggyBank::PiggyBankdouble initialAmount
: savingsinitialAmount isSmashedfalse
Destructor definition
PiggyBank::~PiggyBank
Add any necessary cleanup code here
Member function to deposit money
void PiggyBank::depositdouble 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::withdrawdouble 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 PIGGYBANKHPP
#define PIGGYBANKHPP
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
PiggyBankdouble initialAmount; Parameterized constructor declaration
~PiggyBank; Destructor declaration
void depositdouble amount; Member function to deposit money
void withdrawdouble 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started