Question
In C++, you have been given historical gas prices in gas_prices.txt. These are supposedly real average gas prices (per gallon) for the US in terms
In C++, you have been given historical gas prices in gas_prices.txt. These are supposedly real average gas prices (per gallon) for the US in terms of the value of the dollar in 2015 (so it takes into account inflation). The data is from 1929 to 2015.
Your are also given some starter code. If you run the program you are given the following menu to choose from
type a number followed by return 1-year of highest gas price 2-year of lowest gas price 3- average gas price over first X years 4- year of biggest 1 year gas price jump from previous year 5- (optional) any other extra thing you want to do 6- exit
You can assume the values in the file are the ones you will get so no input validation necessary. For the user input (part 3) there will be minimal input validation as described below.
Items 1-4 call a function associated with that item. It is your job to implement those functions below! The only places you should add code to do items 1-4 in the places that say //IMPLEMENT below. We will go over this in class and decide what we need to know to do this project, my lecture will try to touch on all the things you should know but feel free to do your own research on things.
Requirements: Your code must pass all the test cases (but passing all the test cases does not mean full credit!) but also
A) Use a while loop which checks for the value of -1 to read through the gas_prices.txt file (note the -1 values as the end-- this is called a sentinel value, it's a dummy value which cannot possibly be valid but marks the end of input, meaning the while loop will break when it hits a sentinel value) in parts 1 and 2
B) Use a for loop to calculate the average gas price over the first X years. The for loop should break if it encounters a -1 and return a -1 (i.e. if the number of years given exceeds the number of years in the file). It should also return a -1 with a year equal to 0 or less.
C) Use branching statements where appropriate
D) For part 4 we are looking for the biggest increase ("jump") from the previous year.
optionally you can do your own processing on the code with option 5 but it is not required. One idea is to find the decade of the lowest gas prices or extending 3 to find the standard deviation.
The Years and Gas Prices:
1929 2.38 1930 2.3 1931 2.18 1932 2.61 1933 2.66 1934 2.67 1935 2.62 1936 2.67 1937 2.63 1938 2.64 1939 2.56 1940 2.49 1941 2.43 1942 2.39 1943 2.3 1944 2.25 1945 2.19 1946 1.96 1947 1.97 1948 2.09 1949 2.17 1950 2.14 1951 2.03 1952 2.01 1953 2.08 1954 2.08 1955 2.05 1956 2.04 1957 2.05 1958 1.96 1959 1.94 1960 1.95 1961 1.91 1962 1.88 1963 1.84 1964 1.82 1965 1.83 1966 1.83 1967 1.84 1968 1.79 1969 1.77 1970 1.72 1971 1.67 1972 1.59 1973 1.62 1974 2.03 1975 1.98 1976 1.96 1977 1.94 1978 1.83 1979 2.31 1980 2.95 1981 2.97 1982 2.6 1983 2.37 1984 2.23 1985 2.14 1986 1.61 1987 1.64 1988 1.59 1989 1.7 1990 1.89 1991 1.81 1992 1.75 1993 1.68 1994 1.65 1995 1.67 1996 1.76 1997 1.74 1998 1.47 1999 1.6 2000 2.02 2001 1.91 2002 1.75 2003 2.01 2004 2.32 2005 2.74 2006 3 2007 3.16 2008 3.61 2009 2.58 2010 3.02 2011 3.75 2012 3.8 2013 3.62 2014 3.4 2015 2.45 -1 -1
1 main.cpp #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started