Q:

Write a program to write a length conversion chart to a file. It will print lengths in feet, from 1 to an integer specified by the user, in one column and the corresponding length in meters ( 1 foot = 0.3048 m) in a second column

0

 Write a program to write a length conversion chart to a file. It will print lengths in feet, from 1 to an integer specified by the user, in one column and the corresponding length in meters ( 1 foot = 0.3048 m) in a second column. The main script will call one function that prompts the user for the maximum length in feet; this function must error-check to make sure that the user enters a valid positive integer. The script then calls a function to write the lengths to a file. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch6Ex17.m

% Write a length conversion chart to a file

% Call a function to get the max length in feet

maxl = promptMaxL;

% Call a function to write the chart to a file

lengthChart(maxl)

promptMaxL.m

function maxl = promptMaxL

% This function prompts the user for a max length in feet

% It error-checks to make sure it is a positive integer

% Format of call: promptmaxl or promptmaxl()

% Returns the integer maximum length in feet

inputnum = input('Enter the maximum length: ');

num2 = int32(inputnum);

while num2 ~= inputnum | num2 < 0

 inputnum = input('Invalid! Enter a positive integer: ');

 num2 = int32(inputnum);

end

maxl = inputnum;

end

lengthChart.m

function lengthChart(maxl)

% Creates a chart of converting feet to

% meters and writes it to a file

% Format of call: lengthChart(maximum length)

% Does not return any values

ft = 1:maxl;

meters = ft * .3048;

chart = [ft;meters]';

save ftmetchart.dat chart -ascii

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now