C++ By
EXAMPLE
C++
By
Greg Perry
i
Contents '
C++ By Example
© 1992 by Que
All rights reserved. Printed in the United States of America. No part of this
book may be used or reproduced, in any form or by any means, or stored
in a database or retrieval system, without prior written permission of the
publisher except in the case of brief quotations embodied in critical articles
and reviews. Making copies of any part of this book for any purpose other
than your own personal use is a violation of United States copyright laws.
For information, address Que, 11711 N. College Ave., Carmel, IN 46032.
Library of Congress Catalog Card Number: 92-64353
ISBN: 1-56529-038-0
This book is sold as is, without warranty of any kind, either express or
implied, respecting the contents of this book, including but not limited to
implied warranties for the book’s quality, performance, merchantability,
or fitness for any particular purpose. Neither Que Corporation nor its
dealers or distributors shall be liable to the purchaser or any other person
or entity with respect to any liability, loss, or damage caused or alleged to
be caused directly or indirectly by this book.
96
3
Interpretation of the printing code: the rightmost double-digit number is
the year of the book’s printing; the rightmost single-digit number, the
number of the book’s printing. For example, a printing code of 92-1 shows
that the first printing of the book occurred in 1992.
95
92
94
93
8
7
6
5
4
2
1
ii
C++ By
EXAMPLE
Book Design
Scott Cook
Michele Laseau
Production Analyst
Mary Beth Wakefield
Cover Design
Jean Bisesi
Indexer
Johnna VanHoose
Production
Caroline Roop (Book Shepherd)
Jeff Baker, Paula Carroll,
Michelle Cleary, Brook Farling,
Kate Godfrey, Bob LaRoche,
Laurie Lee, Jay Lesandrini,
Cindy L. Phipps, Linda Seifert,
Phil Worthington
Publisher
Lloyd Short
Publishing Manager
Joseph Wikert
Development Editor
Stacy Hiquet
Production Editor
Kezia Endsley
Copy Editor
Bryan Gambrel
Technical Editor
Tim Moore
Editorial Assistants
Rosemarie Graham
Melissa Keegan
Composed in Palatino and MCPdigital typefaces by Prentice Hall Computer Publishing.
Screen reproductions in this book were created by means of the program Collage Plus
from Inner Media, Inc., Hollis, NH.
iii
Contents '
Dedication
Dr. Rick Burgess, you shaped my life. Good or bad, I’m what I am
thanks to your help. I appreciate the many hours we’ve shared together.
G.M.P.
iv
About the Author
EXAMPLE
C++ By
Greg Perry has been a programmer and trainer for the past 14 years.
He received his first degree in computer science, then he received a
Masters degree in corporate finance. He currently is a professor of
computer science at Tulsa Junior College, as well as a computer
consultant and a lecturer. Greg Perry is the author of 11 other
computer books, including QBASIC By Example and C By Example. In
addition, he has published articles in several publications, including
PC World, Data Training, and Inside First Publisher. He has attended
computer conferences and trade shows in several countries, and is
fluent in nine computer languages.
v
Contents '
vi
EXAMPLE
Acknowledgments
C++ By
Much thanks to Stacy Hiquet and Joseph Wikert at Prentice Hall
(Que) for trusting me completely with the direction and style of this
book. The rest of my editors: Kezia Endsley, Bryan Gambrel, and the
Technical Editor, Tim Moore, kept me on track so the readers can
have an accurate and readable text.
The Tulsa Junior College administration continues to be sup-
portive of my writing. More importantly, Diane Moore, head of our
Business Services Division, Tony Hirad, and Elaine Harris, are
friends who make teaching a joy and not a job.
As always, my beautiful bride Jayne, and my parents Glen and
Bettye Perry, are my closest daily companions. It is for them I work.
Trademark Acknowledgments
Que Corporation has made every attempt to supply trademark
information about company names, products, and services men-
tioned in this book. Trademarks indicated below were derived from
various sources. Que Corporation cannot attest to the accuracy of
this information.
AT&T is a registered trademark of American Telephone &
Telegraph Company.
FORTRAN and COBOL are trademarks of International
Business Machines Corporation (IBM).
Turbo BASIC is a registered trademark of Borland
International, Inc.
Turbo C is a registered trademark of Borland International, Inc.
Microsoft QuickC and MS-DOS are registered trademarks of
Microsoft Corporation.
ANSI is a registered trademark of American National Standards
Institute.
vii
Contents '
viii