C/C++

Можете составить код к этой формуле на языке С++

•Женщины: BMR= 9,99 * вес (в кг) + 6,25 * рост (в см) - 4,92 * возраст (количество лет) -161
•Мужчины: BMR = 9,99 * вес (в кг) + 6,25 * рост (в см) - 4,92 * возраст (количество лет) + 5
#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");
}
Cафонов Владимир
Cафонов Владимир
95 905
Лучший ответ
BMR=9.99*weight+6.25*height-4.92*age+(sex==male? 5:-161);
Юрий «Ўрри»
Юрий «Ўрри»
71 801