Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Copy your temptbl.c file from your Lab4 directory into your Lab5 directory. Modify your temptable() function to be: int temptable(float start, float stop, float step);

Copy your temptbl.c file from your Lab4 directory into your Lab5 directory. Modify your temptable() function to be:

 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) 

should produce this output:

 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 

The call

 temptable(42.0, 32.0, 5.0); 

or the call

 temptable(42.0, 32.0, -5.0); 

should produce this output:

 Fahrenheit Celsius 42.00 5.56 37.00 2.78 32.00 0.00 Computed 3 temperatures 

Finally, 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. 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] 

this is the code from my other file:

#include /*Function to convert fahrenheit to celsius*/ double tocelsius(int fahrenheit) { return (fahrenheit - 32) * 0.5556; } int temptable(float start, float stop) { //we have to increment in 5 units int incr = 5; int count = 0;

//Use while loop till start < stop while (start <= stop) {

//print conversion printf(" Fahrenheit : %f equivalent Celsius : %f", start, tocelsius(start));

//increase count of number of table lines count = count + 1;

//increment by 5 start = start + incr; } return count; } int main() { int fahrenheit; double celsius; int stop; int start; //Get the start and stop temperature first time printf(" Enter start temperature : ");

scanf("%d", &start);

printf(" Enter stop temperature : ");

scanf("%d", &stop); //Repeat this loop till start is not equal to stop while (start != stop) {

//print table by calling temptable functions temptable(start, stop);

//Get the start and stop temperature again printf(" Enter start temperature : ");

scanf("%d", &start);

printf(" Enter stop temperature : ");

scanf("%d", &stop); } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

1 for suggestions). Be specific.

Answered: 1 week ago

Question

=+ What topics are contained in the contracts?

Answered: 1 week ago

Question

=+Are they specific or general in nature?

Answered: 1 week ago