I'm assigned to translate an excel spreadsheet into a C++ program.
The excel spreadsheet is a monthly budget report in which the user has to set the cost/income of each of the services he uses, let's say, water, gas, electricity, amazon.com, etc.
After that, the user is asked again to submit the percentage he pays to calculate what he pays individually for each service... I'm somewhat lost in that sentence.
In order to do this, I ask the user to enter the values using a do-while:
double value;
cin >> value;
do {
passToVector(value);
cin >> value;
} while(value != 0);
The passToVector function then stores the values on an expensesList vector:
void passToVector(double value){
vector<double> expensesList;
expensesList.push_back(value);
};
this is where I'm getting lost, the class should be able to receive those values in order to update them when needed. Here it is an example of what my class looks like:
class Expenses {
private:
double percentage = 0.00;
double mortgage = 0.00;
double electric = 0.00;
double gas = 0.00;
double water = 0.00;
public:
// Set percentage each person brings
void setPercentage(double per) { percentage = per; }
double getPercentage() const { return percentage / 100; }
// Calculate Total Expenses by Person
void calculatePersonExpenses() {
double result = mortgage * getPercentage();
double result2 = electric * getPercentage();
double result3 = gas * getPercentage();
double result4 = water * getPercentage();
cout << "Mortgage: $" << fixed << setprecision(2) << result << endl;
cout << "Electricity: $" << fixed << setprecision(2) << result2 << endl;
cout << "Gas(Home): $" << fixed << setprecision(2) << result3 << endl;
cout << "Water: $" << fixed << setprecision(2) << result4 << endl;
}
};
First, I'm assuming I need to create setters and getters for each of the services but if I do that...why would I need a vector function?; right now the only functions that I have are the ones for setPercentage. The task is just to store the values in a Vector of Class Objects data structure.
How can I update those values automatically when I need to?; Do I have to send the values to the class or is my approach totally wrong?
Hopefully I could explain myself.
Aucun commentaire:
Enregistrer un commentaire