Basically, say that I have the following code snippet...
However, I do not want to do the "x.wage * x.hours" calculation and "cout << x earned: " << xEarned << endl;" shit over and over, so it would look something like this...
Now, I know that the above code won't work whatsoever, I'm not an idiot. That's just to give you guys an idea of what I'm looking for. Is this possible to do with just Classes and Objects? Or would I have to add a Constructor or Array or something?
What I'm looking for is something like this..
1. Create a Class "Money"
2. Create Objects in Class "Money" [A, B, C, D, E] with values "wage" and "hours".
3. Calculate ALL Object's "MoneyAmount" in one line with "wage * hours"
4. cout code with "[x] earned: x"
Code:
#include <iostream>
using namespace std;
class Money {
public:
double hours;
double wage;
int main()
Money A;
Money B;
Money C;
Money D;
Money E;
double MoneyEarned = 0.0;
A.hours = 43.6;
A.wage = 20.50;
B.hours = 38.4;
B.wage = 24.00;
C.hours = 46.9;
C.wage = 20.50;
D.hours = 44.2;
D.wage = 22.0;
E.hours = 39.5;
E.wage = 50.00;
AEarned = A.wage * A.hours
BEarned = B.wage * B.hours
CEarned = C.wage * C.hours
DEarned = D.wage * D.hours
EEarned = E.wage * E.hours
cout << "A earned: " << AEarned << endl;
etc. etc. etc.
};
However, I do not want to do the "x.wage * x.hours" calculation and "cout << x earned: " << xEarned << endl;" shit over and over, so it would look something like this...
Code:
#include <iostream>
using namespace std;
class Money {
public:
double hours;
double wage;
};
int main() {
Money A;
Money B;
Money C;
Money D;
Money E;
double MoneyAmount = 0.0;
A.hours = 43.6;
A.wage = 20.50;
B.hours = 38.4;
B.wage = 24.00;
C.hours = 46.9;
C.wage = 20.50;
D.hours = 44.2;
D.wage = 22.00;
E.hours = 39.5;
E.wage = 50.00;
MoneyAmount = Money(wage) * Money(hours);
cout << "[x] earned: " << MoneyAmount << endl;
return 0;
}
Now, I know that the above code won't work whatsoever, I'm not an idiot. That's just to give you guys an idea of what I'm looking for. Is this possible to do with just Classes and Objects? Or would I have to add a Constructor or Array or something?
What I'm looking for is something like this..
1. Create a Class "Money"
2. Create Objects in Class "Money" [A, B, C, D, E] with values "wage" and "hours".
3. Calculate ALL Object's "MoneyAmount" in one line with "wage * hours"
4. cout code with "[x] earned: x"