Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 - distances Consider the concept of distance in two-dimensional space. In an algebra class, you may have encountered the following formula for the

image text in transcribedimage text in transcribed
Part 1 - distances Consider the concept of distance in two-dimensional space. In an algebra class, you may have encountered the following formula for the distance between two points (x1 . y1) and (X2 , y2): dPythagorean = \\ (x2 - 21)2 + (12 - y1)2 Recall that we learned about the built-in pow() and sqrt() functions in the library in C++. Another useful distance to define is the Manhattan distance - also known as the city block distance. The following image contains 3 examples of "city block paths" in red, blue, and yellow. Notice that the city block distance is the same for these three paths. Consider the red path, for instance. It travels 6 blocks north and then 6 blocks east for a total of 12 blocks. And the yellow path covers 5 blocks east, 2 blocks north, 1 block east, and 4 blocks north (5 + 2 + 1 + 4 = 12). The equation used to calculate city block distances is as follows: dCity Block = (2:2 - 21) + (12 - 91) For example, suppose that you define the position of the lower left black dot (starting point) as (x1, y1) = (0, 0). With this origin, it would make sense to define the position of the end point as (x2, y2) = (6, 6). Substitute these values into the equation above to obtain: dCity Block = (6 - 0) + (6 -0) =6 1 6 = 12 The green path ("as the crow flies") could be called a "Pythagorean path", and the distance it covers can be calculated with the first equation above. dPythagorean = V (6 -0)2 + (6 -0)2 = V36 + 36 8.49Instructions for part 1: Use the pow() and sqrt() functions to calculate the Pythagorean distance between a pair of points. Find the Manhattan distance as well. Use the setprecision() function to display these distances to two decimal places. You can use the points above [(0, 0) and (6, 6)] and verify the results, or you can get creative. For your interest: Dijkstra's algorithm is a somewhat-related problem that finds the shortest distance between two points (called "nodes" in computer science jargon). Examples of the (theoretical) usefulness of this algorithm include GPS navigation (as in Google Maps directions) and network routing protocols. You are likely to study this algorithm in some detail in COSC 2436 at TJC or in a junior/senior level class on network theory. Part 2 - lengths In informal communication, the words "distance" and "length" are sometimes used interchangeably. In the second part of this project, we are referring to a particular usage of length - the total number of characters in a string (ie - the length of a sequence of characters). Instructions for part 2: Twitter has a current character limit (string length) of 280 characters. 1) Use the getline() function to save a Tweet (that you type into the console) as a string variable. 2) Use the length() function to determine if this string exceeds Twitter's limit. (You can verify this on their app or website, if you like). 3) Write the string and its length to an output file

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions