Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
56 views1 page

Week 3 Lab Exercises PDF

This document contains instructions for two exercises in a computer science lab assignment. Exercise 1 involves writing a C++ program to calculate and display the linear expansion of a steel beam based on a given formula. Exercise 2 involves writing a program to calculate the final temperature of an object using Newton's law of cooling, asking the user for input values and displaying the result. Students are asked to compile, link, and execute their programs, name their source file with their student ID, and upload it to Moodle.

Uploaded by

Abdul Aziz Turdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views1 page

Week 3 Lab Exercises PDF

This document contains instructions for two exercises in a computer science lab assignment. Exercise 1 involves writing a C++ program to calculate and display the linear expansion of a steel beam based on a given formula. Exercise 2 involves writing a program to calculate the final temperature of an object using Newton's law of cooling, asking the user for input values and displaying the result. Students are asked to compile, link, and execute their programs, name their source file with their student ID, and upload it to Moodle.

Uploaded by

Abdul Aziz Turdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Sultan Qaboos University

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:

The linear expansion is: xxx.xxx

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:

The final temperature of the object is: xxx.xx

where xxx.xx represents a field of width 6 including 2 digits to the right of the decimal point.

b) Compile, link and execute your program.


c) Name your source file lab3_xxxxx.cpp (where xxxxx is your student ID) and upload it on Moodle
before the end of the lab session.
SAMPLE RUN

You might also like