•Женщины: BMR= 9,99 * вес (в кг) + 6,25 * рост (в см) - 4,92 * возраст (количество лет) -161
•Мужчины: BMR = 9,99 * вес (в кг) + 6,25 * рост (в см) - 4,92 * возраст (количество лет) + 5
C/C++
Можете составить код к этой формуле на языке С++. буду очень благодарен
#include <iostream>
#include <iomanip>
using namespace std;
class Human {
public:
Human() : weight(0), height(0), age(0) {}
virtual int kilocalories()const = 0;
protected:
int weight;
int height;
int age;
double calc()const {
return kw * weight + kh * height - ka * age;
}
private:
inline static const auto kw = 9.99;
inline static const auto kh = 6.25;
inline static const auto ka = 4.92;
};
class Man : public Human {
public:
Man(int weight, int height, int age) {
this->weight = weight;
this->height = height;
this->age = age;
}
int kilocalories()const override {
return static_cast<int>(calc() + x);
}
private:
static const auto x = 5;
};
class Woman : public Human {
public:
Woman(int weight, int height, int age) {
this->weight = weight;
this->height = height;
this->age = age;
}
int kilocalories()const override {
return static_cast<int>(calc() - x);
}
private:
static const auto x = 161;
};
int integer(const char* msg) {
cout << msg;
int value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
system("chcp 1251 > nul");
auto wm = integer("Вес мужчины, кг: ");
auto hm = integer("Рост мужчины, см: ");
auto am = integer("Возраст мужчины, полн. года: ");
Man man{ wm, hm, am };
auto xm = man.kilocalories();
cout << "Расчёт килокалорий для мужчины: " << xm << '\n';
auto ww = integer("Вес женщины, кг: ");
auto hw = integer("Рост женщины, см: ");
auto aw = integer("Возраст женщины, полн. года: ");
Woman woman{ ww, hw, aw };
auto xw = woman.kilocalories();
cout << "Расчёт килокалорий для женщины: " << xw << '\n';
system("pause > nul");
}
P.S. Формула Миффлина-Сан Жеора имеет несколько другой вид и коэффициенты: https://en.wikipedia.org/wiki/Basal_metabolic_rate#BMR_estimation_formulas
#include <iomanip>
using namespace std;
class Human {
public:
Human() : weight(0), height(0), age(0) {}
virtual int kilocalories()const = 0;
protected:
int weight;
int height;
int age;
double calc()const {
return kw * weight + kh * height - ka * age;
}
private:
inline static const auto kw = 9.99;
inline static const auto kh = 6.25;
inline static const auto ka = 4.92;
};
class Man : public Human {
public:
Man(int weight, int height, int age) {
this->weight = weight;
this->height = height;
this->age = age;
}
int kilocalories()const override {
return static_cast<int>(calc() + x);
}
private:
static const auto x = 5;
};
class Woman : public Human {
public:
Woman(int weight, int height, int age) {
this->weight = weight;
this->height = height;
this->age = age;
}
int kilocalories()const override {
return static_cast<int>(calc() - x);
}
private:
static const auto x = 161;
};
int integer(const char* msg) {
cout << msg;
int value;
cin >> value;
cin.ignore(cin.rdbuf()->in_avail());
return value;
}
int main() {
system("chcp 1251 > nul");
auto wm = integer("Вес мужчины, кг: ");
auto hm = integer("Рост мужчины, см: ");
auto am = integer("Возраст мужчины, полн. года: ");
Man man{ wm, hm, am };
auto xm = man.kilocalories();
cout << "Расчёт килокалорий для мужчины: " << xm << '\n';
auto ww = integer("Вес женщины, кг: ");
auto hw = integer("Рост женщины, см: ");
auto aw = integer("Возраст женщины, полн. года: ");
Woman woman{ ww, hw, aw };
auto xw = woman.kilocalories();
cout << "Расчёт килокалорий для женщины: " << xw << '\n';
system("pause > nul");
}
P.S. Формула Миффлина-Сан Жеора имеет несколько другой вид и коэффициенты: https://en.wikipedia.org/wiki/Basal_metabolic_rate#BMR_estimation_formulas
Похожие вопросы
- Можете составить код к этой формуле на языке С++
- Помогите составить код на C++ ,заранее спасибо)
- Как написать код для этого задания на языке С++
- Помогите пожалуйста не могу написать код
- В чём заключается ошибка? (не могу запустить код)
- Не могу написать код на с++ нужно решать через циклы но если у вас другие варианты пишите тоже желательно циклы
- Помогите пожалуйста не понимаю как делать. Буду очень благодарен
- Помогите пожалуйста. Буду очень благодарен
- Решите пожалуйста на С++. Буду очень благодарен за помощь.
- Написать код на языке си