CORONADO ENTERPRISES C++ TUTORIAL - Version 2.0 This documentation and the accompanying software, including all of the example C++ programs and text files, are protected under United States copyright law to protect them from unauthorized commercial- ization. This version of the tutorial is distributed under the shareware concept, which means you are not required to pay for it. You are permitted to copy the disks, and pass the copies on to a friend, provided that you do not modify any files or omit any files from the complete package, and you are in fact encouraged to pass on complete copies to friends. You are permitted to charge a small fee to cover the costs of duplication, but you are not permitted to charge anything for the software itself. If you find the tutorial helpful, you are encouraged to register with the author and to submit a small fee to help compensate him for his time and expense in writing it. We will provide you with a beautifully printed copy of this tutorial if you submit a full registration. See the READ.ME file on either diskette for addi- tional details. Whether or not you send a registration fee, feel free to request a copy of the latest list of available tutorials and a list of the authorized Public Domain libraries that distribute our full line of programming language tutorials. Gordon Dodrill - July 20, 1990 Copyright (c) 1989, 1990, Coronado Enterprises Coronado Enterprises 12501 Coronado Ave NE Albuquerque, New Mexico 87122 C++ TUTORIAL - TABLE OF CONTENTS Introduction Page I-1 Chapter 1 - Simple Things Page 1-1 CONCOM.CPP Constants and comments 1-1 SCOPEOP.CPP Scope operator 1-3 MESSAGE.CPP The stream library 1-3 FSTREAM.CPP File streams 1-6 VARDEF.CPP Variable definitions 1-7 Chapter 2 - Compound Types Page 2-1 ENUM.CPP The enumerated type 2-1 STRUCTUR.CPP The structure 2-1 CLASS1.CPP The class 2-2 UNIONEX.CPP The union 2-3 TYPECONV.CPP Type conversions 2-4 Chapter 3 - Pointers Page 3-1 POINTERS.CPP Using Pointers 3-1 NEWDEL.CPP New and delete operators 3-3 FUNCPNT.CPP Function pointers 3-5 Chapter 4 - Functions Page 4-1 PROTYPE1.CPP Using prototypes 4-1 PROTYPE2.CPP Using prototypes 4-3 PASSREF.CPP Pass by reference 4-5 DEFAULT.CPP Parameter defaults 4-6 VARARGS.CPP Variable number of arguments 4-7 OVERLOAD.CPP Overloading function names 4-8 Chapter 5 - Encapsulation Page 5-1 OPEN.CPP No information hiding 5-1 CLAS.CPP Information hiding 5-2 OPENPOLE.CPP Corruptible data 5-6 CLASPOLE.CPP Protected data 5-7 CONSPOLE.CPP Constructors and destructors 5-10 BOXES1.CPP All in one file 5-11 BOX.HPP Box interface 5-12 BOX.CPP Box implementation 5-12 BOXES2.CPP Using the box class 5-13 Chapter 6 - More encapsulation Page 6-1 OBJARRAY.CPP An Array of objects 6-1 OBJSTRNG.CPP An object with a string 6-3 OBJINTPT.CPP An object with a pointer 6-3 OBJDYNAM.CPP Dynamic allocation of objects 6-5 OBJLIST.CPP Embedded pointers 6-6 OBJLINK.CPP Linked list of objects 6-7 NESTING.CPP Nested classes 6-9 OPOVERLD.CPP Operator overloading 6-10 FUNCOVER.CPP Function name overloading 6-12 Chapter 7 - Inheritance Page 7-1 VEHICLE.HPP Vehicle interface 7-1 VEHICLE.CPP Vehicle implementation 7-2 TRANSPRT.CPP Using the vehicle class 7-2 CAR.HPP Car interface 7-3 CAR.CPP Car implementation 7-4 TRUCK.HPP Truck interface 7-5 TRUCK.CPP Truck implementation 7-6 ALLVEHIC.CPP Use of car, truck, & vehicle 7-6 Chapter 8 - More inheritance Page 8-1 INHERIT1.CPP Using public 8-1 INHERIT2.CPP Omitting public 8-2 INHERIT3.CPP Intra class messages 8-4 INHERIT4.CPP Using protected 8-4 INHERIT5.CPP Using constructors 8-6 INHERIT6.CPP Arrays and pointers 8-6 Chapter 9 - Multiple Inheritance Page 9-1 MULTINH1.CPP Multiple inheritance 9-2 MULTINH2.CPP Duplicate method names 9-3 MULTINH3.CPP Duplicate variable names 9-4 Chapter 10 - Virtual functions Page 10-1 VIRTUAL1.CPP The starting point 10-1 VIRTUAL2.CPP Adding virtual 10-3 VIRTUAL3.CPP Using pointers to subclasses 10-3 VIRTUAL4.CPP Using virtual 10-4 VIRTUAL5.CPP Using pointers to parent class 10-4 VIRTUAL6.CPP True virtual functions 10-6 Chapter 11 - More Virtual Functions Page 11-1 PERSON.HPP Person header 11-1 PERSON.CPP Person implementation 11-2 SUPERVSR.HPP Personnel header 11-2 SUPERVSR.CPP Personnel implementation 11-3 EMPLOYEE.CPP A simple user program 11-3 ELEMLIST.HPP Linked list header 11-4 ELEMLIST.CPP Linked list implementation 11-5 EMPLOYE2.CPP A better user program 11-5 Chapter 12 - Flyaway adventure game Page 12-1 FLYAWAY.EXE Flyaway executable 12-1 CLOCK.HPP Clock header 12-2 CLOCK.CPP Clock implementation 12-2 ITEMS.HPP Moveable items header 12-3 ITEMS.CPP Items implementation 12-3 SCHEDULE.HPP Scheduler header 12-4 SCHEDULE.CPP Scheduler implementation 12-4 LOCATION.HPP Locations header 12-5 LOCATION.CPP Locations implementation 12-5 MESSAGE.H Hint messages 12-6 FLYAWAY.H Nouns and verbs 12-7 COMMAND.CPP Command parser 12-7 FLYAWAY.CPP Main program 12-8 ABOUT THE AUTHOR _________________________________________________________________ The author of this tutorial began programming in 1961 using FORTRAN on an IBM 1620. Since then, most of his career has been involved with designing digital logic for satellite application. In 1983, being somewhat burned out with logic design, he began a study of some of the more modern programming languages and has since made a complete career shift to software development. After learning Pascal, C was studied, followed by Modula-2 and Ada, and more recently C++. Rather than simply learning the syntax of each new language, modern methods of software engineering were studied and applied to effectively utilize the languages. He is currently employed by a large research and development laboratory where he continues to study, teach, and apply the newer programming languages.