0% found this document useful (0 votes)
5 views4 pages

Problem Set #1

This document outlines Problem Set #1 for a C++ course, focusing on calculating Manhattan and Euclidean distances between two points. It includes details on collaboration policies, programming requirements, and specific tasks to be completed, such as user input handling and output formatting. The hand-in procedure specifies saving the code as 'ps1.cpp' and submitting it via the CANVAS website.

Uploaded by

pokedex511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Problem Set #1

This document outlines Problem Set #1 for a C++ course, focusing on calculating Manhattan and Euclidean distances between two points. It includes details on collaboration policies, programming requirements, and specific tasks to be completed, such as user input handling and output formatting. The hand-in procedure specifies saving the code as 'ps1.cpp' and submitting it via the CANVAS website.

Uploaded by

pokedex511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Problem Set #1

Points: 75
Handed out: 9/1/20
Due 11:59pm: 9/8/20

Introduction
This problem set will introduce you to arithmetic and C++ libraries. In this problem set, you will use variables to store data
input by a user, perform arithmetic on the data contained within the variables, and output your findings using the terminal. Be
sure to read this problem set thoroughly, especially the sections of Collaboration and the Hand-in Procedure.

Collaboration
Collaboration amongst students is allowed to the extent outlined in the syllabus. That being the case, the goal of these
assignments is not to share code, but to learn the tools you need to succeed as a computer scientist. Students are expected to
write their own code free of plagiarism from any other student past or current. All assignments will be cross referenced across
all sections of CS135 using the Measure Of Software Similarity (Moss) to automatically determine the similarity of programs.
Refer to the syllabus for further details and consequences of breaking this policy.

Program: Airport Distance

Problem 1
You are working with an airplane company to develop some software for their flight systems. The first thing the company wants
to know is how far their airplanes are from their airports. This can easily be broken down to the problem of finding the distance
between the two points. You work with the airplane company to develop a plan to find the Manhattan distance 1 between each
airport. The Manhattan distance is the distance between points measured along axes at right angles. A way to think of it is like
measuring how many squares away a piece is from another in checkers/chess. It is called the Manhattan distance because the
line you can build to get from point a to b looks like a routing through Manhattan. Write a program that:
1. Prompts the user to enter two (x, y) points as integers and casts them to doubles.
2. Calculates the manhattan distance between the entered two points.

The equation for manhattan distance is:

𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚𝑚 = |𝑥𝑥2 − 𝑥𝑥1| + |𝑦𝑦2 − 𝑦𝑦1|


Note: You will need to use the abs(int n)2 function from the cmath library for this equation.

To check that this problem is complete, verify your program is printing as shown in the example output.

1
https://en.wikipedia.org/wiki/Taxicab_geometry
2
http://www.cplusplus.com/reference/cstdlib/abs/
Problem 2
Once you are finished with the manhattan distance calculations the company comes back to you and requests that you add
euclidean distance 3 to the program. They tell you that they need it added because euclidean distance is more accurate since
airplanes do not have to avoid buildings like cars do, but they still want to keep the manhattan distance calculations as they are
very useful in many situations. Add to your program:
1. The ability to calculate the euclidean distance between the entered two points.

The equation for euclidean distance is:

𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒𝑒 = �(𝑥𝑥2 − 𝑥𝑥1 )2 + (𝑦𝑦2 − 𝑦𝑦1 )2

Note: You will need to use the sqrt(double x)4 and pow(double base, double exponent) 5 functions from the cmath library for
this equation.

To check that this problem is complete, verify your program is printing as shown in the example output.

Problem 3
Now that you have found the distance between two points in multiple ways it is time to display your results to the screen so
your associates at the airplane company can easily see the results of the calculations they want to perform. Add functionality to
your program that:
1. Outputs the numbers you computed formatted exactly as shown below.

To check that this problem is complete, verify your program is printing as shown in the example output.

3
https://en.wikipedia.org/wiki/Euclidean_distance
4
http://www.cplusplus.com/reference/cmath/sqrt/
5
http://www.cplusplus.com/reference/cmath/pow/
Example Output
An example of an interaction with your program is shown below. Your output must match this output exactly. (The words
printed in blue are from the computer, based on your commands, the words in red are user input. Note: these colors are simply
here to distinguish components and not needed in your program.):
Problem 1
Alexs-iMac:PS1 alex$ ./a.out
Enter a x1 value:
**0
Enter a y1 value:
**0
Enter a x2 value:
**5
Enter a y2 value:
**5
Manhattan Distance: 10
Problem 2
Alexs-iMac:PS1 alex$ ./a.out
Enter a x1 value:
**0
Enter a y1 value:
**0
Enter a x2 value:
**5
Enter a y2 value:
**5
Manhattan Distance: 10
Euclidean Distance: 7.07107
Problem 2
Alexs-iMac:PS1 alex$ ./a.out
Enter a x1 value:
**2
Enter a y1 value:
**2
Enter a x2 value:
**7
Enter a y2 value:
**10
Manhattan Distance: 13
Euclidean Distance: 9.43398

Hand-In Procedure

1. Save
Save your code as ps1.cpp. Do not ignore this step or save your file(s) with different names.
2. Submit
Your program source code must be submitted via the CANVAS class website as a .cpp file.

You might also like