c++ PROBLEM 1 A dog life span can be estimated based on its weight according to
ID: 3717097 • Letter: C
Question
c++
PROBLEM 1 A dog life span can be estimated based on its weight according to the following rules A dog that weights up to 3 Kg is estimated to live 17 years. Dog bve A dog that weights between 4 and 7 Kg is estimated to live 14 years. >??G&?? A dog that weights more than 7 Kg is estimated to live 11 years. e 3 Jut IMg reurn Write a function called EstimateDoglifeSpan that will take as input the Dog Weight in pounds and it will calculate the dog weight in Kg and return the estimated years that the dog will ive. Note: A pound equals 0.453592 Kg. Write a main program where you will create two arrays, one for dog names (strings Store the following values in the arrays: ), and one for dog weights :Max, Bolt, Cooper, Buddy, Rocky, Bear, Duke, Tucker, Bella, Luna, Lola, Sadie, Bailey, Abby. hts (pounds): 12, 3, 2, 7, 18, 16, 11, 15, 22, 13, 6, 6, 10, 17 Dog Weig stored in these arrays correspond to names and weights of some dogs. Your program should loop the arrays The Vato the arrays to calculate the estimated life span of the dogs (using the EstimateDoglifeSpan function) and hould display the name and result, one per line. For example, the first two lines of output of your program through should be: Max weighs 12 pounds. It will get to live up to 14 years. Bolt weighs 3 pounds. It will get to live up to 17 years.Explanation / Answer
Please find the C++ code attached for the above program . I have used two different arrays for name and weight as asked .
#include <iostream>
using namespace std;
int t;
int EstimateDogLifeSpan( int m)
{
float k=0.453592*m;
if(k<=3)
t=17;
else
{
if(k>=4 and k<=7)
t=14;
else
t=11;
}
return t;
}
int main() {
// your code goes here
char name[14][20]={"Max","Bolt","Cooper","Buddy","Rocky","Bear","Duke","Tucker","Bella","Luna","Lola","Saidey","Bailey","Abby"};
int weight[]={12,3,2,7,18,16,11,15,22,13,6,6,10,17};
int i;
for(i=0;i<14;i++)
{
int g=EstimateDogLifeSpan(weight[i]);
cout<<name[i]<<" weighs "<< weight[i]<<" pounds."<< " It will get to live upto "<< g<<" years."<<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.