! Chapter 4 Problems 1-4
! Chapter 3 Problem 9
! Chapter 3 Problem 10
! Iliya Smithka
! Pd. 7
! April 7 2003
! Problem: given the principal, invest rate, compounding,
! and term of an investment, calculate and display the final
! value of that investment
!***********************************************************
! Inputs: principal, # of times compounded per year, term
! (in years)
! Outputs: final value and all the inputs
!***********************************************************
! Handworked Example:
! invest=165000
! rate=.06
! times=4
! term=10
! finalv=165000*(1+.06/4)^(4*10)
! finalv=299313.04
!***********************************************************
! Algorithm:
! Level 0 **************************************************
! GETINPUTS
! CALRESULT
! DISRESULT
! Level 1 **************************************************
! GETINPUTS
! prompt for and get-principal
! prompt for and get-interest rate (apr)
! prompt for and get-compounding
! prompt for and get-term (in years)
! CALRESULT
! assign apr*.01 to rate
! assign principal*(1+rate/n)^nt to final
! DISRESULT
! display principal
! display apr
! display compounding
! display term
! display final value
!***********************************************************
! Code:
CALL getinputs(invest, rate, times, term)
CALL calresult(invest, rate, times, term, final)
CALL disresult(invest, rate, times, term, final)
SUB getinputs(invest, rate, times, term)
INPUT prompt "What was the principal? ":invest
INPUT prompt "What is the interest rate? ":rate
INPUT prompt "What is the compounding? ":times
INPUT prompt "What is the term (in years)? ":term
END SUB
SUB calresult(invest, rate, times, term, final)
LET apr=rate*.01
LET final=invest*(1+apr/times)^(times*term)
END SUB
SUB disresult(invest, rate, times, term, final)
PRINT "With a principal of";invest;"dollars at";rate
PRINT "percent interest rate over";term;"years and"
PRINT "compounding";times;"times per year, the final"
PRINT "value of the investment is";final;"dollars."
END SUB
END
! Iliya Smithka
! Pd. 7
! March 10 2003
! Problem: given the product name, price, and weight in
! pounds and ounces, calculate and display the unit
! price
!***********************************************************
! Inputs: product name, price, weight in pounds and ounces
! Outputs: unit price and all the inputs
!***********************************************************
! Handworked Example:
! name=spaghettios
! price=8.5
! lbs=1
! oz=4
! weight=20
! unit=0.425
!***********************************************************
! Algorithm:
! GETINPUTS
! FUNTIONPEROUNCE
! DISRESULT
!-----------------------------------------------------------
! GETINPUTS
! prompt for and get-product name
! prompt for and get-product price
! prompt for and get-product weight in pounds (lbs)
! prompt for and get-product weight in ounces (oz)
! FUNCTIONPEROZ
! assign lbs*16+oz to weight
! assign price/weight to perounce
! DISRESULT
! display name
! display price
! display weight in pounds
! display weight in ounces
! display unit price
!***********************************************************
! Code:
DECLARE FUNCTION perOunce
PRINT "Program by Iliya Smithka"
CALL getinputs(name$, price, lbs, oz)
let uprice=perOunce(lbs, oz, weight, price)
CALL disresult(name$, price, lbs, oz, uprice)
END
SUB getinputs(name$, price, lbs, oz)
INPUT prompt "What is the product's name? ":name$
INPUT prompt "What is its price? ":price
INPUT prompt "What is its weight in pounds? ":lbs
INPUT prompt "What is its weight in ounces? ":oz
END SUB
FUNCTION perOunce(lbs, oz, weight, price)
LET weight=lbs*16+oz
LET perOunce=price/weight
END FUNCTION
SUB disresult(name$, price, lbs, oz, uprice)
PRINT "The unit price of ";name$;" with an original price"
PRINT "of $";price;"and a weight of";lbs;"pound(s) and";oz
PRINT "ounce(s) is $";uprice
END
! Iliya Smithka
! Pd. 7
! March 20 2003
! Problem: gievn an employee's name, ID number, hours
! worked in a week, overtime hours, and their payrate per
! hour; find their gross pay.
! *******************************************************
! Inputs: name, ID number, regular hours, overtime hours,
! payrate.
! Outputs: inputs, gross pay.
! *******************************************************
! Test Data: Sarah Soad, 55651, 48, 3, 5
! -------------------------------------------------------
! Handworked Example:
! gross=48*5+1.5*3*5
! gross=262.5
! *******************************************************
! Alorithm:
! GETINPUTS
! CALRESULTS
! DISRESULTS
! -------------------------------------------------------
! GETINPUTS
! prompt for and get:
! employee name, ID number, regular hours, overtime
! hours, and payrate.
! CALRESULTS
! assign gross pay to:
! regular hours*payrate*5+1.5*OT hours*payrate
! DISRESULTS
! display inputs and gross pay.
! *******************************************************
! Code:
DO
PRINT "Welcome to Super Supermarket's Gross Weekly Pay"
PRINT "Computer -Designed by Iliya Smithka"
CALL getinputs(name$, id, reghrs, othrs, rate)
CALL calresults(name$, id, reghrs, othrs, rate, gross)
CALL disresults(name$, id, reghrs, othrs, rate, gross)
DO
INPUT prompt "Another employee?(y/n) ":yn$
IF yn$<>"n" and yn$<>"y" then
PRINT "Invalid response."
END IF
LOOP until yn$="y" or yn$="n"
LOOP while yn$="y"
END
SUB getinputs(name$, id, reghrs, othrs, rate)
INPUT prompt "What is the employee's name? ":name$
INPUT prompt "ID number? ":id
INPUT prompt "Hours worked this week? ":reghrs
INPUT prompt "Overtime hours? ":othrs
INPUT prompt "Payrate per hour? ":rate
END SUB
SUB calresults(name$, id, reghrs, othrs, rate, gross)
LET gross=reghrs*rate+1.5*othrs*rate
END SUB
SUB disresults(name$, id, reghrs, othrs, rate, gross)
PRINT name$;"'s gross pay for this week, whose ID"
PRINT "number is";id;"and after working";reghrs
PRINT "regular hours,";othrs;"overtime hours, and"
PRINT "earning";rate;"dollars per hour, is";gross
END