Menu

(Get Answer) – Writing To A File

Question Description

Create an array of 100 doubles with values between 10 and 75. Then write all 100 values to a file called “data1.txt”, in tabular form, ten values across in each row. Include in your file, a comment at the front, that says “Start of data” and one at the end that says, “End of data”. Since you don’t seed the random numbers, your output on prclab1 should exactly match the following:

% cat data1.txt

Start of data

64.61 35.63 60.90 61.90 69.26 22.84 31.79 59.93 28.06 46.01

41.03 50.88 33.71 43.37 71.89 69.55 51.32 56.62 19.20 49.45

11.06 25.79 18.92 62.27 20.18 36.06 18.44 17.07 74.93 24.19

43.34 64.54 49.82 29.24 51.44 44.08 42.08 73.23 29.01 60.14

44.24 60.04 36.01 67.95 28.42 32.91 62.50 69.74 14.53 71.71

44.19 15.59 22.49 53.11 67.87 32.68 14.17 11.30 39.75 14.10

25.49 73.09 68.64 65.31 27.33 45.08 34.39 59.42 43.31 53.40

44.55 12.55 38.45 70.57 70.50 56.86 28.48 58.00 51.60 33.01

54.71 20.79 38.61 67.20 63.90 31.47 24.88 68.07 32.77 54.63

72.17 48.26 52.72 65.81 38.57 70.06 35.90 62.96 54.47 69.21

End of data

Refill the array with 13 doubles with values between 130.2 and 130.7. Write all 13 values to a file called “data2.txt”.

Include in “data2.txt” the same comment lines at the beginning and end of the data. Your output in the second file should look like the following:

% cat data2.txt

Start of data

130.44 130.31 130.68 130.66 130.27 130.64 130.52 130.42 130.51 130.34

130.59 130.35 130.42

End of data

%

HTML tutorial

Leave a Reply

Your email address will not be published.