TURBO Pascal Tutor·
Total Page:16
File Type:pdf, Size:1020Kb
The TURBO Pascal Tutor· A Self-Study Guide to TURBO Pascal Copyright @1984 Copyright @1985 BORLAND INTERNATIONAL, INC. 4585 Scotts Valley Drive Scotts Valley, CA 95066 U.S.A. Borland's No-Nonsense License Statement! This software is protected by both United States Copyright Law and International Treaty provisions. Therefore you must treat this software just like a book with the following single exception. Borland International authorizes you to make archival copies of the software for the sole purpose of backing-up your software and protecting your investment from loss. By saying, "just like a book", Borland means for example that this software may be used by any number of people and may be freely moved from one computer location to another so long as there is No Possibility of it being used at one location while it's being used at another. Just like a book that can't be read by two different people in two different places at the same time, neither can the software be used by two different people in two different places at the same time. (Unless, of course, Borland's Copyright has been violated.) WARRANTY With respect to the physical diskette and physical documentation enclosed herein, BORLAND INTERNATIONAL, INC., ("BORLAND") warrants the same to be free of defects in materials and workmanship for a period of 30 days from the date of purchase. In the event of notification within the warranty period of defects in material or workmanship, BORLAND will replace the defective diskette or documentation. The remedy for breach of this warranty shall be limited to replacement and· shall not encompass any other damages, including but not limited to loss of profit, special, incidental, consequential, or other similar claims. BORLAND INTERNATIONAL, INC., SPECIFICALLY DISCLAIMS ALL OTHER WARRANTIES, EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE WITH RESPECT TO DEFECTS IN THE DISKETTE AND DOCUMENTAITON, AND THE PROGRAM LICENSE GRANTED HEREIN. IN PARTICULAR, AND WITHOUT LlMIMTING OPERATION OF THE PROGRAM LICENSE WITH RESPECT TO ANY PARTICULAR APPLICATION, USE, OR PURPOSE. IN NO EVENT SHALL BORLAND BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGE, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL OR OTHER DAMAGES. GOVERNING LAW This Statement shall be construed, interpreted and governed by the laws of the state of California. PREFACE Congratulations! Since you have this book, you have undoubtedly joined the ranks of the 200,000+ owners and users of TURBO Pascal. And you've probably bought this book to help you better learn how to use TURBO Pascal. That's what this book is for, and we don't think that you'll be disappointed. If you're a novice computer user, or novice programmer, then you'll probably want to begin with Part I, TURBO Pascal for the Absolute Novice. This will help you to get your feet wet, showing you just how to get started with TURBO Pascal. If you're a more experienced programmer, you may want to skim through these chapters, especially Chapter 6, Getting Started with TURBO Pascal. If you know yourway around a computer pretty well, then you're probably ready to dive into Part II, A Programmer's Guide to TURBO Pascal. This starts right at rock bottom and builds swiftly, taking you step by step through all the different aspects of Pascal in general, and TURBO Pascal in particular. By the time you get to the end, you should have a solid foundation in Pascal and be able to glean any additional needed information from the TURBO Pascal Reference Manual and other books. Once you feel comfortable with TURBO Pascal, you might take a look at Part III, Advanced Topics in TURBO Pascal. This section contains listings of working programs, showing you how to do things like read the directory off a disk or communicate through a serial port. The listings also demonstrate different programming techniques; they're worth studying for that, if for no other reason. Of course, this book is more than just a book: it comes with a disk as well. The disk is filled with running programs and tutorial information, giving you a ready-made library of routines to copy into your own programs. This is both time-saving and edu cational, especially as you adapt these routines to suit your needs. iii This book, of course, can't replace the TURBO Pascal Reference Manual. Rather, this book's goal is to help you grasp the basic principles underlying Pascal and its various aspects; the Re ference Manual can then help pOint out the exact definitions of the TURBO Pascal implementation. Hope you enjoy your exploration. Good luck and have fun! - Borland I nternational Inc. Acknowledgements The following products mentioned in this manual are manufactured and/or sold by the following companies: The IBM Personal Computer (PC) is a product of IBM. IBM® is a registered trademark of International Business Machines Corporation. MicroPro® and WordStar® are registered trademarks of MicroPro International Corporation. CP/M® is a registered trademark and CP/M-80™ and CP/M-86™ are trademarks of Digital Research. Inc. Microsoft® is a registered trademark and MS™ is a trademark of Microsoft Corporation. Tupperware® is a registered trademark of Dart Industries Inc. TURBO™ Pascal and SideKick™ are trademarks of Borland International. Inc. Third Edition. January. 1985 Printed in the United States of America 987654321 iv ABOUT THE AUTHOR Frank Borland is more mystique than mystic, as elusive as the Trinity Alps big foot, as shy as the famous Loch Ness monster. Even at Borland International, his namesake, few people have ever seen him. The old-timers recognize him for his remarkable algorithms, still the fastest in the west. Borland lives deep in the Santa Cruz mountains with his transportable computer, his burro, and his dogs. In the early days, he didn't have a permanent homestead, but lived in a couple of camps deep in the redwood groves. Now, Frank has settled down a little, bought a cabin, and is raising a family, thanks to the success of his programming. These days he is seen even less around town, but still can occasionally be reached by modem. If you are a Compuserve user, you are closer to Frank Borland than you realize. He is writing either a gothic novel or an epic poem-he hasn't decided which-entirely in bulletin board messages left on different SIGS (Special Interest Groups). But he never uses his real name, and he switches names often, so his writing is hard to follow. Look for messages in cadence, or rhymes. (You can find information on Borland products and a Borland SIG by typing GO BOR from any Compuserve prompt.) Frank is a warm-hearted person. He wrote Sidekick (one of his latest programming efforts) for humanitarian reasons. Carrying notepads, calculator, and calendar from camp to camp was beginning to stunt the growth of his burro, Lotus, so he wrote Sidekick to make all that unnecessary. He left a note in our mailbox, saying he'd saved Lotus' development. He rarely talks about his background, or why he chose to abandon normal life and take to the mountains. Some say it had do to with changing the whole motherboard on a PC, just to replace a single chip. Others blame the high price of micro computer software. We don't really know. Do you? v TABLE OF CONTENTS Preface 0 0 0 0 000 0 0 0 0 0 0 0 0 0 0 00000 0 0 00000000 0 0 0 0 0 0 000 iii About the Author 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v PART I TURBO PASCAL FOR THE ABSOLUTE NOVICE 1. Introduction to TURBO Pascal 0 0 0 • 0 0 0 • 0 •• 0 0 0 1-1 2. A Short History of Pascal 0 •• 0000.000.00000.0 2-1 3. Writing a Simple Program. 0 • 0 0 0 0 0 • 0 0 0 0 0 • 0 0 •• 3-1 4. Programming is More Than Writing a Program 0 0 0 • 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 • 0 0 0 0 4-1 4.1 Data 00000000000.000.00 •••• 00 •• 0000.. 4-1 4.2 Variables 0 • 0 •• 0 0 • 0 0 0 0 0 0 0 0 0 • 0 0 0 • 0 • 0 0 •• 4-4 4.3 Statements. 0 • 0 0 0 0 0 0 0 0 • 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4-5 5. Developing a Program 0 0 0 0 0 •• 0 0 0 0 0 0 0 0 •• 0 • 0 0 0 5-1 5.1 Pseudocode 00.0.0.000000 •• 0 • 0 0 0 • 0 0 •• 5-4 6. Getting Started with TURBO Pascal 0.000000. 6-1 6.1 Turbo Pascal ... 0 0 0 0 0 • 0 0 0 • 0 0 00 •• 0 0 • 0 0 6-2 6.2 The Main Menu 0 • 0 0 0 • 0 0 •• 0 0 0 0 • 0 0 0 0 0 •• 6-3 6.3 Conclusion 0 0.0 •• 00.00.000000000000.. 6-16 PART II A PROGRAMMER'S GUIDE TO TURBO PASCAL 7. The Basics of Pascal. 0 0 • 0 0 0 0 0 0 0 0 .0 0 • 0 0 .0.0. 7-1 7.1 A Quick Example 00000000000000.00.00 7-1 7.2 Some Pascal Terms.