CSE102 HW01 solved




Part 1 50pts
In this part you will write a C code to ask a user his/her birth date as day, month and year respectively and you will
calculate how many days left to his/her birthday and how old is he/she and then you will print this information on the
Your code should include two functions, one for calculating the number of days to the birthday and the other to
calculate the age.
DO NOT use condition and conditional operators.
Take A Year = 365 Days
A Month = 30 Days
int theAge(int day,int month, int year, int today,int this_month, int this_year );
int daysLeft(int day,int month, int today,int this_month);
Sample Usage
int age = theAge(day, month, year,today,this_month, this_year)
int days = daysLeft(day, month, today, this_month)
(day : 4, month : 7,year : 1984, today : 22 ,this_month : 2, this_year: 2017)
Return Value
Days left to birthday, Age of the user
(days : 132, age : 32)
Part 2 50pts
Write a C code to calculate the age of a tree. It will contain two functions, the first function will take the circumference
of tree as input and returns the diameter of tree as output. The second function will take the diameter that calculated
by the first function and the growth factor of tree species as inputs, calculate the age of tree according to the formula :
Age of Tree = Diameter of Tree x Growth Factor and returns the age of tree as output. (Take Pi= 3.14)
Growth factors of some species as following :
American Elm = 4 ; Austrian Pine = 4.5 ; Black Cherry = 5 ; Scotch Pine = 3.5
float diameter(float circumference);
float ageOfTree(float diameter , float growth_factor);
Sample Usage
float dia = diameter(circumference)
float age = ageOfTree(diameter, pine)
( circumference : 60.5, pine : 4.5 )
Return Value
Diameter of the tree , Age of tree
( dia : 19.27, age : 86.70)