Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write your code where prompted to do so, and the main) and testing func

ID: 3903007 • Letter: Y

Question

You will write your code where prompted to do so, and the main) and testing functions are not to be altered . Create two classes and name their types Account and Money Use initialization sections where possible for all constructors With the sole exceptions being the print) functions, no other functions should be printing to the screen unless an error message must be displayed Money Class Requirements -Negative amounts of Money shall be stored by making both the dollars and cents negative - The Money class shall have 4 constructors A default constructor that initializes your Money object to $0.00 + A constructor that takes two integers, the first for the dollars and the second for the cents +A constructor that takes one integer, for a dollar amount and no cents + A constructor that takes one double, and can assign dollars and cents accordingy - bool isNegative) const Returns true if your amount of money is negative - void add(const Money 8m) The sum shall be stored in the calling object - void subtract const Money 8m) The difference shall be stored in the calling object - bool isEqual const Money &n;) const - void print) const This function prints the amount of Money you have, it must print a $, and always show two decimal places Negative amounts of Money shall be represented in the following manner: (Sx xx) - The Money class shall have two private data members AND one helper function *An integer that represents how many dollars you have An integer that represents how many cents you have. + A function getPennies0 that returns the equivalent amount of pennies for the calling object Account Class Requirements - The Account class shall have 4 constructors + A default constructor that initializes your Account object with a name Savings, an interest rate of 0.00%, and an initial balance of S0.00 A constructor that takes a string, double, and Money object to initialize your Accounts name, interest rate, and balance respectively * A constructor that takes a string, double, and an integer that represents your initial balance (a clean dollar amount) 4 A constructor that takes a string, double, and a double that represents your initial balance -std::string getName) const - double getRate) const -const Money getBalance) const - void setNane(std::string newNane) - void deposit(const Money &m;) - void deposit int d, int c) - void deposit int d)

Explanation / Answer

**************************************

Money.h

#include <iostream>

using namespace std;

class Money {

private:

                int dollars, cents;

                int getPennies();

public:

                Money();

                Money(int d, int c);

                Money(int d);

                Money(double amount);

                bool isNegative() const;

                void add(const Money &m);

                void subtract(const Money &m);

                bool isEqual(const Money &m) const;

                void print() const;

};

*********************************************

Money.cpp

#include "Money.h"

#include <iomanip>

Money::Money() {

                dollars = 0.00;

                cents = 0.00;

}

Money::Money(int d, int c) {

                dollars = d;

                cents = c;

}

Money::Money(int d) {

                dollars = d;

}

Money::Money(double amount) {

                dollars = amount;

                cents = amount;

}

bool Money::isNegative() const {

                if(dollars < 0 || cents < 0)

                                return true;

                return false;

}

void Money::add(const Money &m) {

                dollars += m.dollars;

                cents += m.cents;

}

void Money::subtract(const Money &m) {

                dollars -= m.dollars;

                cents -= m.cents;

}

bool Money::isEqual(const Money &m) const {

                if(dollars == m.dollars && cents == m.cents)

                                return true;

                return false;

}

void Money::print() const {

                if(dollars < 0) {

                                cout << endl << "Dollars : $X.XX";

                } else {

                                cout << endl << "Dollars : $" << setprecision(2) << fixed << dollars;

                }

                if(cents < 0) {

                                cout << endl << "Cents : ¢X.XX";

                } else {

                                cout << endl << "Cents : ¢" << setprecision(2) << fixed << cents;

                }

}

*******************************************

Account.h

#include "Money.h"

#include <iostream>

using namespace std;

class Account {

private:

                Money money;

                double rate;

                string account_name;

public:

                Account();

                Account(string a_name, double i_rate, Money &m);

                Account(string a_name, double i_rate, int amount);

                Account(string a_name, double i_rate, double amount);

                string getName() const;

                double getRate() const;

                const Money getBalance() const;

                void setName(string newName);

                void deposit(const Money &m);

                void deposit(int d, int c);

                void deposit(int d);

                void deposit(double d);

                const Money withdraw(const Money &m);

                const Money withdraw(int d, int c);

                const Money withdraw(int d);

                const Money withdraw(double d);

                void accrue();

                void print() const;

                void TransferTo(Account &dest, const Money &amount);

};

****************************************************

Account.cpp

#include "Account.h"

#include <iomanip>

Account::Account() {

                account_name = "Savings";

                rate = 0.00;

                money = Money();

}

Account::Account(string a_name, double i_rate, Money &m) {

                account_name = a_name;

                rate = i_rate;

                money = m;

}

Account::Account(string a_name, double i_rate, int amount) {

                account_name = a_name;

                rate = i_rate;

                money = Money(amount);

}

Account::Account(string a_name, double i_rate, double amount) {

                account_name = a_name;

                rate = i_rate;

                money = Money(amount);

}

string Account::getName() const {

                return account_name;

}

double Account::getRate() const {

                return rate;

}

const Money Account::getBalance() const {

                return money;

}

void Account::setName(string newName) {

                account_name = newName;

}

void Account::deposit(const Money &m) {

                money.add(m);

}

void Account::deposit(int d, int c) {

                money.add(Money(d, c));

}

void Account::deposit(int d) {

                money.add(Money(d));

}

void Account::deposit(double d) {

                money.add(Money(d));

}

const Money Account::withdraw(const Money &m) {

                money.subtract(m);

}

const Money Account::withdraw(int d, int c) {

                money.subtract(Money(d, c));

}

const Money Account::withdraw(int d) {

                money.subtract(Money(d));

}

const Money Account::withdraw(double d) {

                money.subtract(Money(d));

}

void Account::accrue() {

}

void Account::print() const {

                money.print();

}

void Account::TransferTo(Account &dest, const Money &amount) {

                dest.deposit(amount);

                withdraw(amount);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote