Home HTML →True Basic →Chapter 1 →Chapter 1_2 →Chapter 2 →Chapter 3 →Chapter 4 →Chapter 5 →Linear Functions Program Article Reviews |
!Jeremy Fallick !September 8,2004 !Period 6 !Chapter 3, Problem 1-4 call getinputs(invested, interest, times, years) !arguments call formula(invested, interest, times, years, worth) !arguments call display(invested, interest, times, years, worth) !arguments end sub getinputs(principal, rate, number, term) !parameters input prompt "Amount to be invested:": principal input prompt "Annual % interest rate:": rate input prompt "Number of times compounded per year:": number input prompt "Term of the investment in years:": term end sub sub formula(principal, rate, number, term, amount) !parameters let amount=principal * (1 + (rate / 100) / number) ^ (number * term) end sub sub display(principal, rate, number, term, amount) !parameters print "The amount to be invested is"; principal print "The annual % rate of interest is"; rate print "The number of times compounded per year is"; number print "The term of the investment in years is"; term print "The final worth of the investment is"; amount end sub !Jeremy Fallick !September 8,2004 !Period 6 !Chapter 3, Problem 5 print "Welcome to my program!" call input_data call perform_calculations call output_results sub input_data input prompt "Customer name:": customer$ input prompt "Pool diameter:": diameter read poolftcost, deckftcost data 50, 15 end sub sub perform_calculations let radius=diameter/2 let area=pi*radius^2 let circumference=2*pi*radius let poolcost=area*poolftcost let deckcost=circumference*deckftcost end sub sub output_results print "The customer name is "; customer$ print "The pool diameter is"; diameter; "feet." print "The per-foot cost of pool is $"; poolftcost print "The per-foot cost of deck is $"; deckftcost print "The area of the pool is"; area; "square feet." print "The circumference of the pool is"; circumference; "feet." print "The cost of the pool is $"; poolcost print "The cost of the deck is $"; deckcost end sub end !Jeremy Fallick !September 8,2004 !Period 6 !Chapter 3, Problem 6 print "Welcome to my program!" call input_data(name$, length, poolunitcost, deckunitcost) !arguments call perform_calculations(name$, length, poolunitcost, deckunitcost, halflength, space, distance, poolmoney, deckmoney) !arguments call output_results(name$, length, poolunitcost, deckunitcost, space, distance, poolmoney, deckmoney) !arguments end sub input_data(customer$, diameter, poolftcost, deckftcost) !parameters input prompt "Customer name:": customer$ input prompt "Pool diameter:": diameter read poolftcost, deckftcost data 50, 15 end sub sub perform_calculations(customer$, diameter, poolftcost, deckftcost, radius, area, circumference, poolcost, deckcost) !parameters let radius=diameter/2 let area=pi*radius^2 let circumference=2*pi*radius let poolcost=area*poolftcost let deckcost=circumference*deckftcost end sub sub output_results(customer$, diameter, poolftcost, deckftcost, area, circumference, poolcost, deckcost) !parameters print "The customer name is "; customer$ print "The pool diameter is"; diameter; "feet." print "The per-foot cost of pool is $"; poolftcost print "The per-foot cost of deck is $"; deckftcost print "The area of the pool is"; area; "square feet." print "The circumference of the pool is"; circumference; "feet." print "The cost of the pool is $"; poolcost print "The cost of the deck is $"; deckcost end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 7 call read(name$, score1, score2) !arguments call calculate(name$, score1, score2) !arguments call display(name$, score1, score2) !arguments end sub read(student$, test1, test2) !parameters read student$, test1, test2 data "Emily", 92, 100 end sub sub calculate(student$, test1, test2) !parameters let average=(test1+test2)/2 end sub sub display(student$, test1, test2) !parameters print "If "; student$; " has a score of"; test1; "and a score of"; test2; ", then she has an average score of"; average; "." end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 8 call inputs(amount, percent, monthly) !arguments call calculate(amount, percent, monthly, interest, cost) !arguments call display(amount, percent, monthly, interest, cost) !arguments sub inputs(loan, percent_rate, number) !parameters input prompt "Amount of the loan:":loan input prompt "Annual interest rate percentage:":percent_rate input prompt "Number of monthly payments:":number end sub sub calculate(loan, percent_rate, number, rate, payment) !parameters let rate=percent_rate/1200 let payment=loan*rate*(1+rate)^number/((1+rate)^number-1) end sub sub display(loan, percent_rate, number, rate, payment) !parameters print "If the loan is $"; loan; print ", the interest rate is"; percent_rate; print "%, and the number of monthly payments is"; number; print ", then the monthly payment is $"; payment; "." end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 9 call inputs(name$, cost, weight1, weight2) !arguments call calculate(name$, cost, weight1, weight2) !arguments call display(name$, cost, weight1, weight2) !arguments end sub inputs(product$, price, pounds, ounces) !parameters input prompt "Name of product:":product$ input prompt "Price of product:":price input prompt "Weight in pounds:":pounds input prompt "Weight in ounces:":ounces end sub sub calculate(product$, price, pounds, ounces) !parameters let pounds_to_ounces=pounds*16 let total_ounces=ounces+pounds_to_ounces let unit_price=price/total_ounces end sub sub display(product$, price, pounds, ounces) !parameters print product$; "costs $"; price; print ", weighs"; pounds; "pounds and"; ounces; print "ounces, and has a unit price of $"; unit_price; "." end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 10 call inputs(employee$, identification, worktime, extra, pay) !arguments call calculate(employee$, identification, worktime, extra, pay, gross) !arguments call display(employee$, identification, worktime, extra, pay, gross) !arguments end sub inputs(name$, ID_number, hours, overtime, rate) !parameters input prompt "Employee name:":name$ input prompt "ID number:":ID_number input prompt "Hours worked:":hours input prompt "Overtime hours worked:":overtime input prompt "Pay rate per hour:":rate end sub sub calculate(name$, ID_number, hours, overtime, rate, gross_pay) !parameters let gross_pay=(hours*rate)+(overtime*(1.5*rate)) end sub sub display(name$, ID_number, hours, overtime, rate, gross_pay) !parameters print name$; " has ID number"; ID_number; print ", has worked"; hours; print "hours, has worked"; overtime; print "overtime hours, has a pay rate of $"; rate; print ", and has a gross pay of $"; gross_pay; "." end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 11 call inputs(games1, games2, games3, gamej1, gamej2, gamej3) !arguments call calculate(games1, games2, games3, gamej1, gamej2, gamej3, averages, averagej, scores) !arguments call display(games1, games2, games3, gamej1, gamej2, gamej3, averages, averagej, scores) !arguments sub inputs(Sharon_1, Sharon_2, Sharon_3, Judy_1, Judy_2, Judy_3) !parameters input prompt "Sharon's Game 1:":Sharon_1 input prompt "Sharon's Game 2:":Sharon_2 input prompt "Sharon's Game 3:":Sharon_3 input prompt "Judy's Game 1:":Judy_1 input prompt "Judy's Game 2:":Judy_2 input prompt "Judy's Game 3:":Judy_3 end sub sub calculate(Sharon_1, Sharon_2, Sharon_3, Judy_1, Judy_2, Judy_3, Sharon_average, Judy_average, total) !parameters let Sharon_average=(Sharon_1+Sharon_2+Sharon_3)/3 let Judy_average=(Judy_1+Judy_2+Judy_3)/3 let total=Sharon_1+Sharon_2+Sharon_3+Judy_1+Judy_2+Judy_3 end sub sub display(Sharon_1, Sharon_2, Sharon_3, Judy_1, Judy_2, Judy_3, Sharon_average, Judy_average, total) !parameters print "If Sharon's scores are"; Sharon_1; ","; Sharon_2; ", and"; Sharon_3; "," print "and Judy's scores are"; Judy_1; ","; Judy_2; ", and"; Judy_3; "," print "then Sharon's average is"; Sharon_average; "and Judy's average is"; Judy_average; "," print "and the team score is"; total; "." end sub !Jeremy Fallick !October 9, 2004 !Period 6 !Chapter 3, Problem 12 call pandas call unicorns call pterodactyls call white_sox end sub pandas data "Pandas", 11,0 read team$, wins, losses let percent=wins/(wins+losses) print team$, wins, losses, percent end sub sub unicorns data "Unicorns", 6,6 read team$, wins, losses let percent=wins/(wins+losses) print team$, wins, losses, percent end sub sub pterodactyls data "Pterodactyls", 4,6 read team$, wins, losses let percent=wins/(wins+losses) print team$, wins, losses, percent end sub sub white_sox data "White Sox", 0,9 read team$, wins, losses let percent=wins/(wins+losses) print team$, wins, losses, percent end sub |