In: Computer Science
You've been hired by Water Wonders to write a C++ console application that analyzes lake level data. MichiganHuronLakeLevels.txt. Place the input file in a folder where your development tool can locate it (on Visual Studio, in folder \). The input file may be placed in any folder but a path must be specified to locate it.
MichiganHuronLakeLevels.txt Down below:
Lake Michigan and Lake Huron - Average lake levels - 1860-2015
Year Average level (meters)
1860 177.3351667
1861 177.3318333
1862 177.316
1863 177.1796667
1864 176.9955833
1865 176.90525
1866 176.80575
1867 176.9365833
1868 176.7891667
1869 176.8250833
1870 177.1
1871 177.0769167
1872 176.7318333
1873 176.9188333
1874 177.0413333
1875 176.9683333
1876 177.2855833
1877 177.1971667
1878 177.1183333
1879 176.85325
1880 176.90425
1881 177.0205
1882 177.1250833
1883 177.2096667
1884 177.2734167
1885 177.3208333
1886 177.3893333
1887 177.1890833
1888 176.9931667
1889 176.8393333
1890 176.788
1891 176.6149167
1892 176.564
1893 176.6204167
1894 176.6811667
1895 176.4201667
1896 176.3256667
1897 176.5094167
1898 176.5564167
1898 176.5595
1900 176.5626667
1901 176.64175
1902 176.5305833
1903 176.5748333
1904 176.7460909
1905 176.7561667
1906 176.7635
1907 176.7844167
1908 176.7670909
1909 176.5988333
1910 176.5025
1911 176.3356667
1912 176.4768333
1913 176.67025
1914 176.5297273
1915 176.3535833
1916 176.5715833
1917 176.7980833
1918 176.8866667
1919 176.745
1920 176.625
1921 176.4883333
1922 176.445
1923 176.2641667
1924 176.1866667
1925 175.9191667
1926 175.885
1927 176.1483333
1928 176.4433333
1929 176.8958333
1930 176.6508333
1931 176.1183333
1932 175.9408333
1933 175.8675
1934 175.7666667
1935 175.8908333
1936 175.9391667
1937 175.9225
1938 176.1408333
1939 176.2691667
1940 176.1416667
1941 176.1216667
1942 176.3341667
1943 176.6266667
1944 176.5966667
1945 176.57
1946 176.6016667
1947 176.5666667
1948 176.5308333
1949 176.2108333
1950 176.2608333
1951 176.7358333
1952 177.085
1953 176.9333333
1954 176.8291667
1955 176.7225
1956 176.44
1957 176.2633333
1958 176.0675
1959 176.0058333
1960 176.4775
1961 176.3766667
1962 176.2225
1963 175.9225
1964 175.6825
1965 175.9158333
1966 176.1608333
1967 176.3008333
1968 176.4466667
1969 176.6958333
1970 176.6783333
1971 176.805
1972 176.8883333
1973 177.1233333
1974 177.0933333
1975 176.9733333
1976 176.8991667
1977 176.505
1978 176.5908333
1979 176.7941667
1980 176.8033333
1981 176.6983333
1982 176.5983333
1983 176.8333333
1984 176.895
1985 177.1266667
1986 177.2925
1987 176.97
1988 176.5641667
1989 176.4008333
1990 176.35
1991 176.4691667
1992 176.4791667
1993 176.6958333
1994 176.6783333
1995 176.5275
1996 176.6541667
1997 176.9841667
1998 176.7166667
1999 176.2358333
2000 175.9783333
2001 175.9508333
2002 176.1183333
2003 175.8916667
2004 176.1108333
2005 176.09
2006 176.0158333
2007 175.9433333
2008 176.005
2009 176.2583333
2010 176.1108333
2011 176.0366
2012 175.9158
2013 175.9
2014 176.3016667
2015 176.59
Within the app, attempt to open the input file and output file MichiganHuronLakeLevelsHighAndLow.txt. If the input file didn't open, print an error message. If the output file didn't open, print an error message. Read the input file by scanning past the two header rows. Each detail row in the input file contains two fields (year, lake level). Read one token at a time from the input file. See sample Canvas app Text file input – one token per read. Determine the maximum, minimum, and average lake levels. One technique to accomplish this is to use a max variable that starts very small and a min variable that starts very large. After all lines of the input file have been read, use formatted output manipulators (setw, left/right) to print the following rows:
● Column headers.
● Max values.
● Min values.
● Average value.
And columns:
● A left-justified label.
● A right-justified year.
● A right-justified level.
Then write the same information to output file MichiganHuronLakeLevelsHighAndLow.txt. Insure that your code is commented! Provide a complete header comment and body comments. Define constants for the input and output file names and column widths. Format any real numbers to four decimal places. The output should look like this:
Welcome to Wonder Waters
------------------------
Reading lines from file 'MichiganHuronLakeLevels.txt' ...
Writing lines to file 'MichiganHuronLakeLevelsHighAndLow.txt' ...
Year Level (meters)
Max level: … …
Min level: … …
Average level: …
158 line(s) read from file 'MichiganHuronLakeLevels.txt'.
4 line(s) written to file 'MichiganHuronLakeLevelsHighAndLow.txt'.
End of Wonder Waters
Here is the answer for your question in C++ Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : As you have the input text file with you and its content is big, I am providing the .cpp file alone here in the answer.
##########################################################################
CODE :
#include<iostream> using namespace std; int main(){ |
#####################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
#################################################################
OUTPUT :
Console output :
MichiganHuronLakeLevelsHighAndLow.txt file
Any doubts regarding this can be explained with pleasure :)