Unit #4 Homework Problem (Solution) | |
|
|
4hw2a
|
|
Newton's Law of Cooling states that the rate of cooling of an object is proportional to the temperature difference between the object and its surroundings. If an object has initial temperature temp0, the temperature of the surroundings is temps, and in time tdrop the temperature of the object falls to temp1, then the temperature of the object at time t is given by the formula: An
object of initial temperature of 199 0F cools down to 85 0F in about 89.5
seconds, when it is kept in a room of 750F. Write a program which creates
a table of temperature vs time for the first 30 seconds of cooling ( time
varies between 0 and 30 seconds). The table should have 7 lines of numbers
and an appropriate heading. ANSWER: #include <iostream.h> #include <iomanip.h> #include <math.h> main() { float temp0 = 199; // initial temperature float temp1 = 85; // temperature where it drops after tdrop time float tdrop = 89.5; float tstep; float temps = 75; // temperature of surroundings float temperature; float time, a, b ; int k; cout << setiosflags( ios:: fixed) << setprecision(2) cout <<"\n\n A Table of Temperatures "; cout <<"\n During cooling of object"; cout <<"\n ( temperatures in oF time in sec )"; cout <<"\n Temperature of the surroundings :" << temps; cout <<"\n Temperature initialy:" << temp0; cout <<"\n Temperature after tdrop seconds :" << temp1; cout <<"\n Time needed to drop from temp0 to temp1 :" << tdrop; cout <<"\n\n Time Temperature \n"; a = (temp1 - temps)/(temp0 - temps); a = log(a); tstep = 5; for( k = 0 ; k <= 6 ; k++) { time = k * tstep; b = exp( a * time / tdrop); temperature = temps + (temp0 - temps) * b; cout << setw(15) << time << setw(15) << temperature <<endl; } char hold; cout<<"\n\n enter e to exit "; cin >>hold ; } THE OUTPUT: A Table of Temperatures During cooling of object ( temperatures in oF time in sec ) Temperature of the surroundings :75.00 Temperature initialy:199.00 Temperature after tdrop seconds :85.00 Time needed to drop from temp0 to temp1 :89.50 Time Temperature 0.00 199.00 5.00 182.73 10.00 168.59 15.00 156.31 20.00 145.65 25.00 136.38 30.00 128.32 enter e to exit |
|
Jacob Y. Kazakia ©
2001 All rights reserved
|