// Sample program for CS149. v. 10/6/00 // // // Program determines whether or not 4 pts define a parallelgoram. // // To make things simplier, we assume points are given in // clockwise order, so we know which slopes to compare. #include #include #include int main() { // Define and initialize variables. double x1, y1, x2, y2, x3, y3, x4, y4, slope_1, slope_2, slope_3, slope_4; // Define points. x1 = 0; y1 = 0; x2 = 4; y2 = 0; x3 = 4; y3 = 2; x4 = 0, y4 = 2; // Compute slopes. slope_1 = (y2-y1)/(x2-x1); slope_2 = (y3-y2)/(x3-x2); slope_3 = (y4-y3)/(x4-x3); slope_4 = (y4-y1)/(x4-x1); // Check for equal slopes of opposite sides. if ( (slope_1 == slope_3 ) && (slope_2 == slope_4 ) ) cout << "This is a parallelogram." << endl; else cout << "This is not a parallelogram. << endl; // Define points. x1 = 0; y1 = 0; x2 = 5; y2 = 0; x3 = 4; y3 = 2; x4 = 0, y4 = 2; // Compute slopes. slope_1 = (y2-y1)/(x2-x1); slope_2 = (y3-y2)/(x3-x2); slope_3 = (y4-y3)/(x4-x3); slope_4 = (y4-y1)/(x4-x1); // Check for equal slopes of opposite sides. if ( (slope_1 == slope_3 ) && (slope_2 == slope_4 ) ) cout << "This is a paral." << endl; else cout << "This is not a rectangle." << endl; // Define points. x1 = 1; y1 = 0; x2 = 2; y2 = 1; x3 = 1; y3 = 2; x4 = 0, y4 = 1; // Compute slopes. slope_1 = (y2-y1)/(x2-x1); slope_2 = (y3-y2)/(x3-x2); slope_3 = (y4-y3)/(x4-x3); slope_4 = (y4-y1)/(x4-x1); // Check for equal slopes of opposite sides. if ( (slope_1 == slope_3 ) && (slope_2 == slope_4 ) ) cout << "This is a rectangle" << endl; else cout << "This is not a rectangle." << endl; // Exit program. return EXIT_SUCCESS; }