Hello, I have been trying to get this program to work. It is supposed to
take 8 inputs, 4 x values, 4 y values, and identify the quadrilateral. I
have not been able to get it to work. Can anyone identify the problem
and offer a solution? Thanks!
Its not very long, so I pasted it here and included the .rb file.
=========
START CODE
#Set variables
shape = “polygon”
#BEGIN USER INPUT
puts “Enter point A, X value”
xA = gets.chomp().to_i #converts input to integer
puts “Enter point A, Y value”
yA = gets.chomp().to_i #converts input to integer
puts “Enter point B, X value”
xB = gets.chomp().to_i #converts input to integer
puts “Enter point B, Y value”
yB = gets.chomp().to_i #converts input to integer
puts “Enter point C, X value”
xC = gets.chomp().to_i #converts input to integer
puts “Enter point C, Y value”
yC = gets.chomp().to_i #converts input to integer
puts “Enter point D, X value”
xD = gets.chomp().to_i #converts input to integer
puts “Enter point D, Y value”
yD = gets.chomp().to_i #converts input to integer
#END USER INPUT
#BEGIN SLOPE CALCULATIONS
slopeAB = yB-yA/xB-xA #calculates slope of side AB
slopeBC = yC-yB/xC-xB #calculates slope of side BC
slopeCD = yD-yC/xD-xC #calculates slope of side CD
slopeDA = yA-yD/xA-xD #calculates slope of side DA
#END SLOPE CALCULATIONS
#BEGINE SIDE-LENGTH CALCULATIONS
lengthAB = Math.sqrt((xB-xA)**2+(yB-yA)**2) #calculates length of
AB
lengthBC = Math.sqrt((xC-xB)**2+(yC-yB)**2) #calculates length of
BC
lengthCD = Math.sqrt((xD-xC)**2+(yD-yC)**2) #calculates length of
CD
lengthDA = Math.sqrt((xA-xD)**2+(yA-yD)**2) #calculates length of
DA
#END SIDE-LENGTH CALCULATIONS
#BEGIN MIDPOINT CALCULATIONS
midPointACx = (xA+xC)/2 #averages x of A and C
midPointACy = (yA+yC)/2 #averages y of A and C
midPointBDx = (xB+xD)/2 #averages x of B and D
midPointBDy = (yB+yD)/2 #averages y of B and D
#END MIDPOINT CALCULATIONS
#END DIAGONAL LENGTH CALCULATIONS
lengthMidAC = Math.sqrt((xC-xA)**2+(yC-yA)**2) #calculates
length of diagonal AC
lengthMidBD = Math.sqrt((xD-xB)**2+(yD-yB)**2) #calculates
length of diagonal BD
#END DIAGONAL LENGTH CALCULATIONS
#BEGIN QUADRILATERAL IDENTIFICATION
#Identifies if quadrilateral has two pairs of parallel sides
if (slopeAB == slopeCD) and (slopeBC == slopeDA)
shape = “parallelogram”
else
shape = shape
end
#Identifies if quadrilateral diagonals are congruent
if (shape == “parallelogram”) and (lengthMidAC == lengthMidBD)
shape = “rectangle”
elsif (shape == “parallelogram”) and (lengthMidAC != lengthMidBD)
shape = “parallelogram”
else
shape = shape
end
#Determines if shape is a kite or not
if (lengthAB == lengthBC) and (lengthCD == lengthDA)
shape = “kite”
else
shape = shape
end
#If shape is trapezoid, identifies if shape is isosceles trapezoid
if (shape == “trapezoid”) and (lengthMidAC == lengthMidBD)
shape = “isosceles trapezoid”
else
shape = shape
end
#Identifies if shape has four congruent sides
if (lengthAB == lengthBC) and (lengthCD == lengthDA) and (lengthAB ==
lengthCD) and (lengthBC == lengthDA) and (lengthDA == lengthAB)
shape = “rhombus”
else
shape = shape
end
#But is it square?
if (shape == “rhombus”) and (slopeCD == (1-2/slopeDA)) and (slopeAB ==
(1-2/slopeCD))
shape = “square”
else
shape = shape
end
puts “=====================================”
puts “=====================================”
puts "Your quadrilateral is a " + shape
puts “=====================================”
puts “=====================================”
puts slopeAB
puts slopeBC
puts slopeCD
puts slopeDA