What If?; Solutions - AMSTRAD cpc 6128 User Instruction

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

There's a new command in line 150 - INS T R. It tells the computer to INterrogate
the first STRing expression to find the first occurence of the second string expression,
in other words, it searches N A ME $ ( x) for SEA R C H $ (which is the variable you
input in line 130 containing the name that you're looking for). If INS T R doesn't find
it (or any part of it), it gives out a value ofO, which is used here to make the program
pass to line 1 80 and try again with the N E X T value of x. If the program has passed
through all values of x up to 100, it then continues to line 1 90 and tells you that it
hasn't found the name. If however it does find the name, INS T R will not produce a
value of 0, and the program will then pass from line 1 50 to 1 60 and print the name
and phone number, then END at line 1 70.
As you can see, our program is developing quite rapidly now, but there's still so much
to be done. Let's sit back for a moment and consider some drawbacks ofthis program,
starting with the way in which the program runs: First you type in the information,
then you get a list back, then you search for a specific name.
What if?
Well, what if you don't want to do it in that order? What if you want to start by
searching for a name that you stored in the program yesterday? And what if you want
to add some more names and numbers to those already there? These are all aspects of
the program that you have to think about and find solutions for; it's what
programming is all about. As previously mentioned, BASIC is kind enough to let you
sandwich afterthoughts into the program, but a good programmer will have
anticipated these problems beforehand.
Another major problem with this program is that the values of the variables in the
arrays are all stored in a part of the computer's memory that is cleared whenever you
RUN a program. You'll not want to have to type in all the information every time you
use the program, so you'll need the option of being able to save the values of all the
N A M E $ and T E L $ variables before you switch off, together with the option to load in
the values of the variables whenever you run the program.
Solutions
The first ofthese problems (i.e. the order in which things are carried out) can be dealt
with by writing the program so that when it runs, you get a choice of the various
functions that it can perform. This type of program is called 'menu-driven', and in
effect displays a menu on the screen from which you can select an option. If you've
ever used one of those cash dispensers outside the bank, then you'll have already
operated a menu-driven computer program! Let's add a menu to this program:
Beyond Foundations
Chapter 2 Page 5

Advertisement

Table of Contents
loading

Table of Contents