Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Temperature Conversion Assignment for CS 140, Fall 2008 - Prof. Andrew R. Dalton, Assignments of Computer Science

An assignment for cs 140 students in the fall 2008 semester. The assignment involves writing two programs, one for converting temperatures from fahrenheit to celsius, kelvin, and rankine, and the other for converting temperatures from celsius to fahrenheit, kelvin, and rankine. Students are expected to use variables of type float, scanf() and printf() functions, and arithmetic operators. The challenge is to generate output in the specified format with two decimal places and vertically aligned decimal points.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-3zm
koofers-user-3zm ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 140 Fall 2008
Assignment #3:
Temperature Conversion
Dr. Andrew R. Dalton
September 5th, 2008
1 Overview
The purpose of this assignment is to give you some experience working with the functions printf() and
scanf(), variables of type float, and arithmetic operators. You will be using these throughout the semester.
For this reason, it is important that you take the time to practice now, before we cover more advanced topics.
For this assignment, you will develop two (2) separate programs. Both of these programs will be responsible
for converting temperature in a specified unit of measurement to three (3) other units. The formulae needed
to perform the conversions are:
TCelsius = (TF ahrenheit โˆ’32) โˆ—5
9(1)
TF ahrenheit =TCelsius โˆ—9
5+ 32 (2)
TKelvin =TC elsius + 273.15 (3)
TRankine =TF ahrenheit + 459.67 (4)
Formula 1 enables you to calculate the temperature in degrees Celsius, given the temperature in degrees
Fahrenheit. Formula 2 enables you to calculate the temperature in degrees Fahrenheit, given the temperature
in degrees Celsius. Formula 3 enables you to calculate the temperature in Kelvins, given the temperature
in degrees Celsius. Finally, Formula 4 enables you to calculate the temperature in Rankines, given the
temperature in degrees Fahrenheit.
The two (2) programs you are expected to write are described below.
1. Fahrenheit Converter. This program will prompt the user for a temperature in degrees Fahrenheit.
Next, the program will convert the user-entered temperature to degrees Celsius, to Kelvins, and to
Rankines. Finally, the program will print a summary of all of the values. An example run of the
program might look like:
$./a.out
Enter the temperature in Fahrenheit: 32
32.00 degrees Fahrenheit is:
0.00 degrees Celsius
273.15 Kelvins
491.67 Rankines
$
The program should be saved in a file named fahrenheit.c.
1
pf2

Partial preview of the text

Download Temperature Conversion Assignment for CS 140, Fall 2008 - Prof. Andrew R. Dalton and more Assignments Computer Science in PDF only on Docsity!

CS 140 Fall 2008

Assignment #3:

Temperature Conversion

Dr. Andrew R. Dalton

September 5th, 2008

1 Overview

The purpose of this assignment is to give you some experience working with the functions printf() and scanf(), variables of type float, and arithmetic operators. You will be using these throughout the semester. For this reason, it is important that you take the time to practice now, before we cover more advanced topics.

For this assignment, you will develop two (2) separate programs. Both of these programs will be responsible for converting temperature in a specified unit of measurement to three (3) other units. The formulae needed to perform the conversions are:

TCelsius = (TF ahrenheit โˆ’ 32) โˆ—

TF ahrenheit = TCelsius โˆ—

TKelvin = TCelsius + 273. 15 (3)

TRankine = TF ahrenheit + 459. 67 (4)

Formula 1 enables you to calculate the temperature in degrees Celsius, given the temperature in degrees Fahrenheit. Formula 2 enables you to calculate the temperature in degrees Fahrenheit, given the temperature in degrees Celsius. Formula 3 enables you to calculate the temperature in Kelvins, given the temperature in degrees Celsius. Finally, Formula 4 enables you to calculate the temperature in Rankines, given the temperature in degrees Fahrenheit.

The two (2) programs you are expected to write are described below.

  1. Fahrenheit Converter. This program will prompt the user for a temperature in degrees Fahrenheit. Next, the program will convert the user-entered temperature to degrees Celsius, to Kelvins, and to Rankines. Finally, the program will print a summary of all of the values. An example run of the program might look like: $./a.out Enter the temperature in Fahrenheit: 32 32.00 degrees Fahrenheit is: 0.00 degrees Celsius 273.15 Kelvins 491.67 Rankines $

The program should be saved in a file named fahrenheit.c.

CS 140 Fall 2008

  1. Celsius Converter. This program will prompt the user for a temperature in degrees Celsius. Next, the program will convert the user-entered temperature to degrees Fahrenheit, to Kelvins, and to Rankines. Finally, the program will print a summary of all of the values. An example run of the program might look like: $./a.out Enter the temperature in Celsius: 0 0.00 degrees Celsius is: 32.00 degrees Fahrenheit 273.15 Kelvins 491.67 Rankines $ The program should be saved in a file named celsius.c.

2 Details

Each of your programs should include variables of type float to hold the temperature values in the various units. Be sure to use meaningful variable names (e.g., use fahrenheit, not f, celsius not c). Use the scanf() function to read in the appropriate values, and use the formulae shown above to perform the conversions.

The challenge in this assignment comes from making your program generate output in the form specified in the examples above. Note specifically that the values, when printed, are shown at two (2) decimal places. Also notice that the decimal points line up vertically. We will discuss how to perform such alignment in lecture.

Also note your program should do more than replicate the behavior specified in the examples. Your program should be able to correctly handle various input values.

Your code should be formatted using good programming style. Be sure to include a comment block at the top of each file that includes your name, the date, the name of the file, and the purpose of the program.

Finally, be sure to compile your programs using gcc -O -Wall and correct all warnings (and errors) before handing in the source code.

3 Hand-In Instructions

The assignment is due at the start of class on September 12 th. Leave your source code in your cs140/assignment3 directory. Do not modify your program after the due date.

4 Notes on Collaboration

You are required to work individually on this assignment. Please do not consult anyone other than me on any aspect of this assignment.