Professional Documents
Culture Documents
Week 3 Lab Exercises PDF
Week 3 Lab Exercises PDF
College of Science
Department of Computer Science
COMP2002, Spring 2011
Week 3 Lab Exercises
Exercise 1:
Write, compile, link and execute a C++ program to calculate and display the linear expansion in a steel
beam as a function of temperature increase. The formula for linear expansion is: l l0[1 (T f T0 )] ,
where l0 is the length of the beam at temperature T0, is the coefficient of linear expansion, and Tf is the
final temperature of the beam. Your program should ask the user to enter and read the values of l0, , T0
and Tf using clear prompt messages. Display the result in the following format:
where xxx.xxx represents a field of width 7 including 3 digits to the right of the decimal point.
SAMPLE RUN
Exercise 2:
Newton’s law of cooling states that when an object with an initial temperature T is placed in a
surrounding substance of temperature A, it will reach a temperature TFIN after t minutes according to the
formula: TFIN (T A)e kt A , where k is a thermal coefficient for the material being cooled.
a) Using this formula write a C++ program that determines the temperature reached by an object of
initial temperature T degrees after placing it for t minutes in a liquid whose temperature is A degrees.
Your program should ask the user to enter the thermal coefficient k of the object as well as the values
of T, t and A. Use clear prompt messages when reading the inputs and display the result in the
following format:
where xxx.xx represents a field of width 6 including 2 digits to the right of the decimal point.