CSE 5A Homework 3: Temperature Conversion Program, Assignments of Computer Science

The instructions for homework 3 in the cse 5a introduction to programming course. Students are required to create a new folder, write a c source file named hw3.c, and implement a temperature conversion program using scanf(), if-else statements, and for loops. The program should ask the user for the number of conversions and the temperature to convert, as well as whether it's fahrenheit or celsius. The temperature conversions are then performed using the provided formulas and output with the specified format.

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-d9p
koofers-user-d9p ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CSE 5A
Introduction To Programming (C/C++)
Homework 3
Read Chapter 5 & 6 Due: Friday, October 19 by 6:00pm
Create a new folder named HW3 (note uppercase HW3) in your cs5f@ieng9 Home Directory. You can do this
via My Computer -> WebDrive drive W: cs5f@ieng9 โ€“ Home Directory and then create a New -> Folder and
name it HW3.
Using Bloodshed Dev-C++, create a new Source File (File -> New -> Source File) and Save As with File Type
C Source Files (*.c), File Name: hw3 (note lowercase hw3), and Save In the new W: WebDrive/HW3 folder
you created above. Feel free to ask the tutors on duty in the lab for help.
hw3.c will be an extension of hw2.c adding user input (scanf()), conditional (if-else), and looping (for loop).
Let us start with an example execution of the program (user input is in bold):
How many temperature conversions would you like to perform? 3
[#1] Enter the degree you want to convert: 44.492
Is this a Fahrenheit or Celsius temperature? [F/C]: f
44.49 F = 6.94 C
[#2] Enter the degree you want to convert: 212
Is this a Fahrenheit or Celsius temperature? [F/C]: F
212.00 F = 100.00 C
[#3] Enter the degree you want to convert: -100.55
Is this a Fahrenheit or Celsius temperature? [F/C]: c
-100.55 C = -148.99 F
This program will first ask the user how many temperature conversions to perform. Then with each temperature
conversion, output the loop/iteration number (conversion #1, #2, etc.) with a prompt for the user to enter the
degree to convert, whether the entered degree is Fahrenheit or Celsius, and the converted temperature similar to
that of HW2. Note: The user can enter either upper-case 'F' or lower-case 'f' to indicate Fahrenheit and upper-
case 'C' or lower-case 'c' to indicate Celsius.
Use the formulas below to perform the conversions (same as HW2):
C = (F โ€“ 32.0) / 1.8 โ€“ to convert a Fahrenheit temperature to Celsius
F = C * 1.8 + 32.0 โ€“ to convert a Celsius temperature to Fahrenheit
Use the
printf()
format specifier %8.2f to output all of your double floating point variables with 2 places
precision to the right of the decimal point and a total width of 8 characters right-justified.
Use the
scanf()
format specifier %lf to input a double value (%f is for float input).
Whenever you input characters with
scanf()
, be sure to deal with the newline character appropriately. See the
class notes and lecture on Making Decisions for more details. Quick summary: whenever you read a value of
any type with scanf(), insert a
getchar();
as the next statement to absorb the newline character.
pf2

Partial preview of the text

Download CSE 5A Homework 3: Temperature Conversion Program and more Assignments Computer Science in PDF only on Docsity!

CSE 5A

Introduction To Programming (C/C++)

Homework 3

Read Chapter 5 & 6 Due: Friday, October 19 by 6:00pm

Create a new folder named HW3 (note uppercase HW3) in your cs5f@ieng9 Home Directory. You can do this via My Computer -> WebDrive drive W: cs5f@ieng9 โ€“ Home Directory and then create a New -> Folder and name it HW3.

Using Bloodshed Dev-C++, create a new Source File (File -> New -> Source File) and Save As with File Type C Source Files (*.c), File Name: hw3 (note lowercase hw3), and Save In the new W: WebDrive/HW3 folder you created above. Feel free to ask the tutors on duty in the lab for help.

hw3.c will be an extension of hw2.c adding user input (scanf()), conditional (if-else), and looping (for loop).

Let us start with an example execution of the program (user input is in bold):

How many temperature conversions would you like to perform? 3

[#1] Enter the degree you want to convert: 44. Is this a Fahrenheit or Celsius temperature? [F/C]: f 44.49 F = 6.94 C

[#2] Enter the degree you want to convert: 212 Is this a Fahrenheit or Celsius temperature? [F/C]: F 212.00 F = 100.00 C

[#3] Enter the degree you want to convert: -100. Is this a Fahrenheit or Celsius temperature? [F/C]: c -100.55 C = -148.99 F

This program will first ask the user how many temperature conversions to perform. Then with each temperature conversion, output the loop/iteration number (conversion #1, #2, etc.) with a prompt for the user to enter the degree to convert, whether the entered degree is Fahrenheit or Celsius, and the converted temperature similar to that of HW2. Note: The user can enter either upper-case 'F' or lower-case 'f' to indicate Fahrenheit and upper- case 'C' or lower-case 'c' to indicate Celsius.

Use the formulas below to perform the conversions (same as HW2): C = (F โ€“ 32.0) / 1.8 โ€“ to convert a Fahrenheit temperature to Celsius F = C * 1.8 + 32.0 โ€“ to convert a Celsius temperature to Fahrenheit

Use the printf() format specifier %8.2f to output all of your double floating point variables with 2 places precision to the right of the decimal point and a total width of 8 characters right-justified.

Use the scanf() format specifier %lf to input a double value (%f is for float input).

Whenever you input characters with scanf(), be sure to deal with the newline character appropriately. See the class notes and lecture on Making Decisions for more details. Quick summary: whenever you read a value of any type with scanf(), insert a getchar(); as the next statement to absorb the newline character.

scanf( "%c", &ch ); scanf( "%lf", &degree ); getchar(); /* Eat the newline char. / getchar(); / Eat the newline char. */

We will automatically collect your HW3/hw3.c files from your cs5f course specific home directories on ieng at 6pm on Friday. Make sure your HW3 project is stored in your cs5f home directory folder. If you have any questions/problems with this, see one of the tutors or the instructor.

Make sure you have your name and cs5f account number in the header comment of hw3.c.

/*

  • Name: Jane-Joe Student
  • Login: cs5fXX
  • Date: Month Day, Year
  • File: hw3.c
  • Sources of Help:
  • General description of the program ... */

Comment your program similar to the last program in Notes #1.

A couple more sample executions: ------------------------------------------------ Test Execution ------------------------------------------------

How many temperature conversions would you like to perform? 4

[#1] Enter the degree you want to convert: 40. Is this a Fahrenheit or Celsius temperature? [F/C]: c 40.05 C = 104.09 F

[#2] Enter the degree you want to convert: - Is this a Fahrenheit or Celsius temperature? [F/C]: F -212.00 F = -135.56 C

[#3] Enter the degree you want to convert: 0 Is this a Fahrenheit or Celsius temperature? [F/C]: C 0.00 C = 32.00 F

[#4] Enter the degree you want to convert: - Is this a Fahrenheit or Celsius temperature? [F/C]: f -40.00 F = -40.00 C

------------------------------------------------ Test Execution ------------------------------------------------

How many temperature conversions would you like to perform? 0

Your program will be tested with valid input only.

I will place a sample executable in the cs5f Public directory under Examples folder

hw3.exe

Early Turnin Extra Credit: 5% Extra Credit for being finished with this assignment by

6:00pm Thursday, Oct. 18.