Answer to Question #194063 in C++ for Mpopo

Question #194063

Conventionally it was thought that 1 year in a dog's age equals 7 years in human age. A fairly new concept in aging studies claims that chemical modifications to a person's DNA over a lifetime essentially serve as an "epigenetic clock." This tracks an individual's "biological age". The “epigenetic clock” also applies to dogs. The most precise method to convert a dog’s age to human years uses the empirical equation that the researchers in aging studies discovered, which is 16 x ln(dog’s age) +31 = human age, (that is the natural logarithm of the dog’s real age, multiplied by 16, with 31 added to the total.) Write two overloaded functions to calculate a dog’s age in human years, one using the conventional method (simply multiplying the dog’s age in years by 7) and the other using the empirical equation proposed by the researchers in aging studies (16 x ln(dog’s age) + 31 = human age).


1
Expert's answer
2021-05-19T11:58:11-0400
#include <iostream>
#include <cmath>

struct MethodTag_Conventional {};
struct MethodTag_Empirical {};
const MethodTag_Conventional ConventionalMethod;
const MethodTag_Empirical    EmpiricalMethod;

double CalculateDogAge(double dogAge, MethodTag_Conventional)
{
    return dogAge * 7;
}

double CalculateDogAge(double dogAge, MethodTag_Empirical)
{
    return 16 * std::log(dogAge) + 31;
}

int main()
{
    double dogAge;
    std::cout << "Enter a dog's age: ";
    std::cin >> dogAge;

    if(!std::cin || dogAge < 0)
    {
        std::cout << "Bad input\n";
        return 1;
    }

    std::cout << "A dog's age in human years:\n";
    std::cout << " - using the conventional method: " << CalculateDogAge(dogAge, ConventionalMethod) << "\n";
    std::cout << " - using the empirical method:    " << CalculateDogAge(dogAge, EmpiricalMethod) << "\n";
   
    return 0;    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog