Question: Please provide code in C++ language. Thank you. You have been given historical gas prices in gas_prices.txt. These are supposedly real average gas prices (per

Please provide code in C++ language. Thank you.

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

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 code you would have to change is where it says implement.

#include

#include

using namespace std;

//we write function prototypes before main

int calcHighestYear();

int calcLowestYear();

double calcAverageOverFirstXYears(int numYears);

int calcBiggestJumpYear();

//Main is the entry point for our program

//our program starts with { of main and ends with } of main

int main() {

cout << "Welcome to the Historical Gas Prices Explorer! ";

int userInput;

do

{

cout<<"type a number followed by return ";

cout<<"1-year of highest gas price ";

cout<<"2-year of lowest gas price ";

cout<<"3- average gas price over first X years ";

cout<<"4- year of biggest 1 year gas price jump from previous year ";

cout<<"5- (optional) any other extra thing you want to do ";

cout<<"6- exit ";

cin>>userInput;

switch(userInput)

{

case 1:

cout<<"The year with the highest gas price is: "<

break;

case 2:

cout<<"The year with the lowest gas price is: "<

break;

case 3:

int y;

cout<<"enter the number of years you want to calculate the average over: "<

cin>>y;

cout<<"The average gas price from 1929 to "<<1929+y<<" was: "<

break;

case 4:

cout<<"The year of the biggest gas price increase from the previous year is: "<

break;

case 5:

break;

case 6:

break;

default:

cout<

}

} while(userInput!=6);

}

int calcHighestYear()

{

//IMPLEMENT

return 0;

}

int calcLowestYear()

{

//IMPLEMENT

return 0;

}

double calcAverageOverFirstXYears(int numYears)

{

//IMPLEMENT

return 0;

}

int calcBiggestJumpYear()

{

//IMPLEMENT

return 0;

}

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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!