Login Register


[C++] BMR Calculator filter_list
Author
Message
[C++] BMR Calculator #1
After taking a look at one of my college systems, it described a system and formulas to create a BMR (Basal Metobolic Rate) calculator, and I misread the assignment thinking I had to code the system, which I didn't. But I coded the system anyway, so I though I'd share it with you here! I've tested it for both male and female, several heights and weight, and as far as I can tell it runs perfectly! (P.S if anyone knows how to add an icon to console applications, please let me know)

The Code:
Spoiler:
[Image: cOkhny1.png]



The Program:
http://www.sendspace.com/file/69m58e

Let me know what you think! Smile
[Image: F4Z9Dqw.png]

Reply

RE: [C++] BMR Calculator #2
I think you deserve the Coder award. Great share man.

Reply

RE: [C++] BMR Calculator #3
Nice of you to post the source Tongue

Reply

RE: [C++] BMR Calculator #4
Thanks guys. I'm picking up C++ rather quickly actually. I'm so glad I started learning it in college.
[Image: F4Z9Dqw.png]

Reply

RE: [C++] BMR Calculator #5
There's just about twice as much code here from what is really necessary.
-- cxS

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

Reply

RE: [C++] BMR Calculator #6
Not bad, but there is a snippet of code in there that is repeated twice for no real reason. Hopefully by now you've learned to optimize a program such as this. Nonetheless, nice!

Reply

RE: [C++] BMR Calculator #7
(09-14-2013, 12:40 AM)Aristotle Wrote: Not bad, but there is a snippet of code in there that is repeated twice for no real reason. Hopefully by now you've learned to optimize a program such as this. Nonetheless, nice!

lol, I pointed this out months ago.
-- cxS

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

Reply

RE: [C++] BMR Calculator #8
(09-14-2013, 12:43 AM)cxS Wrote: lol, I pointed this out months ago.

My mistake, I thought the thread had said it had 0 replies! Next time, I'll be sure to check.

Reply

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

RE: [C++] BMR Calculator #10
Code-critique, almost a year late. Tongue
[Image: 7ajmN5P.jpg]

Telegram: Oni_SL (Link)

Reply







Users browsing this thread: