Homework 2 Solutions
Problem 3
PROGRAM TRINGL
************************************************************************
* *
* Program to determine the area and length of a hypotenuse for a right *
* triangle if given the lengths of the two legs. Variables used are: *
* LEG1 = length of the first leg *
* LEG2 = length of the second leg *
* AREA = area of the right triangle *
* HYP = length of the hypotenuse *
* *
* *
* Input: LEG1, LEG2 *
* Output: AREA, HYP *
************************************************************************
REAL LEG1, LEG2, AREA, HYP
* obtain lengths of legs one and two
PRINT *, 'INPUT LENGTH OF LEG ONE AND LEG TWO'
READ *, LEG1, LEG2
* calculation of area
AREA = .5*LEG1*LEG2
* calcuation of the hyponetuse
HYP = SQRT( (LEG1**2) + (LEG2**2) )
* display area of triangle
PRINT *, 'AREA OF THE TRIANGLE IS', AREA
*display length of hpotenuse
PRINT *, 'LENGTH OF HYPOTENUSE IS', HYP
END
Problem 13
PROGRAM SHAFT
**********************************************************************
* *
* This program is intended to determine the torque produced by a *
* shaft rotated at a given RPM with a certain amount of horsepower *
* and to determine the necessary diameter for the shaft in order for *
* it to transmit the torque. Variables used are : *
* POWER = horsepower applied to the shaft *
* RPM = the rotational speed of the shaft *
* TORK = the amount of torque preduced by the shaft *
* STR = the sheer strength of the shaft *
* DIA = the necessary diameter of the shaft *
* *
* Input = POWER, RPM, STR *
* Output = TORK, DIA *
* *
**********************************************************************
REAL POWER, RPM, TORK, STR, DIA
* Obtain the horsepower applied to the shaft
PRINT *, 'APPLIED POWER TO SHAFT, IN HORSEPOWER'
READ *, POWER
* Obtain the rotational speed of the shaft
PRINT *, 'ROTATIONAL SPEED OF SHAFT, IN RPM'
READ *, RPM
* Calculate the resulting torque
TORK = 63000. * (POWER / RPM)
* Obtain the allowable sheer strength
PRINT *, 'ALLOWABLE SHEER STRENGTH, IN LBS / SQUARE INCH'
READ *, STR
* Calculate the diameter necessary to transfer torque
DIA = cbrt((16. * TORK / STR))
* Display resulting torque
PRINT *, 'TORQUE DEVELOPED, IN HORSEPOWER', TORK
* Disply required diameter for shaft
PRINT *, 'REQUIRED DIAMETER FOR SHAFT, IN INCHES', DIA
END
Problem 19
PROGRAM LINE
*********************************************************************
* *
* This program is designed to take the coordinates of two points *
* that the user inputs and calculate the length of the line segment *
* between the two points, the slope of that line, the equation of *
* that line in slope-intercept form, the midpoint of the line *
* segment, the slope of the perpendicular bisector of the line *
* segment, and the equation of the perpendicular bisector in *
* slope-intercept form. *
* *
* X1 = X COORDINATE OF POINT ONE *
* Y1 = Y COORDINATE OF POINT ONE *
* X2 = X COORDINATE OF POINT TWO *
* Y2 = Y COORDINATE OF POINT TWO *
* LENG = LENGTH OF LINE SEGMENT FROM POINT ONE TO TWO *
* XM = X COORDINATE OF MIDPOINT *
* YM = Y COORDINATE OF MIDPOINT *
* M1 = SLOPE OF LINE SEGMENT *
* M2 = SLOPE OF PERPENDICULAR BISECTOR *
* B1 = Y-INTERCEPT OF LINE *
* B2 = Y-INTERCEPT OF PERPENDICULAR BISECTOR *
* *
* INPUT = X1, Y1, X2, Y2 *
* OUTPUT = LENG, XM, YM, M1, M2, B1, B2 *
* *
*********************************************************************
REAL X1, X2, Y1, Y2, LENG, XM, YM, M1, M2, B1, B2
* Obtain coordinates of first point
PRINT *, 'INPUT X, Y COORDINATES OF POINT ONE'
READ *, X1, Y1
* Obtain coordinates of second point
PRINT *, 'INPUT X, Y COORDINATES OF POINT TWO'
READ *, X2, Y2
* Calculation of the length of the line segment
LENG = SQRT( (X2 - X1)**2 + (Y2 - Y1)**2)
* Displaying of length of line segment
PRINT *, 'LENGTH OF THE LINE SEGMENT IS', LENG
* Calculation of slope of line
M1 = (Y2 - Y1) / (X2 - X1)
* Displaying of slope of line
PRINT *, 'SLOPE OF LINE IS', M1
* Calculation of y-intercept of line
B1 = Y1 - (M1 * X1)
* Displaying of equation of line in y-intercept, slope form
PRINT *, 'EQUATION OF LINE IS Y=', M1, 'X +', B1
* Calculation of midpoint
XM = .5 * (X1 + X2)
YM = .5 * (Y1 + Y2)
* Displaying of midpoint
PRINT *, 'MIDPOINT OF THE LINE SEGMENT IS', XM, ',', YM
* Calculation of slope of perpendicular bisector
M2 = -1. / M1
* Displaying of slope of perpendicular bisector
PRINT *, 'SLOPE OF THE PERPENDICULAR BISECTOR', M2
* Calculation of y-intercept of perpendicular bisector
B2 = YM - (M2 * XM)
* Displaying of the equation of the perpendicular bisector
PRINT *, 'EQUATION OF THE PERP. BISECTOR IS Y=', M2, 'X +', B2
END