Write a function that writes a series of random Fahrenheit t

Write a function that writes a series of random Fahrenheit temperatures and their corresing Celsius temperatures to a tab-delimited file. Use 32 to 212 as your temperature From the user, obtain the following: The number of temperatures to randomly generate. The name of the output file. A sample run is included below (you must follow the format provided below):>> Please enter the name of your file: Example txt Please enter the number of iterations: 100 >> Example txt: Fahrenheit Celsius 111.29 44.05 78.71 25.95 137.66 58.70 88.17 31.20 etc... Write a function that reads a file produced by part 1. Also, focusing only on the celsius temperatures in the file, calculate and display to screen the following: Mean or Average. Minimum. Maximum.

Solution

//Tested on octave online

clear all
echo off all

name=input(\'Please enter the name of your file\',\'s\')
itr=input(\'Please enter the number of iterations\')
vec=[]
i=1
function result = ftoc(ftemp)
%Convert the values from F to C using the conversion factor
%C = (F – 32) * 5/9
result = (ftemp-32)*5/9;
%In the above statement you can also use (ftemp-32)*(5/9) or many other
end

fid=fopen(name,\'w\');
fprintf(fid, \'Fahrenheit Celsius\ \');

for x=1:itr
random_value=randi([32 212],1,1)
ctemp=ftoc(random_value)
fprintf(fid, \'%.2f %.2f \ \',random_value,ctemp);
end
fclose(fid)

/***************output**************/

Fahrenheit Celsius
77.00 25.00
188.00 86.67
58.00 14.44
192.00 88.89
186.00 85.56
60.00 15.56

part 2:

================

clear all
echo off all

name=input(\'Please enter the name of your file\',\'s\')
vec=[]
i=1
m=dlmread(name)
[rows, columns] = size(m)

for row=2:rows
vec(i)=m(row,2)
i=i+1
end   
maximum=max(vec);
minimum=min(vec);
mean_value=mean(vec)
fprintf(\'Maximum element is %.2f \ \',maximum)
fprintf(\'Minimum Element is %.2f \ \',minimum)
fprintf(\'Mean is %.2f \ \',mean_value)

/*************output*************/

Thanks a lot

 Write a function that writes a series of random Fahrenheit temperatures and their corresing Celsius temperatures to a tab-delimited file. Use 32 to 212 as your
 Write a function that writes a series of random Fahrenheit temperatures and their corresing Celsius temperatures to a tab-delimited file. Use 32 to 212 as your

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site