Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter5: Control Structures Ii (repetition)
Section: Chapter Questions
Problem 27PE
icon
Related questions
Question

polymorphism java

Problem 1. Vehicles
Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in
the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given
distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel
consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny
hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and
adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change.
Input
• On the first line - information about the car in format {Car (fuel quantity} {liters per km}}
• On the second line- info about the truck in format (Truck {fuel quantity} {liters per km}}
• On third line - number of commands N that will be given on the next N lines
• On the next N lines - commands in format
• Drive Car {distance}
• Drive Truck (distance)
• Refuel Car (liters}
• Refuel Truck (liters}
Output
After each Drive command print whether the Car/Truck was able to travel given distance in format if it's successful.
Print the distance with two digits after the decimal separator except trailing zeros.
Car/Truck travelled {distance} km
Orif it is not:
Car/Truck needs refueling
Finally print the remaining fuel for both car and truck:
Car: {liters}
Truck: {liters}
Example #1
Input
Output
Car travelled 9 km
Car 15 e.3
Truck 100 e.9
Car needs refueling
Truck travelled 10 km
4
Drive Car 9
Drive Car 30
Car: 54.20
Truck: 75.00
Refuel Car 50
Drive Truck 10
Transcribed Image Text:Problem 1. Vehicles Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change. Input • On the first line - information about the car in format {Car (fuel quantity} {liters per km}} • On the second line- info about the truck in format (Truck {fuel quantity} {liters per km}} • On third line - number of commands N that will be given on the next N lines • On the next N lines - commands in format • Drive Car {distance} • Drive Truck (distance) • Refuel Car (liters} • Refuel Truck (liters} Output After each Drive command print whether the Car/Truck was able to travel given distance in format if it's successful. Print the distance with two digits after the decimal separator except trailing zeros. Car/Truck travelled {distance} km Orif it is not: Car/Truck needs refueling Finally print the remaining fuel for both car and truck: Car: {liters} Truck: {liters} Example #1 Input Output Car travelled 9 km Car 15 e.3 Truck 100 e.9 Car needs refueling Truck travelled 10 km 4 Drive Car 9 Drive Car 30 Car: 54.20 Truck: 75.00 Refuel Car 50 Drive Truck 10
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Processes of 3D Graphics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr