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?
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....
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.
As a trainer, what would your role be in a self-directed learning program?
As a trainer, what would your role be in a self-directed learning program?
Respond to the following in a minimum of 175 words: It is important to program your...
Respond to the following in a minimum of 175 words: It is important to program your code efficiently. Efficient code manages errors and exceptions and cleans up memory after it ends. The try-except statements are helpful in handling errors that are detected during execution. What are the two categories of errors when debugging code? How can the try-except statements handle errors in Python? Provide a code example that supports your comments.
You are driving your car, and the traffic light ahead turns red. You apply the brakes...
You are driving your car, and the traffic light ahead turns red. You apply the brakes for 2.73 s, and the velocity of the car decreases to + 5.37 m/s. The car’s deceleration has a magnitude of 3.02 m/s2 during this time. What is the car’s displacement? x = A dynamite blast at a quarry launches a rock straight upward, and 1.8 s later it is rising at a rate of 10 m/s. Assuming air resistance has no effect on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT