Professional Documents
Culture Documents
2431130
CSCI 1205.001
Introduction to Programming in C++
Summer 2013
HOMEWORK NO. 1
1. PROBLEM STATEMENT
Get the xy coordinates of two points from the user, and then compute the distance
between the two points by using the distance formula derived from the Pythagorean Theorem.
2. INPUT/OUTPUT DESCRIPTION
The user will be prompted to supply two xy coordinate pairs in the form of integers or
decimal approximations of rational numbers, and both positive and negative numbers will be
considered valid input. The output will be either an integer or decimal approximation.
3. HAND EXAMPLE
We give the coordinates of two points to be P1(0.0, 5.0) and P2(-1.0, 6.5). We calculate
the sides from the points given and use the values for the sides to calculate the distance between
the two points.
Side1= x2 - x1 = -1.0
Side2= y2 - y1= 1.5
Distance = square root[ (Side1)2 + (Side2)2 ]
= 1.80278
4. ALGORITHM DEVELOPMENT
Our variables will be:
Double
Double
Double
Double
x1
y1
x2
y2
Double side1
//first side of
the right
triangle
//formed by the user supplied coordinates
Double side2
//second side of the right triangle //formed
by the user supplied coordinates
Double distance //the length of the hypotenuse of the //right
triangle formed by our points and calculated sides
First we will prompt the user to enter two coordinate pairs. We will then compute the sides of
the right triangle formed by the coordinates. Based on the result of this calculation, we can then
determine the distance between the two supplied points.
5. TESTING
Test data
P1 (4.5,2.0)
P2 (3.25,-4.2)
Expected result: 6.32475
Actual result: 6.32475
6. CONCLUSION
I have learned how to prompt for and accept user input. I have also become more
familiar with the input/output syntax of C++.