1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//prototypes
class FoodItem
{
public:
double points, protein, carbs, fat, fiber;
double totPoints, totProtein, totCarbs, totFat, totFiber;
string foodName;
void CalculatePoints(string foodName, double protein, double carbs, double fat, double fiber)
{
double points = (protein / 10.9375) + (carbs / 9.2105) + (fat / 3.8889) - (fiber / 12.5);
cout << setprecision(2) << fixed << "Total points for " << foodName << " is " << points << endl;
totPoints += points;
totProtein += protein;
totCarbs += carbs;
totFat += fat;
totFiber += fiber;
};
void setInitialValue()
{
foodName = "abc";
totPoints = 0.0;
totProtein = 0.0;
totCarbs = 0.0;
totFat = 0.0;
totFiber = 0.0;
};
void printTotal()
{
cout << "\nTotal points for all food items are " << points << endl;
}
};
int main()
{
FoodItem myFood;
myFood.setInitialValue(); //Clear initial total value
double points = 0.0,
protein = 0.0,
carbs = 0.0,
fiber = 0.0,
fat = 0.0;
string foodName;
do
{
cout << "Enter the following info to convert to points:\n";
cout << "Enter Food Item" << endl;
cin >> foodName;
cout << "Enter protein: \n";
cin >> protein;
cout << "Enter carbs: \n";
cin >> carbs;
cout << "Enter fat: \n";
cin >> fat;
cout << "Enter fiber: \n";
cin >> fiber;
myFood.CalculatePoints(foodName, protein, carbs, fat, fiber);
}while (foodName != "\0" || foodName != "");
myFood.printTotal();
system("pause");
return 0;
};
|