Top Banner

of 143

Computers 4 Smart People

Apr 05, 2018



  • 7/31/2019 Computers 4 Smart People


    Computers For Smart People

    Robert S. Swiatek

  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


    Id like to thank all the people who made this

    book possible, in particular, all those people Imet during my stay in Binghamton in the early1970s. I especially thank my niece, ElizabethThomann-Stellrecht, who was responsible for

    the great cover of this book. Her work can befound on the vast majority of the books that Ipublished since the spring of 2008 thatsmuch more than a two-thirds majority neededto overcome Republican objections. Over thelast few years, people have raved about thesecovers at various arts and crafts festivals of

    which I have been a part. Some have evenpurchased a book. Thanks!

  • 7/31/2019 Computers 4 Smart People


    To Pat and Lou

  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People



    humor. The subject matter may have limited that aspect, but as I have found, there are

    very few books where levity cant be interjected.

    In general, it is probably better that the book didnt get published at that time. It

    really wasnt ready to come into print. However, when I revised it in 2001, all theselimitations would be gone. Half a dozen years later, the work still wasnt published. I did

    some more modifications in January 2010 while staying in my cousin Jims town home in

    Sun City Center, Florida. Incidentally, I have at least three cousins with that name. Thenin December 2011, I decided to publish it as an ebook, resulting in a great deal moreediting. Since I had created my own computer language, that created the biggest holdup. Ifelt for the longest time that the programs few though they werehad to be thoroughly

    checked over since they couldnt really be tested with a computer. I needed to put in the

    effort to get this task done.Somehow, I came up with a new idea. Every program found in this book is here

    for instructional purposes. It is meant to display computer concepts and who really caresif there are a few places where something may fail or could be done better. In reality,

    these programs have nowhere near the bugs that you will find on the Internet or even onyour PC, each of which is rushed into production without checking. As you can tell, thatapproach was not done in this book. After all, quite a few years had passed since I startedwriting it. For that reason, any problems that you encounter in this work are truly minorand can easily be overlooked. If you are a person who likes to correct others by findingtiny mistakes in books, I need only remind you that every book that was ever written hasat least one error, of some kind or another. Dont waste your time.

    As far as the book title that I first chose, this goes back to my days atBinghamton University when I was studying for a degree in computer science. My fellowstudents and I worked together as a team to get projects done. The effort required was

    intense but we had a good sense of humor about it. In fact while going through the degreeprogram one of my study-partners remarked, Six months ago I could not spell computerprogrammernow I are one!

    We all got a laugh out of that, and I loved that title. However, I decided that there

    wasnt enough room on the cover to put all those words if I used a smaller font, notmany people could read it so I thought about another one that would be better. This

    didnt come easy, but eventually I settled on Computer For Smart People. I hope youfind this treatise to be enjoyable and enlightening.

  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People



    The file that we want to consider is a file for checking at the bank. For now it willconsist of just a few fields, account number, last name, first name, middle initial, street

    address, city, state, zip code and balance. Using someones social security number because of identity theftis not a good idea. In some cases, the computer will generate anaccount numberand even let the customer know what it is. In our system, the accountnumber will be a nine-digit field greater than nine.

    Both the first and last names must consist of letters of the alphabet, the space,apostrophe, period and hyphen only. This accommodates Billy Bob Thornton, Tom

    OBrien, Jill St. John and Olivia Newton-John. The first name is limited to fifteencharacters while the last name is restricted to eighteen. That should be enough characters.The middle initial must beA throughZ, but it can also be left blank. The street address islimited to twenty-five characters and has the same restrictions as the name, exceptnumbers are also allowed as well as the comma. If you live at 10 Main Street, goodluck. City must be no more than fifteen characters and these must consist only of lettersof the alphabet, the period, space and hyphen.

    The state must be exactly two characters and it must be the valid abbreviation forone of the fifty. The zip code must be a five digit numeric field. The balance will be asigned numeric field having eight digits, six to the left of the decimal point and two to the

    right. If you have a balance of over $999,999, it shouldnt be in a checking account. In

    fact this bank may even be more restrictive and caring about the customer that couldhappenas large balances might result in letters being sent out notifying customers thatthey may want to consider a certificate of deposit or the idea of buying stock.

    Our file is the account file andif I want to read it in a program, I will specify thevariable


    that represents a file which the program can read. How this is done will be shown whenwe get to the program. For now we need to worry about the fields that make up the file.We have to spell out the names of the fields, their sizes, where they are in the record and

    what type each field is. To save space one field will follow the other so well define a

    structure, which will refer to the file, the record and each field.

    Well define a file and its composition so that we know the makeup of a typical

    record. That way, well know where each field should be. We certainly dont want the

    first record to have the account number at the beginning followed by the last name andthen the second record have the first name directly after the account number. Thatscenario will make it impossible to process the file. In our account number file, the

    account number will start in position 1 of the record and end in position 9, last name willstart in position 10 and end in position 27, first name will begin in position 28 and end inposition 42 and so forth until we get to balance, which ends in position 99. This will bethe case for each record on the file and it means we can find the data we want where itshould be.

    We could have put commas as separators between the fields and accomplished thesame result but what happens when one of the fields has a comma in it? That could messus up so our method will be better. We start by defining a file and its structure. The

  • 7/31/2019 Computers 4 Smart People



    account number file consists of nine fields. We must then thoroughly describe each field.This gives us some keywords. The first is

    defineand the others are





    The actual program code to describe the account file record and its makeup is asfollows:

    define acctfile record account-record structureaccount-numberinteger(9)

    last-name character(18)first-name character(15)middle-initial characterstreet-address character(25)city character(15)state character(2)zip-code integer(5)balance signeddecimal(6.2)

    Note that the ten lines above are not a program, which well get to in the next

    chapter. Let us begin with the first line,define file acctfile record account-record structure.

    The keyworddefine

    spells out to the program the name of the fileindicated by what follows the keywordfile

    and what fields make up each record. Thats what the keywordrecord

    is for. The field


    is a variable, as are the nine fields in the record that follow. The record is related to thesefields by the keyword

    structurewhich says that the variable

    account-recordconsists of nine fields. The end of the record is indicated by the next occurrence of thekeyword define,or some keyword, such as


  • 7/31/2019 Computers 4 Smart People


  • 7/31/2019 Computers 4 Smart People




    zip-codecould have been defined using the keyword

    characterrather than

    integersince each number is included in the character set. The last line

    balance signeddecimal(6.2)introduces two new keywords,


    decimal.Since the account balance could be negative at times and it does involve cents as well asdollars, we need to spell that out. The variable


    allows for negative as well as positive numbers, whiledecimal(6.2)

    indicates that the field has 6 digits to the left of the decimal point and 2 to