Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP 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

PLEASE HELP

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.

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.

image text in transcribed

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

main.cpp EL ESTE 2 einclude using namespace std; 5 6 7 I write function srototypes before main 8 int calcHighestYear(); 9 Int calclovestYear(); 10 double calcAverageOverFirstXYears(int nunYears); 11 Ent calcbiggest JumpYear); 12 in the entry point for our program 14 four program starts with of an and ends with) of 15 int main() { 16 cout whileluser Input 1-6) 53 ) 54 55 SG int calcntighestYeart) 58 64 05 To 71 72 int calclovesteart) 76 C 75 80 double calchergedverfirstrearstint punyears) B7 int calcbiggest Jump reart) // 55 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Know the principles of effective service recovery systems.

Answered: 1 week ago

Question

Explain the service recovery paradox.

Answered: 1 week ago