Programming Exercise 2
Decision Making
1. Write a program that performs the following calculations and checks:
Assume that we specify two points in the place with the declaration double
x1,y1, x2,y2; Determine and print
- ...the distance between these points
- ...the slope of the line from the first point to the second
- ...whether both points lie on the same line from the origin
- ...whether the first point is above the second
- ...what quadrant the first point lies in (1st, 2nd, 3rd, or 4th)
- ...whether the two points lie in the same quadrant
2. Write a program that performs the following calculations and checks:
Assume that specify an interval by a pair of int values (the
ones at the beginning and end of the interval in the place with the
declaration): 5 and 8 would specify the interval containing the
numbers 5, 6, 7, and 8 inclusive. We declare int
b1,e1, b2,e2; to represent the beginning and end of two intervals, and int
x; so represent some value. Note that we will guarantee that the intervals
are "well formed": b1 <= e1 and b2 <= e2.
- Compute and print the number of integer values in an interval beginning
with b1 and ending with e1.
- Determine and print whether...
- ...x is inside the first interval
- ...x is not inside the first interval
- ...x is inside the first interval but not the second
- ...x is inside either the first or second interval (or both)
- ...x is inside either the first or second interval (but not
both)
- Determine and print whether...
- ...the first interval is the same as the second
- ...the first interval ends before the second one begins
- ...the first interval ends on the same value as the second one begins
- ...the first interval is inside the second one
- ...the first interval and the second interval overlap (at least one
common value)
- ...the first interval and the second interval do not overlap (no
common values)