

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 2
This page cannot be seen from the preview
Don't miss anything!
CS 140 Fall 2008
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.
The program should be saved in a file named fahrenheit.c.
CS 140 Fall 2008
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
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.
You are required to work individually on this assignment. Please do not consult anyone other than me on any aspect of this assignment.