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: 3881084 • 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 classes and function : ---------------------->>>>>>>>>>>>>>>

#include<iostream>
#include<math.h>

using namespace std;


class Money{
int dollor;
int cents;

public:
  Money(){
   dollor = 0;
   cents = 0;
  }
  Money(int d,int c){
   dollor = d;
   cents = c;
   if(d < 0){
    dollor = -dollor;
    cents = -abs(cents);
   }
  }
  Money(int d){
   dollor = d;
   cents = 0;
   if(d < 0){
    dollor = -dollor;
    cents = -cents;
   }
  }
  Money(double am){
   dollor = (int)am;
   cents = (int)(am-dollor);
   if(am < 0){
    dollor = -dollor;
    cents = -cents;
   }
  }
  
  int getPennies()const{
   return (dollor*100)+cents;
  }
  bool isNegative()const{
   if(dollor < 0){
    return true;
   }
   
   return false;
  }
  void add(const Money &m){
   cents = cents + m.cents;
   if(cents >= 100){
    cents = cents - 100;
    dollor = dollor + 1;
   }else if(cents <= -100){
    cents = cents + 100;
    dollor = dollor - 1;
   }
   
   dollor = dollor + m.dollor;
  }
  void subtract(const Money &m){
   cents = cents - m.cents;
   if(cents < 0){
    cents = cents + 100;
    dollor = dollor - 1;
   }
   if(dollor < 0){
    dollor = dollor - m.dollor;
   }else{
    dollor = dollor - m.dollor;
    if(dollor < 0){
     cents = -cents;
    }
   }
  }
  bool isEqual(const Money &m)const{
   if(dollor == m.dollor && cents == m.cents){
    return true;
   }
   
   return false;
  }
  
  void print(){
   if(dollor < 0){
    cout<<"(-$"<<abs(dollor)<<"."<<abs(cents)<<" )";
   }else{
    cout<<"$"<<dollor<<"."<<cents;
   }
  }
};

class Account{
string name;
double interestRate;
Money amount;

public:
  Account(){
   amount = Money();
   name = "";
   interestRate = 0.0;
  }
  Account(string n,double rate,Money m){
   amount = m;
   name = n;
   interestRate = rate;
  }
  Account(string n,double rate,double am){
   amount = Money(am);
   name = n;
   interestRate = rate;
  }
  
  string getName()const{
   return name;
  }
  double grtRate()const{
   return interestRate;
  }
  const Money getBalance()const{
   return amount;
  }
  void setName(string n){
   name = n;
  }
  void deposit(const Money &m){
   if(!m.isNegative()){
    amount.add(m);
   }
  }
  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()){
    if(amount.getPennies() >= m.getPennies()+500){
     amount.subtract(m);
     accrue();
    }
   }
   
   return amount;
  }
  const Money withdraw(int d,int c){
   Money m(d,c);
   if(!m.isNegative()){
    if(amount.getPennies() >= m.getPennies()+500){
     amount.subtract(m);
     accrue();
    }
   }
   return amount;
  }
  const Money withdraw(int d){
   Money m(d);
   if(!m.isNegative()){
    if(amount.getPennies() >= m.getPennies()+500){
     amount.subtract(m);
     accrue();
    }
   }
   return amount;
  }
  const Money withdraw(double d){
   Money m(d);
   if(!m.isNegative()){
    if(amount.getPennies() >= m.getPennies()+500){
     amount.subtract(m);
     accrue();
    }
   }
   return amount;
  }
  void accrue(){
   amount.add(Money((double)(amount.getPennies()*interestRate)/100));
  }
  
  void print(){
   amount.print();
  }
  
  void transferTo(Account &dest,Money &am){
   dest.deposit(am);
  }
};

const Account createAccount(){
system("cls");
string name;
double inter;
double amount;
cout<<"Let's set up Your Account : ";
cout<<"First what is the name of your Account ? ";
getline(cin,name);
cout<<" what is the interest rate of your "<<name<<" Account ? ";
cin>>inter;
cout<<" Finally ,what is the starting balance of your "<<name<<" Account ? ";
cin>>amount;

Account temp(name,inter,amount);

return temp;
}

int main(){

}

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