Question
Create this c++ program. Create to classes and name their type Account and Money. Follow the instruction listed below. Please read and implement instructions very carefully
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
media%2F30c%2F30cb3a62-343d-4b32-a153-d9
media%2F1c2%2F1c26f264-2f1d-4602-be10-47
media%2Ffef%2Ffef01f22-6a43-4fed-af50-dc
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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<<"\nLet's set up your Account \n";

cout<<"\nFirst Enter your account name ";

getline(cin,name);

cout<<"\nEnter interest rate for your "<<name<<" Account ?";

cin>>rate;

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

cin>>bal;

Account temp(name,rate,bal);

return temp;

}

Add a comment
Know the answer?
Add Answer to:
Create this c++ program. Create to classes and name their type Account and Money. Follow the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create two classes and name their types HotdogStand and Money • All relevant classes, functions, and...

    Create two classes and name their types HotdogStand and Money • All relevant classes, functions, and data shall be placed in a namespace called MyAwesomeBusiness • Negative amounts of Money shall be stored by making both the dollars and cents negative • The Money class shall have four (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 –...

  • C++ Redo Practice program 1 from chapter 11, but this time define the Money ADT class...

    C++ Redo Practice program 1 from chapter 11, but this time define the Money ADT class in separate files for the interface and implementation so that the implementation can be compiled separately from any application program. Submit three files: YourLastNameFirstNameInitialMoney.cpp - This file contains only the Money class implementation YourLastNameFirstNameInitialProj4.cpp - This file contains only the main function to use/test your money class YourLastNameFirstNameInitialMoney.h - This file contains the header file information.   Optional bonus (10%): Do some research on make...

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • CIT-111 Homework #5, Part A                                    Chapter 5, part 1

    CIT-111 Homework #5, Part A                                    Chapter 5, part 1 and alternate part 2 (page 341) A breakdown of the problem is as follows: Class name:                        Money Instance variables:           private, integer:                dollars, cents Constructor methods:    Money () – sets dollars and cents both to zero                                                 Money (int bucks) – sets dollars to bucks, cents to zero                                                 Money (int buck, int pennies) – sets dollars to bucks, cents to pennies Accessor methods:          getDollar () – returns value of dollars for...

  • implement a class called PiggyBank that will be used to represent a collection of coins. Functionality...

    implement a class called PiggyBank that will be used to represent a collection of coins. Functionality will be added to the class so that coins can be added to the bank and output operations can be performed. A driver program is provided to test the methods. class PiggyBank The PiggyBank class definition and symbolic constants should be placed at the top of the driver program source code file while the method implementation should be done after the closing curly brace...

  • In C++, create a class, called DynamicCharArray, which wraps around the standard char array and offers...

    In C++, create a class, called DynamicCharArray, which wraps around the standard char array and offers the following features: • Default constructor: initializes an internal array of 8 elements • Copy constructor: called implicitly when making a copy • int size(): returns the length of the array • void expand(int amount): increases the capacity of the array by the specified amount. It will need to create a new internal array and copy the elements over to accomplish this correctly, but...

  • Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp....

    Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...

  • Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...

    Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse: . a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which stores that salesman's position title . a float which stores their commission percentage, i.e., the percentage of sales they receive as a paycheck . a float which stores...

  • C++ Object-Oriented Programming - Program using structs, functions, and a little of overloaded functions. The finished...

    C++ Object-Oriented Programming - Program using structs, functions, and a little of overloaded functions. The finished program should look exactly like the part at the bottom in gray text. Create two structures and name the types Account and Money. The Money struct has two variables One represents how many dollars you have The other represents h ow many cents you have .The Account struct has three variables - A Money struct that will represent how much money is in the...

  • // Header code for stack // requesting to create source code using C++ #ifndef Stack_h #define...

    // Header code for stack // requesting to create source code using C++ #ifndef Stack_h #define Stack_h #include <stdio.h> #include <string> #include <iostream> using namespace std; class Stack { public: Stack(); ~Stack(); bool empty(); string top(); void push(const string &val); void pop(); void display(ostream &out); private: class Node { public: string word; Node *next; }; Node *tos; }; #endif Header file provided above. PLS create source code for functions declared in the header. If changes are need no make in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT