Jeremy Fallick's Computer Science 7 Portfolio-True Basic-Linear Function Program-Phase II

Jeremy Fallick's Portfolio-True Basic-Linear Functions Program-Phase II



Home
HTML
→True Basic
→Chapter 1
→Chapter 1_2
→Chapter 2
→Chapter 3
→Chapter 4
→Chapter 5
→Linear Functions Program
→→Phase I
→→Phase II
Article Reviews
!Linear Functions Program
!Problem: Students will plan, construct and test the sections necessary to accept the specified inputs from the user. Then the program will calculate and display the indicated slope and y-intercept . The program will also test for and prevent division by zero. Obviously, this is an expansion of the program written for PhaseI.
!Inputs/Ouputs: Choice$, a, b, c, x, y, xint, yint, Slope, x1, y1, x2, y2, PerpendicularSlope, ParallelSlope
!Test Data/Hand-worked Example:
!Please choose from the following:
!A.....The slope and y-intercept of your function.
!B.....Two ordered pairs that lie on the graph of your function.
!C.....The slope of a line perpendicular to your function and the coordinates of a point on the graph of your function.
!D.....The slope of a line parallel to your function and the coordinates of a point on the graph of your function.
!E.....The slope of your function and one ordered pair that lies on the graph of your function.
!F.....The coefficients of the general form of the equation of your function General form:(Ax + By = C).
!G.....Exit the Program
!What is your choice? f
!This is the General Form sub.
!a=3
!b=6
!c=5
!The slope is -1/2.
!Please choose from the following:
!A.....The slope and y-intercept of your function.
!B.....Two ordered pairs that lie on the graph of your function.
!C.....The slope of a line perpendicular to your function and the coordinates of a point on the graph of your function.
!D.....The slope of a line parallel to your function and the coordinates of a point on the graph of your function.
!E.....The slope of your function and one ordered pair that lies on the graph of your function.
!F.....The coefficients of the general form of the equation of your function General form:(Ax + By = C).
!G.....Exit the Program
!What is your choice? g
!Thank you for using Jeremy F.'s Linear Functions Program.
!
!Algorithm:
!Level 0 *****************************************************
!Display Welcome Message
!Repeat the following until the user enters "G" (choice to quit)
!	Menu
!Display 'Thank you' message
!
!Level 1 *****************************************************
!Menu
!Repeat the following until choice >=A and <=G (is valid choice)
!Display menu choices
!Prompt for and get choice
!Convert choice to uppercase
!If not valid
!	Display error message
!If choice = A
!	SlopeIntercept
!Otherwise If choice = B
!	TwoPoints
!Otherwise If choice = C
!	Perpendicular
!Otherwise If choice = D
!	ParallelSlope
!Otherwise If choice = E
!	PointSlope
!Otherwise If choice = F
!	GeneralForm
!Otherwise if choice = G
!	TakeTheCredit
!
!Level 2 *****************************************************
!SlopeIntercept
!Define PromptAndGetNum
!Display Welcome to slope intercept sub message
!Assign PromptAndGetNum 'Slope' to Slope
!Assign PromptAndGetNum 'y-intecept' to y-int
!Display Slope and y-Intercept
!
!TwoPoints
!Define PromptAndGetNum
!Display Welcome to Two Points sub message
!Assign PromptAndGetNum 'X1' to x1
!Assign PromptAndGetNum 'Y1' to y1
!Assign PromptAndGetNum 'X2' to x2
!Assign PromptAndGetNum 'Y2' to y2
!If X1=X2
!	VerticalLine
!Otherwise
!	Calculate slope
!	Calculate y-intercept
!	Display Slope and y-Intercept
!
!Perpendicular
!Define PromptAndGetNum
!Display Welcome to Perpendicular sub message
!Assign PromptAndGetNum 'Perpendicular slope' to PerpendicularSlope
!Assign PromptAndGetNum 'X' to x
!Assign PromptAndGetNum 'Y' to y
!If PerpendicularSlope=0
!	VerticalLine
!Otherwise
!	Calculate slope
!	Calculate y-intercept
!	Display Slope and y-Intercept
!
!ParallelSlope
!Define PromptAndGetNum
!Display Welcome to Parallel Slope sub message
!Assign PromptAndGetNum 'Parallel slope' to ParallelSlope
!Assign PromptAndGetNum 'X' to x
!Assign PromptAndGetNum 'Y' to y
!Calculate slope
!Calculate y-intercept
!Display Slope and Intercept
!
!PointSlope
!Define PromptAndGetNum
!Display Welcome to Point Slope sub message
!Assign PromptAndGetNum 'Slope' to slope
!Assign PromptAndGetNum 'X' to x
!Assign PromptAndGetNum 'Y' to y
!Calculate slope
!Calculate y-intercept
!Display Slope and y-Intercept
!
!GeneralForm
!Define PromptAndGetNum
!Display Welcome to General Form sub message
!Assign PromptAndGetNum 'A' to a
!Assign PromptAndGetNum 'B' to b
!Assign PromptAndGetNum 'C' to c
!If b=0
!	VerticalLine
!Otherwise
!	Calculate slope
!	Calculate y-intercept
!	Display Slope and y-Intercept
!
!Level 3 *****************************************************
!PromptAndGetNum
!Display prompt
!Get number
!Return number
!
!Vertical Line
!Display 'Vertical Line' message
!
!Code:
Print "Welcome to Jeremy F's Linear Functions Program."
declare function PromptAndGetNum
do
	call Menu(choice$)
