Okay where should I begin.... I have this rather asinine program that as of right now only asks the user what quantity of dollars and particular coins they have then just spits out what was imputed. I need to add in a 'child' class that does all the following

-Add a new private or protected data member for a cents. This should be a floating point variable.

-Add the appropriate accessor and mutator methods to the class

-It needs to have its own no argument constructor that calls the base class constructor and then initializes cents to 0.

-The new class should override the inputInfo method of Money. This new method will use the base class method to retrieve the data from the user as dollars, quarters, dimes, nickels and pennies. After the data has been retrieved the method should convert and store the value of the dollars, quarters, dimes, nickels and pennies as a floating point value in cents.

-The new class should override the outputInfo method so that in additional to calling the base classes method, it prints an additional line showing the amount of money as a decimal value.

I attached a UML (i think)

And heres the code:

#include <iostream>
using namespace std;

class Money
{
private:
// Private data members
int dollars, quarters, dimes, nickels, pennies;
public:
// Default constructor
Money() : dollars(0),quarters(0),dimes(0),nickels(0),pennies(0)
{}
// User input/output methods
void inputInfo();
void outputInfo();
// Accessor methods
int getDollars() { return(dollars); }
int getQuarters() { return(quarters); }
int getDimes() { return(dimes); }
int getNickels() { return(nickels); }
int getPennies() { return(pennies); }
// Mutator methods
void setDollars(int data) { dollars = data; }
void setQuarters(int data) { quarters = data; }
void setDimes(int data) { dimes = data; }
void setNickels(int data) { nickels = data; }
void setPennies(int data) { pennies = data; }
};
int main()
{
Money money;
money.inputInfo ();
money.outputInfo ();
return 0;
}
void Money::outputInfo()
{
cout << "\n\nYou have " << getDollars() << " dollars, "
<< getQuarters() << " quarters, "
<< getDimes() << " dimes, " << getNickels()
<< " nickels and " << getPennies()
<< " pennies.\n";
}
void Money::inputInfo()
{
int input;
cout << "Enter the number of dollars you have (whole numbers only): ";
cin >> input;
setDollars(input);
cout << "Enter the number of quarters you have (whole numbers only): ";
cin >> input;
setQuarters(input);
cout << "Enter the number of dimes you have (whole numbers only): ";
cin >> input;
setDimes(input);
cout << "Enter the number of nickels you have (whole numbers only): ";
cin >> input;
setNickels(input);
cout << "Enter the number of pennies you have (whole numbers only): ";
cin >> input;
setPennies(input);
}

Now what I need is some help as to how to implement this new derived class into my code.

And please try to keep any explanations simple I am rather "challenged" in this field.

Attachments UML.png 61.09 KB

You will need to post a version of the class to be created(to prove that you are actually showing progress) then we can work on it together, with you learning more and we gaining more experience!!

"Show me your code and I will tell you who you are.."-Tkud

yeah i understand that but if i knew how to write a class then i really wouldent have any reason to come here. and I can't learn if im never taught.

This article has been dead for over six months. Start a new discussion instead.