/* Example on while loop ( linear interpolation) Fall 1999 _________________________________ Jacob Y. Kazakia jyk0 September 21, 1999 Recitation Instructor: J.Y. Kazakia Recitation Section 01 ________________________________ Purpose: This program calculates the temperature of a surface at a given elapsed time after the start of cooling Algorithm: The initial temperature is given at T1 = 160 oC The temperature T2 = 95 oC is reached 1.6 minutes later. After an additional 5.1 minutes the temperature drops to 30 oC and remains constant thereafter. Linear interpolation is to be used for other times. The formulas are: temp = T1 + rate1 * (time - time1) for time1<=time // header which contains the functions // needed for input and output void main( ) { double T1 = 160.0; double T2 = 95.0; double T3 = 30.0; double time1 = 0.0; double time2 = 1.6; double time3 = 6.7; double time, temp; double rate1, rate2; rate1 = ( T2-T1)/(time2-time1); rate2 = ( T3-T2)/(time3-time2); cout<<"\n\n Enter the time elapsed since the start of cooling ( in minutes)-->"; cin >> time; while ( time > 0.0 ) { if ( time <= time2) temp = T1 + rate1 * (time - time1); else if ( time <= time3) temp = T2 + rate2 * (time - time2); else temp = T3; cout << "\n\n At this time the temperature is : " <"; cin >> time; } cout << " \n\n GOOD BYE"; // hold the screen char hold; cout << " \n\n Enter a character to quit \n"; cin >> hold; } /* TYPICAL RUN Enter the time elapsed since the start of cooling ( in minutes)-->1.6 At this time the temperature is : 95 Enter another time elapsed ( in minutes).. ENTER -1 to TERMINATE ....>6.7 At this time the temperature is : 30 Enter another time elapsed ( in minutes).. ENTER -1 to TERMINATE ....>4.8 At this time the temperature is : 54.2157 Enter another time elapsed ( in minutes).. ENTER -1 to TERMINATE ....> Enter another time elapsed ( in minutes).. ENTER -1 to TERMINATE ....>-1 GOOD BYE Enter a character to quit */