loop until choice$="G"
end
sub Menu(choice$)
declare function PromptAndGetNum
do
	print "Please choose from the following:"
	print "A.....The slope and y-intercept of your function."
	print "B.....Two ordered pairs that lie on the graph of your function."
	print "C.....The slope of a line perpendicular to your function."
	print "and the coordinates of a point on the graph of your function."
	print "D.....The slope of a line parallel to your function and the coordinates of a point on the graph of your function."
	print "E.....The slope of your function and one ordered pair that lies on the graph of your function."
	print "F.....The coefficients of the general form of the equation of your function General form:(Ax + By = C)."
	print "G.....Exit the program."
	input prompt "What is your choice?":choice$
	let choice$=UCASE$(choice$)
	If choice$>"G" then
		print "INVALID INPUT"
	Else If choice$ = "A" then
		call SlopeIntercept
	Else If choice$ = "B" then
		call TwoPoints
	Else If choice$ = "C" then
		call Perpendicular
	Else If choice$ = "D" then
		call ParallelSlope
	Else If choice$ = "E" then
	 	call PointSlope
	Else If choice$ = "F" then
		call GeneralForm
	else if choice$ = "G" then
		call TakeTheCredit
	end if
loop until choice$>="G"
end sub
sub SlopeIntercept
declare function PromptAndGetNum
print "Welcome to the Slope Intercept Sub!"
let slope=PromptAndGetNum("Slope")
let yint=PromptAndGetNum("y-intercept")
print "Slope:";Slope
print "Y-intercept:";Yint
end sub
sub TwoPoints
declare function PromptAndGetNum
print "Welcome to the Two Points Sub!"
let x1=PromptAndGetNum("X1")
let y1=PromptAndGetNum("Y1")
let x2=PromptAndGetNum("X2")
let y2=PromptAndGetNum("Y2")
If X1=X2 then
	call VerticalLine
Else
	let slope=(y2-y1)/(x2-x1)
	let yint=-Slope*x1+y1
	print "Slope:";slope
	print "Y-intercept:";yint
end if
end sub
sub Perpendicular
declare function PromptAndGetNum
print "Welcome to the Perpendicular Sub!"
let PerpendicularSlope= PromptAndGetNum ("Perpendicular slope")
let x = PromptAndGetNum ("X")
let y = PromptAndGetNum ("Y")
If PerpendicularSlope=0 then
	call VerticalLine
else
	let Slope = -PerpendicularSlope^(-1)
	let yint = -slope*x+y
	print "Slope:";slope
	print "Y-intercept:";yint
end if
end sub
sub ParallelSlope
declare function PromptAndGetNum
print "Welcome to the Parallel Slope Sub!"
Let ParallelSlope=PromptAndGetNum ("Parallel slope")
Let x=PromptAndGetNum ("X")
Let y=PromptAndGetNum ("Y")
let slope=parallelslope
let yint=-slope*x+y
print "Slope:";slope
print "Y-intercept:";yint
end sub
sub PointSlope
declare function PromptAndGetNum
print "Welcome to the Point Slope Sub!"
Let slope=PromptAndGetNum ("Slope")
Let x=PromptAndGetNum ("X")
Let y=PromptAndGetNum ("Y")
let yint=-slope*x+y
print "Slope:";slope
print "Y-intercept:";yint
end sub
sub GeneralForm
declare function PromptAndGetNum
print "Welcome to the General Form Sub!"
Let a=PromptAndGetNum ("A")
Let b=PromptAndGetNum ("B")
Let c=PromptAndGetNum ("C")
If b=0 then
	call VerticalLine
Else
	let slope=-a/b
	let yint=c/b
	print "Slope:";slope
	print "Y-intercept:";yint
end if
end sub
sub TakeTheCredit
print "Thank you for using Jeremy F.'s Linear Functions Program."
end sub
function PromptAndGetNum(num$)
print num$;":";
input prompt " ":num
let PromptAndGetNum=num
end function
sub VerticalLine
Print "This line is a vertical line."
end sub