Advanced Programming Worksheet With Answers - Jamal Alskran, King Abdullah Ii School For Information Technology - 2012

ADVERTISEMENT

King Abdullah II School for Information Technology
Computer Science Department
Advanced Programming
Programming Homework #1
Instructor: Dr. Jamal Alsakran
Due Date: Wednesday 24/10/2012
Chapter 10: Exercise 14: Page 706:
The equation of a line in standard form is ax + by = c, wherein both a and b cannot be zero, and a, b, and c are
real numbers. If b ≠ 0, then –a/b is the slope of the line. If a = 0, then it is a horizontal line, and if b = 0, then
it is a vertical line. The slope of a vertical line is undefined. Two lines are parallel if they have the same slope
or both are vertical lines. Two lines are perpendicular if either one of the lines is horizontal and the other is
vertical or the product of their slopes is -1. Design the class lineType to store a line. To store a line, you need
to store values of a (coefficient of x), b (coefficient of y), and c. Your class must contain the following
operations:
a. If a line is nonvertical, then determine its slope.
b. Determine if two lines are equal. (Two lines a
x + b
y = c
and a
x + b
y = c
are equal if either a
=
1
1
1
2
2
2
1
a
, b
= b
, and c
= c
or a
= ka
, b
= kb
, and c
= kc
for some real number k).
2
1
2
1
2
1
2
1
2
1
2
c. Determine if two lines are parallel.
d. Determine if two lines are perpendicular.
e. If two lines are not parallel, then find the point of intersection.
Add appropriate constructors to initialize variables of lineType. Also write a program to test your class.
Operation you need to implement:
a. Constructor: initializes variables
b. Slope: returns the slope of a line
c. IsVertical: checks if a line is vertical or not
d. IsHorizontal: checks if a line is horizontal or not
e. Equal: determines if two lines are equal
f. Parallel: determines if two lines are parallel
g. Perpendicular: determines if two lines are perpendicular
h. Intersection: finds the intersection point of two lines (x, y).
x = ((-c
/b
) – (-c
/b
)) / ((-a
/b
) – (-a
/b
))
2
2
1
1
1
1
2
2
y = (-a
/b
) * x + (-c
/a
)
1
1
1
1
Submission:
Files to be submitted: main.cpp, lineType.cpp, and lineType.h.
Email me the files at ().
In the subject line write: AP-Your Student ID- First Name-Last Name

ADVERTISEMENT

00 votes

Related Articles

Related forms

Related Categories

Parent category: Education
Go