Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ and complete the assignment by following the format for the examples as closely as possible: Assignment You will be creating a program that

Use C++ and complete the assignment by following the format for the examples as closely as possible:image text in transcribedimage text in transcribedimage text in transcribed

Assignment You will be creating a program that calculates a fleet's car and truck miles per gallon. Create a program that continually asks for a command, which will be "car", "truck", or "done". If the user does not specify one of these commands, output "Unknown command." If the user types "done", calculate the average miles per gallon of all of the given cars and calculate the average miles per gallon of all of the given trucks. If the user did not provide any cars, output "Fleet has no cars." If the user did not provide any trucks, output "Fleet has no trucks." Otherwise, output "Average car MPG "and "Average truck MPG-" If the user types "truck" or "car", then ask the user for the number of miles and number of gallons of fuel used on either the truck or car. This will be a running total. You will need to store the total number of miles, total number of gallons, and total number of cars and trucks. You must also make a check to ensure the user gives you proper input. If improper input was given, keep asking the user to give you legitimate values until they comply (see examples below) Examples ./lab4 Enter command: car Enter car's miles: 255 Enter car's gallons: 13 Enter command: car Enter car's miles: 715 Enter car's gallons: 33 Enter command: truck Enter truck's miles: 477 Enter truck's gallons: 22 Enter command: done Average car MPG-21.087 Average truck MPG 21.6818 ./lab4 Enter command: done Fleet has nocars. Fleet has no trucks. ./lab4 Enter command: car Enter car's miles: 177.25 Enter car's gallons: 22.182 Enter command: done Average car MPG -7.99071 Fleet has no trucks ./Lab4 Enter command: car Enter car's miles: z41 Enter car's miles: kcc Enter car's miles: 1lkaj Enter car's miles: m81 Enter car's miles: 18.2lkjalj Enter car's gal Lons: Enter car's galLons: nss Enter car's gallons: ooslei.83 Enter car's gallons: p Enter car's gallons: 22.15 Enter command: ca Unknown command Enter command: d Unknown command. Enter command: done Average car MPG-0.82167 Fleet has no trucks Hints 1. car, truck, and done are the only commands accepted. Car is not a valid command, and neither is Truck. 2. You do not need to strip off the end of a valid number, such as 18.2dz. The extraction operator will extract 18.2 and leave dz in the stream, which will need to be ignored later since it will try to match the next command

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

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions