Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ using Visual Studio please Assignment Calculating fuel economy. This program will use exceptions and stream errors to make a robust application that gets the

C++ using Visual Studio please image text in transcribed
image text in transcribed
image text in transcribed
Assignment Calculating fuel economy. This program will use exceptions and stream errors to make a robust application that gets the number of miles and gallons each time the user fuels their car. It will put those values into vectors. economy. 4. Once the user wants to quit enter values, it will calculate the fuel a. Create GetMiles() function that returns double. If there is a stream error, then throw a runtime_error with the message Invalid input received, you must enter a decimal number. Don't forget to clear the error and ignore all characters until the end of the stream. i. li. If the value is less then or equal to zero, then throw a runtime_error with the ii. Otherwise, return the miles the user entered i. If there is a stream error, then throw a runtime error w message. Miles cannot be less than e. b. Create GetGallons() function that returns double. th the message Invalio input received, you must enter a decimal number. Don't forget to clear the error and ignore all characters until the end of the stream. li If the value is less than or equal to zero, then throw a runtime_error with the message. Gallons cannot be less than ii. Otherwise, return the miles the user entered c. Create GetMPG(vector gallons) function that returns a double i. If the size of the vectors is 0, then throw a runtime_error with the message No values recorded MPG is nan Otherwise, total the miles and gallons and return the miles per gallon. li. The main program should loop and get the Gallons and Miles catching any exceptions that were thrown. Then ask if they want to enter another tank. if they enter gallons d. and miles put the values into the vectors given. When the user is done the program should calculate the MPG by calling GetMPG, catching the exception if the user did not enter any values. Then it should show the result. Stream Errors cout number: if (cin.failo) ( /I Clear error state cin.clear) // Ignore characters in stream until newline cin.ignore (numeric limits: :max ), n') cout

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

More Books

Students also viewed these Databases questions

Question

4. Why does the LM curve slope upward?

Answered: 1 week ago

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago