Login Register


[C++] BMR Calculator filter_list
Author
Message
RE: [C++] BMR Calculator #9
Here's a way you can encapsulate it's functionality:
Code:
#include <iostream> #include <cstdint> enum GENDER { MALE, FEMALE }; struct BMR { public: BMR(GENDER gender) : sex(gender), years(0), weight_kg(0), height_cm(0), last_bmr(0) { } BMR(GENDER gender, float weight, float height, uint32_t age) : sex(gender) { weight_kg = weight; height_cm = height; years = age; last_bmr = 10 * weight + 6.25 * height - 5 * age + (gender == MALE ? 5 : -161); } uint32_t operator() () { return getBmr(); } uint32_t last_bmr; uint32_t years; float weight_kg; float height_cm; GENDER sex; private: uint32_t getBmr() { return (last_bmr = 10 * weight_kg + 6.25 * height_cm - 5 * years + (sex == MALE ? 5 : -161)); } }; int main() { BMR bmr(MALE, 100, 180, 27); std::cout << bmr() << std::endl; bmr.weight_kg = 80; std::cout << bmr() << std::endl; }

Disregarding the user input parsing, there's an example of its usage as well. If you wanted it to say "BMR: {value} or something like that, obviously you'd overload the << operator.
-- cxS

[ Haskell/.NET/C/C++ - Software Engineer ]

Reply





Messages In This Thread
[C++] BMR Calculator - by BreShiE - 02-02-2013, 06:33 PM
RE: [C++] BMR Calculator - by Kinanizer - 02-02-2013, 07:35 PM
RE: [C++] BMR Calculator - by KyleFYI - 02-02-2013, 07:37 PM
RE: [C++] BMR Calculator - by BreShiE - 02-02-2013, 09:26 PM
RE: [C++] BMR Calculator - by cxS - 02-25-2013, 12:08 PM
RE: [C++] BMR Calculator - by Dong - 09-14-2013, 12:40 AM
RE: [C++] BMR Calculator - by cxS - 09-14-2013, 12:43 AM
RE: [C++] BMR Calculator - by Dong - 09-14-2013, 12:46 AM
RE: [C++] BMR Calculator - by cxS - 12-10-2013, 02:10 AM
RE: [C++] BMR Calculator - by Oni - 12-10-2013, 05:50 AM
RE: [C++] BMR Calculator - by cxS - 12-10-2013, 05:53 AM
RE: [C++] BMR Calculator - by Oni - 12-10-2013, 05:56 AM



Users browsing this thread: 1 Guest(s)