Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The distance travelled by a vehicle can be calculated as follows: distance = speed * time For example, if a car travels 4 0 kilometres

The distance travelled by a vehicle can be calculated as follows:
distance = speed * time
For example, if a car travels 40 kilometres per hour for 3 hours, the total distance travelled is 120km. Complete the C++ program below, which asks the user for the speed of a vehicle (in kilometres per hour) and the number of hours it has been travelling. The program should then use a loop to display the distance travelled by the vehicle during each hour of that time period. Here are some examples of the output:
Example 1:
What is the speed of the vehicle in kmh?-60
Please enter a non-negative number for speed: 140
For how many hours has it travelled? 2
Example 2:
What is the speed of the vehicle in km/h?-5
Please enter a non-negative number for speed: -60
Please enter a non-negative number for speed: 90
For how many hours has it travelled? 0
Please enter a 1 or greater for hours: -1
Please enter a 1 or greater for hours: 4
Example 3:
What is the speed of the vehicle in kmh?110
For how many hours has it travelled? 0
Please enter a 1 or greater for hours: 3
Hour Distance Travelled in km
\table[[1,110],[,220],[,330]]
The bold text in the above output represents user input. Input validation: Do not accept negative numbers for speed or any value less than 1 for time travelled.
image text in transcribed

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

Joe Celkos Data And Databases Concepts In Practice

Authors: Joe Celko

1st Edition

1558604324, 978-1558604322

More Books

Students also viewed these Databases questions