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

Money Class Requirements - Negative amounts of Money shall be stored by making b

ID: 3881082 • Letter: M

Question

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 an clean dollar amount A constructor that takes one double, and can assign dollars and cents accordingly - int getPennies const - bool isNegative) const - void add (const Money &m;) - void subtract (const Money &m;) - bool isEqual (const Money &m;) const Returns the equivalent amount of money as a number of pennies Returns true if your amount of money is negative The sum shall be stored in the calling object The difference shall be stored in the calling object -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

Explanation / Answer

here is your program : --------------------->>>>>>>>>>>>>

#include<iostream>

using namespace std;

class Money{

int dollor;

int cents;

public:

Money(){

dollor = 0;

cents = 0;

}

Money(int d,int c){

dollor = d;

cents = c;

}

Money(double d){

dollor = (int)d;

cents = (int)(d-dollor);

}

Money(int d){

dollor = d;

cents = 0;

}

int getPennies(){

return (100*dollor)+cents;

}

bool isNegative(){

if(dollor < 0){

return true;

}

return false;

}

void add(const Money &m){

cents = cents + m.cents;

if(cents > 100){

cents = cents - 100;

dollor++;

}

dollor = dollor + m.dollor;

}

void subtract(const Money &m){

cents = cents - m.cents;

if(cents < 0){

cents = cents + 100;

dollor--;

}

dollor = dollor - m.dollor;

}

bool isEqual(const Money &m){

if(dollor == m.dollor && cents == m.cents){

return true;

}

return false;

}

void print(){

if(dollor < 0){

cout<<"(-$"<<dollor<<"."<<cents<<")";

}

else{

cout<<"$"<<dollor<<"."<<cents;

}

}

};

class Account

{

string name;

double rate;

Money amount;

public:

Account(){

name = "";

rate = 0;

amount = Money();

}

Account(string n,double r,Money m){

name = n;

rate = r;

amount = Money(m);

}

Account(string n,double r,int d){

name = n;

rate = r;

amount = Money(d);

}

Account(string n,double r,double d){

name = n;

rate = r;

amount = Money(d);

}

string getName(){

return name;

}

double getRate(){

return rate;

}

const Money getBalance(){

return amount;

}

void setName(string n){

name = n;

}

void deposit(const Money &m){

if(!m.isNegative()){

amount.add(m);

accrue();

}

}

void deposit(int d,int c){

Money m(d,c);

if(!m.isNegative()){

amount.add(m);

accrue();

}

}

void deposit(int d){

Money m(d);

if(!m.isNegative()){

amount.add(m);

accrue();

}

}

void deposit(double d){

Money m(d);

if(!m.isNegative()){

amount.add(m);

accrue();

}

}

const Money withdraw(const Money &m){

if(!m.isNegative()){

amount.subtract(m);

accrue();

}

return amount;

}

const Money withdraw(int d,int c){

Money m(d,c);

if(!m.isNegative()){

amount.subtract(m);

accrue();

}

return amount;

}

const Money withdraw(int d){

Money m(d);

if(!m.isNegative()){

amount.subtract(m);

accrue();

}

return amount;

}

const Money withdraw(double d){

Money m(d);

if(!m.isNegative()){

amount.subtract(m);

accrue();

}

return amount;

}

void accrue(){

double d = amount.getPennies()*rate;

deposit(d);

}

void print(){

amount.print();

}

};

const Account createAccount(){

system("cls");

string name;

double rate;

double bal;

cout<<" Let's set up your Account ";

cout<<" First Enter your account name ";

getline(cin,name);

cout<<" Enter interest rate for your "<<name<<" Account ?";

cin>>rate;

cout<<" Finally enter the starting balance for your "<<name<<" Account?";

cin>>bal;

Account temp(name,rate,bal);

return temp;

}

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