C++ weekend crash course 2000

502 64 0
C++ weekend crash course 2000

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

4689-9 FM.f.qc 3/7/00 9:16 PM Page i C++ Weekend Crash Course 4689-9 FM.f.qc 3/7/00 9:16 PM Page ii 4689-9 FM.f.qc 3/7/00 9:16 PM Page iii C++ Weekend Crash Course Stephen R Davis IDG Books Worldwide, Inc An International Data Group Company Foster City, CA ◆ Chicago, IL ◆ Indianapolis, IN ◆ New York, NY 4689-9 FM.f.qc 3/7/00 9:17 PM Page iv C++ Weekend Crash Course Published by IDG Books Worldwide, Inc An International Data Group Company 919 E Hillsdale Blvd., Suite 400 Foster City, CA 94404 www.idgbooks.com (IDG Books Worldwide Web site) Copyright © 2000 IDG Books Worldwide, Inc All rights reserved No part of this book, including interior design, cover design, and icons, may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording, or otherwise) without the prior written permission of the publisher Library of Congress Card Number: 00-101537 ISBN: 0-7645-4689-9 Printed in the United States of America 10 1B/RS/QU/QQ/FC Distributed in the United States by IDG Books Worldwide, Inc Distributed by CDG Books Canada Inc for Canada; by Transworld Publishers Limited in the United Kingdom; by IDG Norge Books for Norway; by IDG Sweden Books for Sweden; by IDG Books Australia Publishing Corporation Pty Ltd for Australia and New Zealand; by TransQuest Publishers Pte Ltd for Singapore, Malaysia, Thailand, Indonesia, and Hong Kong; by Gotop Information Inc for Taiwan; by ICG Muse, Inc for Japan; by Intersoft for South Africa; by Eyrolles for France; by International Thomson Publishing for Germany, Austria, and Switzerland; by Distribuidora Cuspide for Argentina; by LR International for Brazil; by Galileo Libros for Chile; by Ediciones ZETA S.C.R Ltda for Peru; by WS Computer Publishing Corporation, Inc., for the Philippines; by Contemporanea de Ediciones for Venezuela; by Express Computer Distributors for the Caribbean and West Indies; by Micronesia Media Distributor, Inc for Micronesia; by Chips Computadoras S.A de C.V for Mexico; by Editorial Norma de Panama S.A for Panama; by American Bookshops for Finland For general information on IDG Books Worldwide’s books in the U.S., please call our Consumer Customer Service department at 800-762-2974 For reseller information, including discounts and premium sales, please call our Reseller Customer Service department at 800-434-3422 For information on where to purchase IDG Books Worldwide’s books outside the U.S., please contact our International Sales department at 317-596-5530 or fax 317-572-4002 For consumer information on foreign language translations, please contact our Customer Service department at 800-434-3422, fax 317-572-4002, or e-mail rights@idgbooks.com For information on licensing foreign or domestic rights, please phone +1-650-653-7098 For sales inquiries and special prices for bulk quantities, please contact our Order Services department at 800-434-3422 or write to the address above For information on using IDG Books Worldwide’s books in the classroom or for ordering examination copies, please contact our Educational Sales department at 800-434-2086 or fax 317-572-4005 For press review copies, author interviews, or other publicity information, please contact our Public Relations department at 650-653-7000 or fax 650-653-7500 For authorization to photocopy items for corporate, personal, or educational use, please contact Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, or fax 978-750-4470 LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK THE PUBLISHER AND AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE THERE ARE NO WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS PARAGRAPH NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS THE ACCURACY AND COMPLETENESS OF THE INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES Trademarks: All brand names and product names used in this book are trade names, service marks, trademarks, or registered trademarks of their respective owners IDG Books Worldwide is not associated with any product or vendor mentioned in this book is a registered trademark or trademark under exclusive license to IDG Books Worldwide, Inc from International Data Group, Inc in the United States and/or other countries 4689-9 FM.f.qc 3/7/00 9:17 PM Page v Welcome to the world of IDG Books Worldwide IDG Books Worldwide, Inc., is a subsidiary of International Data Group, the world’s largest publisher of computer-related information and the leading global provider of information services on information technology IDG was founded more than 30 years ago by Patrick J McGovern and now employs more than 9,000 people worldwide IDG publishes more than 290 computer publications in over 75 countries More than 90 million people read one or more IDG publications each month Launched in 1990, IDG Books Worldwide is today the #1 publisher of best-selling computer books in the United States We are proud to have received eight awards from the Computer Press Association in recognition of editorial excellence and three from Computer Currents’ First Annual Readers’ Choice Awards Our bestselling For Dummies® series has more than 50 million copies in print with translations in 31 languages IDG Books Worldwide, through a joint venture with IDG’s Hi-Tech Beijing, became the first U.S publisher to publish a computer book in the People’s Republic of China In record time, IDG Books Worldwide has become the first choice for millions of readers around the world who want to learn how to better manage their businesses Our mission is simple: Every one of our books is designed to bring extra value and skill-building instructions to the reader Our books are written by experts who understand and care about our readers The knowledge base of our editorial staff comes from years of experience in publishing, education, and journalism — experience we use to produce books to carry us into the new millennium In short, we care about books, so we attract the best people We devote special attention to details such as audience, interior design, use of icons, and illustrations And because we use an efficient process of authoring, editing, and desktop publishing our books electronically, we can spend more time ensuring superior content and less time on the technicalities of making books You can count on our commitment to deliver high-quality books at competitive prices on topics you want to read about At IDG Books Worldwide, we continue in the IDG tradition of delivering quality for more than 30 years You’ll find no better book on a subject than one from IDG Books Worldwide John Kilcullen Chairman and CEO IDG Books Worldwide, Inc Eighth Annual Computer Press Awards 1992 Ninth Annual Computer Press Awards 1993 Tenth Annual Computer Press Awards 1994 Eleventh Annual Computer Press Awards 1995 IDG is the world’s leading IT media, research and exposition company Founded in 1964, IDG had 1997 revenues of $2.05 billion and has more than 9,000 employees worldwide IDG offers the widest range of media options that reach IT buyers in 75 countries representing 95% of worldwide IT spending IDG’s diverse product and services portfolio spans six key areas including print publishing, online publishing, expositions and conferences, market research, education and training, and global marketing services More than 90 million people read one or more of IDG’s 290 magazines and newspapers, including IDG’s leading global brands — Computerworld, PC World, Network World, Macworld and the Channel World family of publications IDG Books Worldwide is one of the fastest-growing computer book publishers in the world, with more than 700 titles in 36 languages The “ For Dummies®” series alone has more than 50 million copies in print IDG offers online users the largest network of technology-specific Web sites around the world through IDG.net (http://www.idg.net), which comprises more than 225 targeted Web sites in 55 countries worldwide International Data Corporation (IDC) is the world’s largest provider of information technology data, analysis and consulting, with research centers in over 41 countries and more than 400 research analysts worldwide IDG World Expo is a leading producer of more than 168 globally branded conferences and expositions in 35 countries including E3 (Electronic Entertainment Expo), Macworld Expo, ComNet, Windows World Expo, ICE (Internet Commerce Expo), Agenda, DEMO, and Spotlight IDG’s training subsidiary, ExecuTrain, is the world’s largest computer training company, with more than 230 locations worldwide and 785 training courses IDG Marketing Services helps industry-leading IT companies build international brand recognition by developing global integrated marketing programs via IDG’s print, online and exposition products worldwide Further information about the company can be found at www.idg.com 1/26/00 4689-9 FM.f.qc 3/7/00 9:17 PM Page vi Credits Acquisitions Editor Greg Croy Project Editor Matthew E Lusher Technical Editor Greg L Guntle Copy Editors S.B Kleinman Rich Adin Media Development Specialist Jason Lusher Graphics and Production Specialists Robert Bihlmayer Jude Levinson Michael Lewis Ramses Ramirez Victor Pérez-Varela Dina F Quan Quality Control Specialist Laura Taflinger Proofreading and Indexing York Production Services Permissions Editor Lenora Chin Sell Illustrators Mary Jo Richards Brent Savage Media Development Manager Stephen Noetzel Cover Design Clark Creative Group Project Coordinators Linda Marousek Louigene A Santos Marcos Vergara About the Author A 43-year-old father and husband, lives and works in Greenville, Texas as a programmer both at work and at play when he’s not riding his bicycle or hauling his son to Tae Kwon Do events 4689-9 FM.f.qc 3/7/00 9:17 PM Page vii to my wonderful new nieces, Christa and Sarah 4689-9 FM.f.qc 3/7/00 9:17 PM Page viii 4689-9 FM.f.qc 3/7/00 9:17 PM Page ix Preface C ++ Weekend Crash Course teaches the reader C++ in one admittedly busy weekend: 30 sessions of a half-hour each, for 15 hours stretching from Friday evening to Sunday afternoon At the end of each part of the book, you’ll get a chance to pause, reflect, and review what you’ve just learned before pushing on through the rest Good luck! What is C++? C++ is the most popular programming language in use today C++ is used in applications from the micro-programs that drive your microwave oven, your clothes washer and your TV up through the huge, hardcore programs that control nuclear missiles and Mars rockets — heh, you can’t blame the Mars rockets on C++ In the late 1980s C began to show signs of age For one, C does not support the object-oriented programming style At the time, the object-oriented wave was taking the world by storm Employers were throwing money at object-oriented programmers All you had to was work the phrase “new paradigm” into the conversation in order to gather a crowd of admirers The problem was that every program worth its salt was written in C (there were a few programs written in Pascal like early versions of Windows, but they don’t count — if you are familiar with the earliest versions of Windows, you know why) There was no way that companies were going to rewrite all that code just to ride the object-oriented wave Object-oriented concepts had to be grafted onto the existing C language The result was called C++ 4689-9 FM.f.qc 3/7/00 9:17 PM Page x x Preface C++ is a superset of C Any well written C program can be rebuilt with a C++ tool to generate a working program That meant the companies could upgrade their software in pieces Existing code could remain in C while new code adopted the extra features of C++ Fortunately for us, C++ is a standardized language The American National Standards Institute (ANSI) and International Standards Organization (ISO) agree on what C++ is They issued a detailed description of the C++ language This standardized language is often known as ANSI or ISO standard C++ or simply Standard C++ Standard C++ is not controlled by a single company such as Microsoft (or Sun, for that matter) The Standard C++ community is not held hostage to the whims of any one corporate giant In addition, companies not stray Even Microsoft’s Visual C++ holds tightly to the C++ standard The programs in C++ Weekend Crash Course in can be built using any Standard C++ implementation The Object-Oriented Paradigm Object-oriented programming is not all hype Object-oriented programming really is a different approach to programming than its predecessor Object-oriented programs are easier to write and maintain Object-oriented modules can be reused with greater ease than those written in older styles C++ Weekend Crash Course presents more than just the C++ language You need to learn the object-oriented paradigm in order to make complete use of the power of C++ C++ Weekend Crash Course uses C++ examples to teach you the object-oriented view of the world Anyone who claims to program in C++ without understanding OO concepts is just using C++ as a “better C” Who C++ Weekend Crash Course is intended for the beginner through the intermediate reader This book serves the beginner by not assuming any knowledge of programming or programming concepts The first few lessons go over real-world, non-techie explanations of what programming is This book is also great for the home programmer The multiple examples demonstrate programming techniques used in modern, high speed programs 4689-9 appB.f.qc 3/7/00 9:39 PM Page 494 494 Appendix B while(target[index]) { // if the current member of the // string matches the target // character if (target[index] == testChar) { // then return the index return index; } // skip to the next character index++; } // if we exited the loop then we must // have encountered the end without // finding the desired character return -1; } If the target character is found, the index value is returned immediately If control exits the loop, it can only mean that the end of the string was encountered without finding the desired character Personally, I find this style more straightforward; however, some organizations have a rule against multiple returns in a single function A double occupies bytes whereas an int occupies only bytes It’s entirely possible that C++ would use of the bytes to store the integer 10, leaving the other bytes unused This would not cause an error; however, you should not assume that your compiler would work this way void displayString(char* pszString) { while(*pszString) { cout n1 and pmc->n2 are garbage because the pointer pmc was not initialized to point to anything In fact, the program might abort without generating any output due to a bad pointer Sunday Morning class Vehicle { public: Vehicle(int nWheels) { } }; class Motor { public: Motor(int nCylinders) { } }; class Car : pubic Vehicle { public: Car(int nCyliners, int nWheels) : Vehicle(nWheels), motor(nCylinders) { } Motor motor; }; 495 4689-9 appB.f.qc 3/7/00 9:39 PM Page 496 4689-9 appC.f.qc 3/7/00 9:39 PM Page 497 APPENDIX C What’s On the CD-ROM T he CD-ROM that accompanies this book contains materials to help you work through the sessions and learn C++ in a weekend: ¼ Installation files for the GNU C++ compiler ¼ The C++ Weekend Crash Course Self-Assessment Test ¼ A complete set of all the programs from the book GNU C++ The installation files for GNU C++ that you’ll find on this CD-ROM were taken from the Delorie Web site mentioned in Session Here we’ve provided complete sets of install files for Windows 95, 98 and NT/2000 To install GNU C++ from these files, follow these steps: Create a folder named \DJGPP Copy the complete set of Zip files from the appropriate folder on the CD-ROM for your version of Windows into the DJGPP folder Unzip the files into the DJGPP folder itself Add the following commands to AUTOEXEC.BAT: set PATH=C:\DJGPP\BIN;%PATH% set DJGPP=C:\DJGPP\DJGPP.ENV 4689-9 appC.f.qc 3/7/00 9:39 PM Page 498 498 Appendix C Note: the above command lines assume your DJGPP folder is directly under C:\ If you’ve placed your DJGPP folder somewhere else, substitute that path in the commands above Reboot to complete the installation The \BIN folder, created when you unzip the files, includes the actual GNU tool executables The DJGPP.ENV file sets a series of options to describe the Windows GNU C++ “environment.” Tip Before you begin using GNU C++ check the DJGPP.ENV file to make sure that Long File Name support is enabled Disabling Long File Name support is the most common GNU C++ installation error Open the DJGPP.ENV file using a text file editor such as Microsoft Notebook Don’t worry if you see one long string of text punctuated by little black boxes — Unix uses a different newline character than Windows Look for the phrase “LFN=y” or “LFN=Y” (the case is not important) If you find “LFN=n” instead (or if you don’t find “LFN” at all), change the “n” to a “y” Save the file (Make sure that you save the file as an ASCII text file and not in some other format such as a Word DOC file.) C++ Weekend Crash Course Self-Assessment Test The C++ Weekend Crash Course Self-Assessment Test provides you with a way to check your knowledge and skills once you’ve completed the book Its fifty questions cover the entire range of basic C++ concepts Sample Programs The \Programs folder contains the source code for each of the programs found in the book I suggest that you copy the entire folder and all its subfolders to your hard disk; however, you may copy individual source files if you prefer The programs are separated by session Each session’s folder includes the CPP source file plus executables; the latter are present only as a convenience to the reader You may execute the programs directly from the CD-ROM The EXE executable found in the folder itself was generated by GNU C++ The Visual C++ EXE is present in a subfolder named DEBUG 4689-9 appC.f.qc 3/7/00 9:39 PM Page 499 What’s on the CD-ROM 499 Session contains directions for building a program using Visual C++ Session contains similar instructions for GNU C++ Note: Two source files are slightly modified from that appearing in the book: The function ltoa() has been replaced with a call to the functionally equivalent function itoa() in ToStringWOStream.cpp in Session 29 GNU C++ uses the full name strstream.h while Visual C++ uses the 8.3 format of strstrea.h The reference to this include file in ToStringWStream.cpp must be adjusted accordingly The source code appearing here uses an #ifdef to decide automatically which include file name to use The source code in the book indicates the problem via a comment 4689-9 appC.f.qc 3/7/00 9:39 PM Page 500 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 517 APPENDIX GNU GENERAL PUBLIC LICENSE A Version 2, June 1991 Copyright  1989, 1991 Free Software Foundation, Inc 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed Preamble The licenses for most software are designed to take away your freedom to share and change it By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This General Public License applies to most of the Free Software Foundation’s software and to any other program whose authors commit to using it (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too When we speak of free software, we are referring to freedom, not price Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can these things To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have You must make sure that they, too, receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software Also, for each author’s protection and ours, we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on, we want its recipients to know that what 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 518 they have is not the original, so that any problems introduced by others will not reflect on the original authors’ reputations Finally, any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary To prevent this, we have made it clear that any patent must be licensed for everyone’s free use or not licensed at all The precise terms and conditions for copying, distribution and modification follow TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License The “Program”, below, refers to any such program or work, and a “work based on the Program” means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language (Hereinafter, translation is included without limitation in the term “modification”.) Each licensee is addressed as “you” Activities other than copying, distribution and modification are not covered by this License; they are outside its scope The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program) Whether that is true depends on what the Program does You may copy and distribute verbatim copies of the Program’s source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 519 You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, not apply to those sections when you distribute them as separate works But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 520 You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections and above provided that you also one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections and above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections and above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 521 You are not required to accept this License, since you have not signed it However, nothing else grants you permission to modify or distribute the Program or its derivative works These actions are prohibited by law if you not accept this License Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions You may not impose any further restrictions on the recipients’ exercise of the rights granted herein You are not responsible for enforcing compliance by third parties to this License If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they not excuse you from the conditions of this License If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all For example, if a patent license would not permit royaltyfree redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 522 This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded In such case, this License incorporates the limitation as if written in the body of this License The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns Each version is given a distinguishing version number If the Program specifies a version number of this License which applies to it and “any later version”, you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation 10 If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally NO WARRANTY 11 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE THE ENTIRE 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 523 RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION 12 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES *****END OF TERMS AND CONDITIONS***** How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms To so, attach the following notices to the program It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the “copyright” line and a pointer to where the full notice is found one line to give the program’s name and an idea of what it does Copyright (C) yyyy name of author This program is modify it under as published by of the License, free software; you can redistribute it and/or the terms of the GNU General Public License the Free Software Foundation; either version or (at your option) any later version This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General Public License for more details 4689-9 GNU.f.qc 3/7/00 9:40 PM Page 524 You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA Also add information on how to contact you by electronic and paper mail If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) yyyy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’ This is free software, and you are welcome to redistribute it under certain conditions; type ‘show c’ for details The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate parts of the General Public License Of course, the commands you use may be called something other than ‘show w’ and ‘show c’; they could even be mouseclicks or menu items whatever suits your program You should also get your employer (if you work as a programmer) or your school, if any, to sign a “copyright disclaimer” for the program, if necessary Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision’ (which makes passes at compilers) written by James Hacker signature of Ty Coon, April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library If this is what you want to do, use the GNU Library General Public License instead of this License ... styles C++ Weekend Crash Course presents more than just the C++ language You need to learn the object-oriented paradigm in order to make complete use of the power of C++ C++ Weekend Crash Course. .. install and use both GNU C++ and Visual C++ How C++ Weekend Crash Course follows a one -weekend format Start with Friday evening; conclude Sunday afternoon This “One weekend format is: ¼ ideal... programs in C++ Many readers will already own a programming environment such as Microsoft’s ubiquitous Visual C++ For those who not own a C++ environment already, C++ Weekend Crash Course includes

Ngày đăng: 25/03/2019, 17:11

Từ khóa liên quan

Mục lục

  • Cover

  • Preface

  • Contents

  • Chapter01

  • Chapter02

  • Chapter03

  • Chapter04

  • Chapter05

  • Chapter06

  • Chapter07

  • Chapter08

  • Chapter09

  • Chapter10

  • Chapter11

  • Chapter12

  • Chapter13

  • Chapter14

  • Chapter15

  • Chapter16

  • Chapter17

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan