Task 2 Rainfall graph You are given a text file called raind

Task 2: Rainfall graph You are given a text file called raindata.txt. It contains 364 integer values representing the rainfall on each day of an entire year measured in millimeters. Write a program that reads these values into an array and can show a graph of the rainfall of a number of consecutive weeks chosen by the user. The program should prompt the user to specify a starting week number and the number of weeks for which a bar chart should be displayed. If the user enters a week’s index number that is outside the specified range, the program should display an error message and terminate. 3If the user enters a week’s index number that is in the specified range, the program should prompt the user for the number of weeks that should be displayed. This prompt should specify valid values based on the starting week number. If the user enters a number that is outside the specified range, the program should display an error message and terminate. The following is a sample test with invalid input: Enter the starting week’s index [1 - 52]: 50 Enter the number of weeks [1 - 3]: 4 You entered 4 where only values [1 - 3] are valid. If the user entered valid values, the program should calculate the total rainfall for the weeks within the specified range an then calculate the % of this total rainfall that was recorded for each of the weeks in the range. For each week draw a line of = signs to visualize the calculated value. For 100% the program should draw 80 = signs and for 50% it should draw 40. Round the number of signs to be printed to the nearest integer on this scale. The following is a sample successful test run. Enter the starting week’s index [1 - 52]: 22 Enter the number of weeks [1 - 31]: 4 -------------------------------------------------------------------------------------- Relative Weekly Rainfall (%) 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ 22|================================= 23| 24|=============================================== 25| --------------------------------------------------------------------------------------

Solution

s=364;
fileID=fopen(\'raindata.txt\');
A=fscanf(fileID,\'%f\',s);
B=zeros(1,s);
for m=1:52
    K=0;
    for n=(m-1)*7+1:(m-1)*7+7
        K=K+A(n);
    end
    B(m)=K./7;
end
w=input(\'enter starting week\'\'s end [1 52]\');
if isinteger(w)==false
    error(\'not an integer value\');
end
ch=[\'enter number of weeks [1-\',int2str(53-w),\']\'];
R= input(ch);
if isinteger(R)==false
    error(\'not an integer\');
end
if R<1&&R>(53-w)
    error(\'not in the range\');
end
l=w:w+R-1;
for p=w:w+R-1
    J=B(p);
end
stem(l,J);

Task 2: Rainfall graph You are given a text file called raindata.txt. It contains 364 integer values representing the rainfall on each day of an entire year mea

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site