Question

In: Computer Science

Your team was asked to program a self-driving car that reaches its destination with minimum travel...

Your team was asked to program a self-driving car that reaches its destination with minimum travel time.

Write an algorithm for this car to choose from two possible road trips. You will calculate the travel time of each trip based on the car current speed and the distance to the target destination. Assume that both distances and car speed are given.

Solutions

Expert Solution

Here is the solution if you have any doubt then please write in the comment section.

Please give feedback.

If there will be same speed for both routes then we are not required to calculate time because the route which have less distance will be chosen automatically.

Algorithm:

  1. START
  2. Declare 4 double variables firstDistance,secondDistance,firstSpeed,secondSpeed.
  3. Input the 4 numbers, firstDistance,secondDistance,firstSpeed,secondSpeed respectively.
  4. Declare 2 double variables firstTime,secondTime.
  5. Divide firstDistance by firstSpeed and store in firstTime similarly Divide secondDistance by secondSpeed and store in secondTime
  6. If firstTime is less than secondTime then goto step 7 else goto step 8
  7. Print the value of variable firstTime and message "Choose Route first" and goto step 9
  8. Print the value of variable secondTime and message "Choose Route second"
  9. END

I am also writing the program for better understanding.

Program in C++

I have written comments for better understanding.



#include <iostream>

using namespace std;

int main()
{
    //Declare 4 double variables firstDistance,secondDistance,firstSpeed,secondSpeed
   double firstDistance,secondDistance,firstSpeed,secondSpeed;
   //Input the 4 numbers, firstDistance,secondDistance,firstSpeed,secondSpeed respectively
   cin>>firstDistance>>secondDistance>>firstSpeed>>secondSpeed;
   //Declare 2 double variables firstTime,secondTime
   double firstTime,secondTime;
   //Divide firstDistance by firstSpeed and store in firstTime
   firstTime=firstDistance/firstSpeed;
   //Divide secondDistance by secondSpeed and store in secondTime
   secondTime=secondDistance/secondSpeed;
   //If firstTime is less than secondTime then 
   if(firstTime<secondTime)
   {
       cout<<"Time Taken by first route is:"<<firstTime<<" So Choose Route first";
   }
   //otherwise
   else
   {
       cout<<"Time Taken by second route is:"<<secondTime<<" So Choose Route second";
   }
    return 0;
}

Output:

If you have any type of doubts then please write in the comment section, I will feel happy to help you.

Please give feedback.

Thank You!


Related Solutions

MARKETING! Google is developing a self-driving car that will be in the marketplace in the near...
MARKETING! Google is developing a self-driving car that will be in the marketplace in the near future. Identify a potential market segment and describe the value proposition that would meet the needs of this target customer group. What need is being fulfilled? What benefits are being sought?
With regard to the self-driving car, and the research conducted by the Moral Machine project; provide...
With regard to the self-driving car, and the research conducted by the Moral Machine project; provide your own ranking for the following (1= most important to save; 9= least important to save).                                                                                         # Ranking Category Sparing the young Sparing the fit Inaction (doing nothing) Sparing the most (#) people Sparing the lawful Sparing humans over animals Sparing pedestrians Sparing women Sparing people of higher social status Which group did you prioritize as most important? Which group was the...
If you needed to compare two simulated scenarios, and in one of them a self-driving car...
If you needed to compare two simulated scenarios, and in one of them a self-driving car is braking up to -3 meters per second squared, in another up to -8 meters per second squared (unit of acceleration), which one do you think is more risky? Please explain your answer or how you arrived to this conclusion.
You are in your car A on the 407 driving at a constant velocity ~vA =...
You are in your car A on the 407 driving at a constant velocity ~vA = (vA, 0, 0) and next to it another car (B) takes the exit ramp on one of Toronto’s huge exchangers to get onto the 404. For consistency we set the two cars to start at (0, 0, 0) at t = 0 and car B turns in the positive y direction. The exchanger can be seen as a quarter circle of radius R. 1....
What are some important ethical concerns with self-driving cars? a minimum two page double spaced response...
What are some important ethical concerns with self-driving cars? a minimum two page double spaced response is required please
You are thinking of buying a used car for $4,000 for driving to school. Your parents...
You are thinking of buying a used car for $4,000 for driving to school. Your parents are willing to lend you the $4,000 and charge only 2.4% APR. They want the loan repaid equally in 48 monthly payments, with the first payment due at the end of the month in which you buy the car. You estimate that the monthly cost of operating the car, including gas, insurance, maintenance and licence fees will be $200 and payable at the start...
Driving in your car with a constant speed of 12 m/s, you encounter a bump in...
Driving in your car with a constant speed of 12 m/s, you encounter a bump in the road that has a circular cross section, as indicated in the figure. If the radius of curvature of the bump is r = 31 m, find the apparent weight of a 54-kg person in your car as you pass over the top of the bump. N
If your team was asked to consult for a large volume bricks and mortar bookstore, such...
If your team was asked to consult for a large volume bricks and mortar bookstore, such as Chapters, which corporate strategies would you recommend to the company’s senior leadership?
1. GLS Chapter 7, Question 13: True or false: Average variable cost reaches its minimum point...
1. GLS Chapter 7, Question 13: True or false: Average variable cost reaches its minimum point at a lower level of output than average total costs. Explain your answer, using a graph of average and marginal costs to illustrate.
Your team will make a modification of the program #1 above, that will read in the...
Your team will make a modification of the program #1 above, that will read in the string as a “command-line argument” to your program, instead ofhaving the user type it while your program is running. Your program should print out the inverted string to the screen. For example, if you are running your program in the command window (by clicking the Start button, then typing in “cmd”, then pressing Enter, then using the “cd ” command to change to the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT