Distance traveled. A vehicle is to travel on demand. Its initial location is given as x0, y0 (assur the first statement in your program as assigning initial values, say x0,y0 = 5.0, 5.0). Repeated take as input the distance the vehicle has to travel. If the input given is 0 or lesser, the travel ends - assume that at least one positive distance will be given. The direction in which the vehicle is to travel is determined as follows: if distance is <= 25 it travels north, if between 26- it travels south, between 51 and 75 it travels east, and >= 76 it travels west. Find the final coordinate of the vehicle, the total distance it has traveled, and the straight line distance between the initial location and the final location (use standard formula for distance between t coordinates; note that this distance is not same as total distance traveled).

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. A vehicle is to travel on demand. Its initial location is given as x0, y0 (assume
the first statement in your program as assigning initial values, say x0,y0 = 5.0, 5.0). Repeatedly
take as input the distance the vehicle has to travel. If the input given is 0 or lesser, the travel
ends - assume that at least one positive distance will be given. The direction in which the
vehicle is to travel is determined as follows: if distance is <= 25 it travels north, if between 26-50
it travels south, between 51 and 75 it travels east, and >= 76 it travels west. Find the final
coordinate of the vehicle, the total distance it has traveled, and the straight line distance
between the initial location and the final location (use standard formula for distance between two
coordinates; note that this distance is not same as total distance traveled).
Hint: Initialize current coordinates x,y to x0,y0, and distance traveled to 0. For taking the
distance use a while loop (as you dont know how many distances will be given). This can be
done in two ways - you can initialize a variable (say dist) to some +ve value, and then loop till
the value is 0 (or lesser) and in the loop get the input from the user for next distance.
Alternatively, you can have an infinite while loop, and take input in the loop and break if the
input given is 0 (or lesser). For each input distance, determine the new coordinates, and keep
track of total distance traveled. After the loop is done, compute the distance also.
Transcribed Image Text:Distance traveled. A vehicle is to travel on demand. Its initial location is given as x0, y0 (assume the first statement in your program as assigning initial values, say x0,y0 = 5.0, 5.0). Repeatedly take as input the distance the vehicle has to travel. If the input given is 0 or lesser, the travel ends - assume that at least one positive distance will be given. The direction in which the vehicle is to travel is determined as follows: if distance is <= 25 it travels north, if between 26-50 it travels south, between 51 and 75 it travels east, and >= 76 it travels west. Find the final coordinate of the vehicle, the total distance it has traveled, and the straight line distance between the initial location and the final location (use standard formula for distance between two coordinates; note that this distance is not same as total distance traveled). Hint: Initialize current coordinates x,y to x0,y0, and distance traveled to 0. For taking the distance use a while loop (as you dont know how many distances will be given). This can be done in two ways - you can initialize a variable (say dist) to some +ve value, and then loop till the value is 0 (or lesser) and in the loop get the input from the user for next distance. Alternatively, you can have an infinite while loop, and take input in the loop and break if the input given is 0 (or lesser). For each input distance, determine the new coordinates, and keep track of total distance traveled. After the loop is done, compute the distance also.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Constants and Variables
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