Question

In: Computer Science

ASSIGNMENT 5 REQUIREMENTS The distance a vehicle travels can be calculated as follows: distance = speed...

ASSIGNMENT 5 REQUIREMENTS

The distance a vehicle travels can be calculated as follows:

distance = speed * time

For example, if a train travels 40 miles per hour for 3 hours,

the distance traveled is 120 miles.

Write a program that asks the user for the speed of a vehicle

(in miles per hour) and how many hours it has traveled.

The program should then use a loop to display the distance the

vehicle has traveled for each hour of that time period.

Here is an example of the output:

What is the speed of the vehicle in mph? 40

How many hours has it traveled? 3

Hour Distance Traveled

--------------------------------

1. 40

2. 80

3. 120

Input Validation:

Do not accept a negative number for speed and

do not accept any value less than 1 for time traveled.

=================================================================

TEST SET

============================

TEST CASE SPEED HOURS

1. 55 12

2. 65 10

3. 75 8

----------------------------

Solutions

Expert Solution

NOTE: Since programming language is not specified I am doing it in python. you  can easily convert it to any language logic is same.

SOLUTION:


##read the speed i have used float
speed=float(input("What if the speed of the vehicle in mph? "))

if(speed<0):
##for speed validation of speed that it should not be negative
speed=float(input("Enter speed greater than zero"))
  
time=float(input("How many hours has it traveled? "))
##read the time
if(time<1):
##this is for the input validation of the time that it should greater than zero
time=float(input("Enter time greater than zero"))

for i in range(int(time)):
##for calculating the distance after every hour
print("Distance after ",i+1," hour is ",speed*(i+1) )

if(time>int(time)):
## if time is 2.3 hours or in any float in the above loop we are calculating only for the integer part
##we are not calculating the float part for calculating that we are using this
print("Distance after ",time, " Hours is ",round(speed*time,2))

CODE IMAGE:

OUTPUT:


Related Solutions

The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For...
The distance a vehicle travels can be calculated as follows: Distance = Speed * Time For example, if a train travels 40 miles-per-hour for three hours, the distance traveled is 120 miles. Write a program that asks for the speed of a vehicle (in miles-per-hour) and the number of hours it has traveled. Both values are assumed to be integers. It should use a loop to display the distance a vehicle has traveled for each hour of a time period...
PROGRAM IN C++ The distance a vehicle travels can be calculated using the following equation: distance...
PROGRAM IN C++ The distance a vehicle travels can be calculated using the following equation: distance = speed * time For example, if a train travels 40 miles per hour for 3 hours, the distance traveled is 120 miles. Write a program that asks the user for the speed of a vehicle (in miles per hour) and how many hours it has traveled. The program should then use a loop to display the distance the vehicle has traveled for each...
Vehicle speed on a particular bridge in China can be modeled as normally distributed. If 5%...
Vehicle speed on a particular bridge in China can be modeled as normally distributed. If 5% of all vehicles travel less than 39.15 m/h and 10% travel more than 73.27 m/h, what are the mean and standard deviation of vehicle speed? What is the probability that a randomly selected vehicle's speed is between 50 and 65 m/h? What is the probability that a randomly selected vehicle's speed exceeds the speed limit of 70 m/h?
Vehicle speed on a particular bridge in China can be modeled as normally distributed? If 5%...
Vehicle speed on a particular bridge in China can be modeled as normally distributed? If 5% of all vehicles travel less than 39.18 m/h and 10% travel more than 73.27 m/h, what are the mean and standard deviation of vehicle speed? (Round your answers to three decimal places.) a) mean? standard deviation? b) What is the probability that a randomly selected vehicle's speed is between 50 and 65 m/h? (Round your answer to four decimal places.) c) What is the...
A 5 kg block starting with an initial velocity of 7.69 m/s travels a distance of...
A 5 kg block starting with an initial velocity of 7.69 m/s travels a distance of x m along a rough surface that has a coefficient of kinetic friction of μ=0.15. It then travels up a frictionless ramp at an angle of 17.0⁰ to a height of 1.38 m until it stops. How far does it travel along the rough surface - what is the x? (Note there may be more information provided in the problem statement than you need...
Vehicle speed on a particular bridge in China can be modeled as normally distributed. (a) If...
Vehicle speed on a particular bridge in China can be modeled as normally distributed. (a) If 5% of all vehicles travel less than 39.13 m/h and 10% travel more than 73.23 m/h, what are the mean and standard deviation of vehicle speed? (b) What is the probability that a randomly selected vehicle's speed is between 50 and 65 m/h? (c) What is the probability that a randomly selected vehicle's speed exceeds the speed limit of 70 m/h?
Vehicle speed on a particular bridge in China can be modeled as normally distributed. (a) If...
Vehicle speed on a particular bridge in China can be modeled as normally distributed. (a) If 5% of all vehicles travel less than 39.19 m/h and 10% travel more than 73.21 m/h, what are the mean and standard deviation of vehicle speed? (Round your answers to three decimal places.) mean standard deviation (b) What is the probability that a randomly selected vehicle's speed is between 50 and 65 m/h? (Round your answer to four decimal places.) (c) What is the...
The relationship between the speed of a car and its stopping distance can be modelled by...
The relationship between the speed of a car and its stopping distance can be modelled by the function D= 0.0575v2, where D is the stopping distance, in metres, and v is the speed, in kilometres per hour. a) Express the speed, v, as a function of D, in the form of y = af[k(x-d)] + c b) Explain the meaning of the inverse function. c) Graph each relation on separate axes. Label axes and title each graph. d) State the...
Open your Unit 5 assignment and identify the means and confidence intervals you calculated for male-at-rest...
Open your Unit 5 assignment and identify the means and confidence intervals you calculated for male-at-rest and female-at-rest. Use the 95% confidence intervals to determine if the resting male heart is the same as the resting female heart. Write the null hypothesis being tested and whether you reject the null hypothesis based on the comparison of confidence intervals. Heart rate before and after exercise       M=0 F=1   Resting    After Exercise 0   85.9    87.5 0   67.7    79.4 0  ...
How can I improve my code below to meet the requirements of this assignment with syntax...
How can I improve my code below to meet the requirements of this assignment with syntax add to my code to complete the assignment below: #include <iostream> #include <vector> using namespace std; class Inventory { private: int itemNumber; int quantity; double cost; double totalCost; public: Inventory() { itemNumber = 0; quantity = 0; cost = 0; totalCost = 0; } Inventory(int n, int q, double c) { itemNumber = n; quantity = q; cost = c; setTotalCost(); } void setItemNumber(int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT