Prblem: Implement a base class Account and derived classes Savings and Checking. In the base class,supply member functions deposit(), withdraw(), and print() which prints out the ownerand balance. Create constructors that take a string (for the owner's name) and a double for the initialbalance. All methods should return void.
I also need to implement a daily_interest()but i didnt do it
My code did compile right, but it did not give the right output
#include <iostream>
#include <string>
using namespace std;
const int DAYS_PER_MONTH = 30;
///////////// Account CLASS //////////////////////////
class Account
{
public:
Account(double amount);
void deposit(double amount);
void withdraw(double amount);
void print();
void daily_interest();
//private:
double balance;
};
Account::Account(double amount)
{
balance = amount;
}
void Account::deposit(double amount)
{
balance += amount;
}
void Account::withdraw(double amount)
{
balance -= amount;
}
void Account::print()
{
cout << balance;
}
void Account::daily_interest()
{}
///////////// Savings CLASS //////////////////////////
class Savings : public Account
{
public:
Savings(double balance);
double get_balance() const;
private:
double s_balance;
};
Savings::Savings(double balance)
: Account(balance)
{
s_balance = balance;
}
double Savings::get_balance() const
{
return s_balance;
}
///////////// Checking CLASS //////////////////////////
class Checking : public Account
{
public:
Checking(double balance);
double get_balance() const;
private:
double c_balance;
};
Checking::Checking(double balance)
: Account(balance)
{
c_balance = balance;
}
double Checking::get_balance() const
{
return c_balance;
}
///////////////////////////////////////////////////////
int main()
{
Checking c = Checking(1000.0);
Savings s = Savings(1000.0);
for (int i = 1; i <= DAYS_PER_MONTH; i++)
{
c.deposit(i * 5);
c.withdraw(i * 2);
s.deposit(i * 5);
s.withdraw(i * 2);
//c.daily_interest();
//s.daily_interest();
if (i % 10 == 0)
{
cout << "day " << i << "\n";
cout << "Checking balance: " << c.get_balance() << "\n";
cout << "Savings balance: " << s.get_balance() << "\n";
}
}
return 0;
}