Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exception Handling Skills Required 0 Exception Handling ' Read and write Files, Work with arrays and vectors, Create Functions, Include Headers and other les, Loops

image text in transcribedimage text in transcribed
Exception Handling Skills Required 0 Exception Handling ' Read and write Files, Work with arrays and vectors, Create Functions, Include Headers and other les, Loops (while, for), Conditional (if, switch), Datatypes, assignment, etc. ' Basic git commands . Follow the link that was given on Canvas for this Assignment to create your repository. 2. Use the directions and skills from Week 1 to clone the repository into the directory of your choosing. 3. Open the starter solution provided Assignment 4. 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. Once the user wants to quit enter values, it will calculate the fuel economy. a. Create GetMilesO function that returns double. i. If there is a stream error, then throw a runtime_error with the message inn MI -.-.-. MI W. Don't forget to clear the error and ignore all characters until the end of the stream. ii. Ifthe value is less then or equal to zero, then throw a runtime_error with the message. .'\\].L_-.- i..- .'n I'M l I: iii. Otherwise, return the miles the user entered b. Create GetGallonsO function that returns double. i. If there is a stream error, then throw a mntime_crror with the message so.\" I lit Don't forget to clear the error and ignore all characters until the end of the stream. ii. Ifthe value is less than or equal to zero, then throw a runtime_error with the message. i..;i..\\.-_......--. lie was i|1.:n II iii. Otherwise, return the miles the user entered c. Create GetMPG(vector gallons) function that returns a double. i. Ifthe size of the vectors is 0, then throw a runtimegerror with the message mm..s.i..|,.n.m. ii. Otherwise, total the miles and gallons and return the miles per gallon. . 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 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 ifthe user did not enter any values. Then it should show the result. O Switch To Light Mode i. If the size of the vectors is 0, then throw a runtime_error with the message No values recorded MPG is nan ii. Otherwise, total the miles and gallons and return the miles per gallon. d. 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 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 "Enter a number : > number; if (cin. fail () ) { / / Clear error state cin . clear () ; // Ignore characters in stream until newline cin. ignore (numeric_limits : : max () , ' \ ' ) ; 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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions