Lecture 7. AMES 5, Tues. 26 Jan. 1999

From the course outline we see the reading assignment this week is Chapter 5 on Standard Functions and Program Design. You need to turn in modified versions of all the example programs in this chapter, and do Practice Programs 5.1 and 5.2.

Arthmetic, trigonometric, string, conversion from string to numerical and back, ascii, keyboard, and mouse functions are discussed in Chapter 5. Single-line user-defined functions are introduced. Some of the concepts are:

All of these concepts are illustrated by the Example Programs which you will modify in your homework.

The design of an original computer program is illustrated by Practice Program 4.9, where a Fibonacci series (eg: 1,1,2,3,5,8,13,21,34,55 etc.) for length n is computed. The use of string functions, pseudocode, subroutines, and short practice programs PP4.9.1 and PP4.9.2 to develop the longer program is illustrated. Possible practice programs PP4.1 and PP4.2 were emailed to Anissa Barnett.

Practice Program 5.7 tests a word or phrase to see if it reads the same backwards as forwards. If it does, it is called a "Palindrome". A famous example is the alleged quote from Napoleon: "Able was I ere I saw Elba".

Quiz 4a Solution

Lecture8. AMES 5, Thurs. 28 Jan. 1999

In order to test the behavior of T-BASIC functions, it is useful to write short programs using the function that can be run several times with different parameters. For example, to test the function abs(x):

The program:

PRINT abs(-1.2345)


Gives output:


and the program:

! Print out the ascii codes and associated characters.

! Use functions ord(a$) and chr$(x), x is 0 to 255.

LET index = 0


LET index = index + 1

PRINT index;chr$(index),

LOOP while index < 255


Gives output:

ascii code table.

A program to test the random number function and also to explore graphics from Chapter 12 is:

Random circles and sounds:

SET MODE "graphics"


LET i=1

DO while i <50

LET ratio=1.4

LET x=rnd

LET y=rnd

LET rad=(rnd-.5)

SET WINDOW -2*ratio,2*ratio,-2,2

SET COLOR -10*rnd

DRAW circle (rad,x,y)

SOUND 1000*rnd,2*rnd


LET i=i+1



PICTURE circle (r,x,y)

BOX CIRCLE x-r,x+r,y-r,y+r


Try it!

Quiz 4b Solution