Answered step by step
Verified Expert Solution
Link Copied!

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(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

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

b. What are its goals and objectives?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago