Temperature Conversion Program

advertisement
ICS Assignment - Temperature Conversion Program
Temperature Conversion Program
Topics Covered





textboxes, labels
math expressions (order of operations)
use of double numeric data types
converting between numeric and string data types
using a Design Elements table to design user interface
Problem Definition
Create a program that will convert temperature values from Fahrenheit to Celsius and from Celsius to
Fahrenheit based on values provided by users.
Reference Information
Temperature Conversion Formulas
Fahrenheit = Celsius x 9/5 + 32
Celsius = (Fahrenheit - 32) x 5/9
TextBoxes and Labels
Recall that the Text property is used to read data from TextBoxes and display data in Labels. In this
Assignment you will use a Label to display the new converted temperature and you will use a single textbox
to obtain the input temperature from the user.
Buttons
Recall that buttons are used to respond to user initiated actions. When you double-click on the button
control within the Designer you will be switched to the code editor. Your code will be added into the
button_click method.
Converting Strings to Numbers
For this application we want to convert the user provided temperature to a double.
The following method can be used to convert the Text property of a textbox (string) into a double value
which could then be used in the conversion calculation.
double.Parse(txtTempIn.Text)
Converting Math Expressions to Strings
Once the calculation is complete the answer needs to be converted back into a string to be displayed in
the label as its Text Property using an assignment operator (=).
The following method can be used to convert (note there are required brackets around the expression to
ensure the calculation is completed before the method is called):
(<calculation>).ToString()
Computer Science Assignment
[1]
Temperature Conversion Program
ICS Assignment - Temperature Conversion Program
Design Phase
Design User Interface
1. Define your GUI controls in the Design Elements table provided
2. Add the controls to your Form within Visual Studio. Ensure you name the controls appropriately.
Design Elements Table
Control
type
Control
Name
Property
Purpose
TextBox
Button
Button
Label
Code and Test the Application
1. Write C# code (each button will have code) to read the input (textbox), calculate the new
temperature and display the output (label).
Computer Science Assignment
[2]
Temperature Conversion Program
Download