Lecture 7. MAE 5, Tues. April 23, Quiz 6 Today! (see version given previously)

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 , 5.2, 5.3, and 5.4.

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. Note: a much simpler solution of PP4.9 can be constructed.

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

Self Test Question Answers Chapter 5. Study these in preparation for Quiz 6 (today)

Lecture 8. MAE 5, Thurs. April 25, 2002, Quiz 7 Today! (see version given previously)

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)

END

Gives output:

1.2345

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

DO

LET index = index + 1

PRINT index;chr$(index),

LOOP while index < 255

END

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"

RANDOMIZE

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

PAUSE .2

LET i=i+1

LOOP

END

PICTURE circle (r,x,y)

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

END PICTURE

Try it!



Quiz 4b Solution

Self Test Question Answers Chapter 5. Study these in preparation for Quiz 7 (today)

Help