# Basics, Lecture 3

1. The process of creating software
1. Example problem:   Write a program that converts a temperature in Fahrenheit to both Celsius and Kelvin.  The formula for conversion of Fahrenheit to Celsius is C = (5/9)(F-32), where F is temperature in Fahrenheit and C is temperature in Celsius.  Degrees Kelvin are just degrees Celsius shifted by a constant amount. The zero of the Kelvin scale is -273.15 degrees Celsius.   Your output should look something like: 32 Fahreheit is equivalent to 0 Celsius and 273.15 Kelvin.
2. Analyze the problem
2. Determine what outputs the program must produce:
1. What is the form of the output?
2. What parts of the output are computed and what parts are fixed?
1. In the example, the 0 and -273.15 parts are computed.  Everything else in the output example except for the 32 is fixed.
3. Determine what items are considered inputs in the problem
1. An input is something that can be changed each time the program is run
2. In the example, Fahrenheit temperature is an input item and 32 is the input value used for this input item in the example.
3. Develop (design) a solution
1. List the steps of the overall solution (a solution outline)
2. Compute the Celsius and Kelvin values corresponding to the input Fahrenheit value
3. Output the input and computed values
2. If one of the steps appears to be even a little difficult to write in C++, refine the step (break it down into substeps and add detail)
1. The "Compute" step in the example is not obvious.  Refine it into two substeps and supply detailed formula for computing each value:
1. Compute Celsius using the formula C = (5/9)(F-32)
2. Compute Kelvin using the formula K = C + 273.15
3. Trace (aka desk check) your solution on at least one example to make sure that it gives correct answers.
1. Draw a box for each variable (F, C, and K in the example) and for the "screen" where the output can be displayed
2. Go through the steps of the outline and change the boxes as directed
3.  Step F C K screen a 32 b.i 32 0 b.ii 32 0 273.15 c 32 0 273.15 32 Fahreheit is equivalent to 0 Celsius and 273.15 Kelvin
4. Verify that the result is what you expected.  If not, correct problems in your analysis or solution.
1. Write the standard parts of the program (#include, main, return, etc.)
2. Identify data types of input/output variables
1. In this example, F, C, and K should probably all be float because of the decimal in the Kelvin value in the example.
3. Write declaration statements for all variables.  The variable names used may or may not be those used in the design.  Include appropriate comments.
1. Example:

2. float fahrenheit;  // input temperature in fahrenheit
float celsius;         // temperature in celsius corresponding to input fahrenheit temp
float kelvin;          // temperature in kelvin corresp. to celsius and fahrenheit
4. Write other C++ statements corresponding to each line in the solution outline, including comments corresponding to at least highest level of the solution outline.
1. Be careful about various C++ idiosyncracies:
1. Integer arithmetic (truncation of quotient to an integer)
2. Multiplication must be indicated explicitly
2. Example:

3. // Assign value to fahrenheit input item
fahrenheit = 32.0;

// Compute corresponding values on other temperature scales
celsius = (5.0/9.0)*(fahrenheit - 32.0);
kelvin = celsius + 273.15;

// Output the results
cout << fahrenheit << " Fahreheit is equivalent to "
<< celsius << " Celsius and " << kelvin << " Kelvin" << endl;