Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PROBLEM 1 Write a function called approxDaysLived that will take a parameters: .

ID: 3735478 • Letter: P

Question

PROBLEM 1 Write a function called approxDaysLived that will take a parameters: .Birth month * Birth year The function should calculate and return the number of days a person born in the given month and year has lived to date. For simplicity, you can assume that all months have 30 days and that all years have 365 days. Also, you don't' need to be precise to the day of the month, only the month. The function will really return a close estimate. For example, somebody born on 12/1992 has lived 25 full years (from 1993 to 2017) and 1 month (Jan of 2018), giving the following result: (25*365) + 30 = 9155 days lived to date Write a main program where you will create three arrays, one for names (strings), one for birth months, and one for birth years. Store the following values in the arrays: Names: Ann, Jen, Tim, Tom, Mike, Ben, Mon, Bob, Brad, Zoe, Ted, Karl, Kim, Jim, Rob, Max. Birth months: 12, 5, 8, 2,7, 5, 8,6,8, 5, 2, 1,6,6, 10, 11. Birth years: 1992, 2007, 1970, 1982, 1981, 1975, 1978, 1966, 1995, 2001, 2004, 2015, 1960, 1916, 1986, 2010 The values stored in these arrays correspond to names, bi should loop through the arrays to calculate the number of days each user has lived to date (using the approxDa lines of output of your program should be: rth months, and birth years of users. Your program ysLived function) and it should display the name and result, one per line. For example, the first two Ann, you have lived approximately 9155 days. Jen, you have lived approximately 3890 days.

Explanation / Answer

PLEASE REFER BELOW CODE

#include<stdlib.h>
#include<stdio.h>

int approxDaysLived(int birth_month, int birth_year)
{
//Using formula given in problem
return ((2017 - birth_year) * 365 + (12 - birth_month + 1) * 30);
}
int main()
{
//array for Names
const char * Names[] = {"Ann","Jen","Tim","Tom","Mike","Ben","Mon","Bob","Brad","Zoe",
"Ted","Karl","Kim","Jim","Rob","Max"};

//array for Months
int birth_months[] = {12,5,8,2,7,5,8,6,8,5,2,1,6,6,10,11};
//Array for years
int birth_years[] = {1992,2007,1970,1982,1981,1975,1978,1966,1995,2001,2004,2015,1960,1916,
1986,2010};

int size_arr,i,days;

//size of the array
size_arr = sizeof(birth_months) / sizeof(int);

//Taking each entry of the array and passing to function approxDaysLived() and printing result
for(i = 0; i < size_arr; i++)
{
days = approxDaysLived(birth_months[i], birth_years[i]);
printf("%s, you have lived approximately %d days ", Names[i], days);
}

return 0;
}

PLEASE REFER BELOW OUTPUT

Ann, you have lived approximately 9155 days
Jen, you have lived approximately 3890 days
Tim, you have lived approximately 17305 days
Tom, you have lived approximately 13105 days
Mike, you have lived approximately 13320 days
Ben, you have lived approximately 15570 days
Mon, you have lived approximately 14385 days
Bob, you have lived approximately 18825 days
Brad, you have lived approximately 8180 days
Zoe, you have lived approximately 6080 days
Ted, you have lived approximately 5075 days
Karl, you have lived approximately 1090 days
Kim, you have lived approximately 21015 days
Jim, you have lived approximately 37075 days
Rob, you have lived approximately 11405 days
Max, you have lived approximately 2615 days

Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote