Jeremy Fallick's Computer Science 7 Portfolio-True Basic-Chapter 5

Jeremy Fallick's Portfolio-True Basic-Chapter 5



Home
HTML
→True Basic
→Chapter 1
→Chapter 1_2
→Chapter 2
→Chapter 3
→Chapter 4
→Chapter 5
→Linear Functions Program
Article Reviews
!Jeremy Fallick
!March 11 ,2005
!Period 6
!Chapter 5, Problem 3
!Solve the linear equation ax+b=0, where a and b are given numbers with a<>0. The program should provide for the input of several set of coefficients a and b terminated by 0,0. It should check that a<>0 and if so, display the equation's solution, x=-b/a
!Inputs: a, b
!Outputs: a, b, x
!Test data:
!1,0 x=0
!0,0 Bye
!0,1 INVALID
!5,6 x=-6/5
!7,2 x=-2/7
!Algorithm
!Main program				Level 0
!repeat
!	get inputs a,b
!	If a=0 then
!		If b=0 then exit
!		otherwise print invalid
!		end ifthen
!	otherwise assign -b/a to x
!	display outputs a,b,x
do
	input prompt "a,b:":a,b
	if a=0 then
		if b=0 then
			print "Bye"
		else
			print "INVALID"
		end if
	else
		let x=-b/a
		print "a=";a
		print "b=";b
		print "x=";x
	end if
loop until a=0 and b=0
end
!Jeremy Fallick
!March 17, 2005
!Period 6
!Chapter 5, Problem 4
!Problem: Compute the federal tax due on a taxable income input by the user.
!
!Inputs: taxable income
!Outputs: taxable income, tax due
!
!Test Data/Handworked Examples:
!$40,000-$17,850=$22,150
!28% of $22.150=$6,202
!$6,202+$2,677.50=$8,879.50
!
!$60,000-$43,150=$16,850
!33% of $16,850=$5,560.50
!$5,560.50+$9,761.50=$15,322
!
!Algorithm:
!get taxable income
!if taxable income <= 89560 then
!	if taxable income <= 43150 then
!		if taxable income <= 17850 then
!			assign 15% of taxable income to tax due
!			otherwise assign 28% of (taxable income - 17850) + 2677.50 to tax due
!		end if then
!		otherwise assign 33% of (taxable income - 43150) + 9761.50 to tax due
!	end if then
!	otherwise assign 28% of (taxable income - 89560) + 25076.80 to tax due
!end if then
!display taxable income
!display tax due
!
!Code:
input prompt "Taxable income:": income
if income<=89560 then
	if income<=43150 then
		if income<=17850 then
			let tax=.15*income
		else
			let tax=.28*(income-17850)+2677.50
		end if
	else
		let tax=.33*(income-43150)+9761.50
	end if
else
	let tax=.28*(income-89560)+25076.80
end if
print "Taxable income:$";income
print "Tax due:$";tax
end