K
k3n3dy
Hello everybody, I would like to ask anybody to help me understand what
should be done exactly with this Problem. I have provided what I have
up to now, although it is not quite accurate.
Create a class to operate on the US currency. Call the new class Money.
All the data components in this class for dollars and cents are integer
variables (this is where I get confused and don't know how to actually
do the job). Include member functions and constructors to initialize
Money to 0 and to initialize it to fixed values. A member function
should display it in appropriate format. Include member functions that
permit data conversion in both directions:
- from real (float) value (4.5f US) to dollars/cents ( 4 dollar, 50
cents)
- from dollars/cents (4 dollar, 50 cents) to real (float) value (4.5f
US)
Here it is what I have managed to do up to now although I am not sure
if I am on the right way even. So if anybody could help me with this I
would really appreciate, it is interesting, but I've been trying for
quite some time and I just can't figure it out!
Thanks to anyone in advance!
#include <iostream>
using namespace std;
class Money {
private: int dollars; int cents;
public: Money() { dollars = 0; cents = 0; }
Money (int dol, int cnt) { dollars = dol; cents = cnt; }
Money (float fl_dollars) // one-arg constructor
{
cout << "fl_dollars value is: " << fl_dollars << endl;
float flt_dollars = fl_dollars;
dollars = int(flt_dollars);
cout << "fl_dollars value is: " << flt_dollars << endl << " And
dollars are: " << levs << endl;
float cents_part = float(fl_dollars - dollars);
cents = cents_part;
cout << "Cents after conversion: " << cents << endl;
cout << "cents value is: " << cents<< endl;
cout << "\n 1-arg Constructor activated\n";
}
void ShowMoney()
{
cout <<"\nDistObject= " << dollars << " dollars" <<" and "<< cents
<< " cents" << endl << endl;
}
};
void main ()
{
// Conversion from Basic to User Defined >>> one-arg Constructor
Money d3 = 10.89;
d3.ShowMoney();
}
should be done exactly with this Problem. I have provided what I have
up to now, although it is not quite accurate.
Create a class to operate on the US currency. Call the new class Money.
All the data components in this class for dollars and cents are integer
variables (this is where I get confused and don't know how to actually
do the job). Include member functions and constructors to initialize
Money to 0 and to initialize it to fixed values. A member function
should display it in appropriate format. Include member functions that
permit data conversion in both directions:
- from real (float) value (4.5f US) to dollars/cents ( 4 dollar, 50
cents)
- from dollars/cents (4 dollar, 50 cents) to real (float) value (4.5f
US)
Here it is what I have managed to do up to now although I am not sure
if I am on the right way even. So if anybody could help me with this I
would really appreciate, it is interesting, but I've been trying for
quite some time and I just can't figure it out!
Thanks to anyone in advance!
#include <iostream>
using namespace std;
class Money {
private: int dollars; int cents;
public: Money() { dollars = 0; cents = 0; }
Money (int dol, int cnt) { dollars = dol; cents = cnt; }
Money (float fl_dollars) // one-arg constructor
{
cout << "fl_dollars value is: " << fl_dollars << endl;
float flt_dollars = fl_dollars;
dollars = int(flt_dollars);
cout << "fl_dollars value is: " << flt_dollars << endl << " And
dollars are: " << levs << endl;
float cents_part = float(fl_dollars - dollars);
cents = cents_part;
cout << "Cents after conversion: " << cents << endl;
cout << "cents value is: " << cents<< endl;
cout << "\n 1-arg Constructor activated\n";
}
void ShowMoney()
{
cout <<"\nDistObject= " << dollars << " dollars" <<" and "<< cents
<< " cents" << endl << endl;
}
};
void main ()
{
// Conversion from Basic to User Defined >>> one-arg Constructor
Money d3 = 10.89;
d3.ShowMoney();
}