Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
The medical examiner arrives at the crime scene and takes the temperature, T_i, of the deceased. An hour later the medical examiner again takes the temperature T_f of the deceased. The examiner notices that the thermostat in the room is set for a constant T_a temperature. From this data and Newton's Law of Cooling, design, write, compile, run and debug a program that takes in (use cin) temperatures T_i, T_f and T_a in degrees Fahrenheit from the user and displays those temperatures, constant k, and the approximate length of time t_h in hours between the death of the individual and the arrival of the examiner (assume the individual's body temperature was T_d = 98.6 degrees Fahrenheit at the time of death).

Step 1: Determine constant k from: k = (-log((T_f - T_a)/(T_i - T_a)))/1.0
Step 2: Determine t_h in hours from: t_h = (-log((T_i - T_a)/(T_d - T_a)))/k
Step 3: Print out the value of t_h in hours.

[EDIT - OP code from comment]
okay, so I did my best but the answer it gives me don't seem like a right answer..... Im not sure if I did something wrong

C++
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{

double T_i,T_f,T_a,k,T_h;
const double T_d = 98.6;

cout<<	 "Determine length of time t_h in hours between the death of the individual and the arrival of the examiner "<<endl<<endl;

cout<< "Enter the value of T_i: ";
cin>> T_i;
cout<< "Enter the value of T_f: ";
cin>> T_f;
cout<< "Enter the value of T_a: ";
cin>> T_a;
k = (-log((T_f - T_a)/(T_i - T_a)))/1.0;
T_h = (-log((T_i - T_a)/(T_d - T_a)))/k;

cout<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(4)
<< "time between the death of the individual and the arrival of the examiner:"<<T_h<< "hours"<<endl;


return 0;


}
Posted
Updated 1-Feb-16 3:45am
v2
Comments
CHill60 31-Jan-16 16:17pm    
Of course, if you react with nothing but a down vote then that will be at least one less member prepared to help further down the line. Apologies - it appears it wasn't you. However please see the following questions...
What have you actually tried, where are you stuck, what went wrong?
Andreas Gieriet 31-Jan-16 17:00pm    
What's the problem exactly?
You read in three values (cin >> t_f, etc.), calculate from these values the value of k (#include <cmath>, use the proper "log" function, etc.), then the value of t_h, and finally print t_h (cout << t_h, etc.).
So, again: what's the problem? Choose the right types? choose the right logarithm? C++ as such (includes, namespaces, main function, ...)?
Do you have test data to check against?
Cheers
Andi
[no name] 1-Feb-16 10:10am    
k = (-log((T_f - T_a)/(T_i - T_a)))/1.0;

Is " / 1.0" (divide by one) a typo or is it really not necessary?
[ok, seems to be the Delta t]

Have look here: Newton's Law of Cooling -- EndMemo[^]
Stefan_Lang 5-Feb-16 5:13am    
Unfortunately the 'k' value calculated by the formula above uses hours and Fahrenheit rather than seconds and Celsius. Therefore you can't use it with the calculator on that site to cross-check a given result.

P.S.: the '/1.0' part of the formula really reads '/1.0h' because 1h is the time difference between the measurements. To convert this to metric, you'd need to divide by 3600s instead.
[no name] 5-Feb-16 7:08am    
Thank you for Feedback. Fahrenheit instead of Celsius: That was also my first thought. But if you have a closer look to the formula you will recognize, that the formula works for both :)

1 solution

This is homework.
We don't do your homework for you.
Why? Because it doesn't help you.

Give it a try.
Follow your course notes.

When you get stuck, then post a question that includes the code you have tried and details of where you are stuck.

We are more than happy to help ... but only if you try
 
Share this answer
 
Comments
Dave Kreskowiak 31-Jan-16 16:30pm    
Whoever hit you with a 1 vote is someone who's been around for quite a while. They hit you as hard as I can.
CHill60 31-Jan-16 16:37pm    
Cheers!
I've looked again and apologised to the OP.
Thank you for the balancing vote.
I'm more concerned about whoever it is that is randomly downvoting (again!) ... I'm happy to be corrected when I'm wrong, and appreciate corrective comments, but there is someone out there being silly at the moment
Andreas Gieriet 31-Jan-16 16:55pm    
My 5!
Cheers
Andi
Member 12298677 31-Jan-16 20:22pm    
okay, so I did my best but the answer it gives me don't seem like a right answer..... Im not sure if I did something wrong
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main()
{

double T_i,T_f,T_a,k,T_h;
const double T_d = 98.6;





cout<< "Determine length of time t_h in hours between the death of the individual and the arrival of the examiner "<<endl<<endl;




cout<< "Enter the value of T_i: ";
cin>> T_i;
cout<< "Enter the value of T_f: ";
cin>> T_f;
cout<< "Enter the value of T_a: ";
cin>> T_a;
k = (-log((T_f - T_a)/(T_i - T_a)))/1.0
;T_h = (-log((T_i - T_a)/(T_d - T_a)))/k

;cout<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< setprecision(4)
<< "time between the death of the individual and the arrival of the examiner:"<<T_h<< "hours"<<endl;


return 0;


}
CHill60 1-Feb-16 9:47am    
So your next step is to debug the code ... which of the answers that you arrived at do you think is wrong? Have you checked your results using a calculator?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900