Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The distance a vehicle travels can be calculated as follows: Distance = Speed *

ID: 3815858 • Letter: T

Question

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. Create an algorithm, flowchart, and pseudocode for a program that asks for the speed of a vehicle (in miles-per-hour) and he number of hours it has traveled. It should use a loop to display the distance a vehicle has traveled for each hour of time period specified by the user. For example, if a vehicle is traveling at 40 mph for a three hour period, it should display a report similar to the one that follows:

Hour Distance Traveled

1 40

2 80

3 120

Explanation / Answer

#include <iostream>

using namespace std;

int main()
{
int speed, hours;
cout << "Enter the speed of the vehicle: ";
cin >> speed;
cout<<"Enter the number of hours travelled: ";
cin >> hours;
cout<<"Hour Distance Traveled"<<endl;
for(int i=1; i<= hours; i++){
cout<<i<<" "<<(i * speed)<<endl;
}

return 0;
}

Output:

sh-4.2$ g++ -o main *.cpp                                                                                                                                                                                                                                              

sh-4.2$ main                                                                                                                                                                                                                                                           

Enter the speed of the vehicle: 40                                                                                                                                                                                                                                     

Enter the number of hours travelled: 3                                                                                                                                                                                                                                 

Hour    Distance Traveled                                                                                                                                                                                                                                              

1       40                                                                                                                                                                                                                                                             

2       80                                                                                                                                                                                                                                                             

3       120

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote