The objectives of this lab are to give you more practice at using functions and while loops and to begin using if statements. You are still expected to be thinking in terms of the algorithms for your programs before coding; however, we will not ask you to turn in the algorithms separately. Instead, we do expect to see your algorithms in the comments in your files.
You should begin by creating a new directory called Lab5 in your EE160/Labs directory (which you have created in previous labs). All of the program files you write for this lab should be in this Lab5 directory.
Enter an integer value: 10 Enter an integer value: 20 Enter an integer value: 30 Enter an integer value: [control-D] The average of 3 input values is 20.000000 Enter a weight/value pair: 20 90 Enter a weight/value pair: 30 80 Enter a weight/value pair: 50 60 Enter a weight/value pair: [control-D] The weighted average of 3 input values is 72.000000 int temptable(float start, float stop, float step); /* Given: starting and ending temperatures in degrees Fahrenheit and a step size. The function prints a table of conversions from degrees Fahrenheit to degrees Celsius from start to at most stop in "step" degree F increments, one conversion per line. Returns: the number of table lines printed. */The new function, temptable(), should still use your function, tocelsius(). Its job is to print an appropriate temperature table. The catch is that this function should work correctly, regardless of whether the first temperature is larger than the second or the second is larger than the first. In addition, it should not behave badly (go into an infinite loop) with a very small step (such as 0.0); that means for this lab that it should produce an error message "No table--step smaller than 0.001!" if the step is smaller than 0.001. If the step is negative, the function should turn it into a positive step. The call
temptable(32.0, 64.0, 4.0) Fahrenheit Celsius 32.00 0.00 36.00 2.22 40.00 4.44 44.00 6.67 48.00 8.89 52.00 11.11 56.00 13.33 60.00 15.56 64.00 17.78 Computed 9 temperatures temptable(42.0, 32.0, 5.0); temptable(42.0, 32.0, -5.0); Fahrenheit Celsius 42.00 5.56 37.00 2.78 32.00 0.00 Computed 3 temperaturesFinally, replace the main program in temptbl.c with a new main program that repeatedly reads the temperatures and the step from the user and then uses the temptable function to print the table. Use ctrl+d to end. As an example, here's a sample run of the program.
Enter start, stop and step:32 64 4 Fahrenheit Celsius 32.00 0.00 36.00 2.22 40.00 4.44 44.00 6.67 48.00 8.89 52.00 11.11 56.00 13.33 60.00 15.56 64.00 17.78 Computed 9 temperatures Enter start, stop and step:42 32 5 Fahrenheit Celsius 42.00 5.56 37.00 2.78 32.00 0.00 Computed 3 temperatures Enter start, stop and step:42 32 -5 Fahrenheit Celsius 42.00 5.56 37.00 2.78 32.00 0.00 Computed 3 temperatures [control-D]Use the "grade" command to turn in the five programs (sum.c, avg.c, weight.c, temptbl.c, and account.c). Your command will look like the following.
If you are in Section 001 use:
grade -lab5s1,ee160 sum.c avg.c weight.c temptbl.c account.c If you are in Section 002 use:
grade -lab5s2,ee160 sum.c avg.c weight.c temptbl.c account.c If you are in Section 003 use:
grade -lab5s3,ee160 sum.c avg.c weight.c temptbl.c account.c If you are in Section 004 use:
grade -lab5s4,ee160 sum.c avg.c weight.c temptbl.c account.c You should verify that you turned in things successfully, which you can do with the command (which simply leaves the file names off from the previous command).
grade -lab5s1,ee160 OR grade -lab5s2,ee160 OR grade -lab5s3,ee160 OR grade -lab5s4,ee160NOTE: after the files are prepared for grading, you will no longer be able to see your file listing using the above command.