Purpose. The purpose of this lab is to perform a calculation repetitively within a loop. The loop may be either a while loop or a for loop. You are to write a program that calculates the distance a vehicle has traveled in a certain number of hours. Write a program called vehicleTrip.cpp to calculate the distance traveled for a given speed. Requirements. 1. Using the following formula: distance rate * time = calculate how many miles a vehicle has travelled in a certain number of hours.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
**Distance Traveled, v 1.0**

**Purpose.** 
The purpose of this lab is to perform a calculation repetitively within a loop. The loop may be either a while loop or a for loop. You are to write a program that calculates the distance a vehicle has traveled in a certain number of hours. 

Write a program called `vehicleTrip.cpp` to calculate the distance traveled for a given speed.

**Requirements.**

1. Using the following formula: 

   \[
   \text{distance} = \text{rate} \times \text{time}
   \]

   calculate how many miles a vehicle has traveled in a certain number of hours.

2. Have the program ask the user for the speed of the vehicle (in miles per hour) and how many hours the vehicle has traveled. **Do not accept a negative number for the speed of the vehicle, and do not accept a value less than 1 for hours the vehicle has traveled.**

3. The program should use a loop to display the distance the vehicle has traveled for each hour of the time period that has been inputted.

**Program I/O.**

- **Input:** Speed of the vehicle (in miles per hour), and Number of hours the vehicle has traveled. The input values are shown colored in blue (the program you write does not need to use blue coloring for console input).

- **Output:** A table-like format that looks similar to this:

  ```
  What is the speed of the vehicle in mph?  40
  How many hours has it traveled?  3
  
  Hours   Distance Traveled
  ========================
  1        40
  2        80
  3       120
  ```

This output shows the distance traveled for each hour, multiplying the speed by the number of hours sequentially.
Transcribed Image Text:**Distance Traveled, v 1.0** **Purpose.** The purpose of this lab is to perform a calculation repetitively within a loop. The loop may be either a while loop or a for loop. You are to write a program that calculates the distance a vehicle has traveled in a certain number of hours. Write a program called `vehicleTrip.cpp` to calculate the distance traveled for a given speed. **Requirements.** 1. Using the following formula: \[ \text{distance} = \text{rate} \times \text{time} \] calculate how many miles a vehicle has traveled in a certain number of hours. 2. Have the program ask the user for the speed of the vehicle (in miles per hour) and how many hours the vehicle has traveled. **Do not accept a negative number for the speed of the vehicle, and do not accept a value less than 1 for hours the vehicle has traveled.** 3. The program should use a loop to display the distance the vehicle has traveled for each hour of the time period that has been inputted. **Program I/O.** - **Input:** Speed of the vehicle (in miles per hour), and Number of hours the vehicle has traveled. The input values are shown colored in blue (the program you write does not need to use blue coloring for console input). - **Output:** A table-like format that looks similar to this: ``` What is the speed of the vehicle in mph? 40 How many hours has it traveled? 3 Hours Distance Traveled ======================== 1 40 2 80 3 120 ``` This output shows the distance traveled for each hour, multiplying the speed by the number of hours sequentially.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

The program should only use one loop, not two. It can be either a while loop or a for loop, but should one loop.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

The program doesn't work properly. if we  input 40 for the first question (What is the speed of the vehicle in mph?)  and 3 for the second ( How many hours has it traveled?). The ouput should be something 1 40 , which is not. 
                                                                     2 80
                                                                    3 120

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Types of Loop
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education