0% found this document useful (0 votes)
103 views

Programming Principles and Practice Using C 1st Edition Bjarne Stroustrup instant download

The document provides links to various programming and academic ebooks, including 'Programming Principles and Practice Using C' by Bjarne Stroustrup and other titles on programming and philosophy. It includes details about the contents and structure of the book, as well as information on how to obtain permissions for reproduction. The document also emphasizes the importance of programming education and offers insights into the author's philosophy of teaching and learning.

Uploaded by

ishovladab6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Programming Principles and Practice Using C 1st Edition Bjarne Stroustrup instant download

The document provides links to various programming and academic ebooks, including 'Programming Principles and Practice Using C' by Bjarne Stroustrup and other titles on programming and philosophy. It includes details about the contents and structure of the book, as well as information on how to obtain permissions for reproduction. The document also emphasizes the importance of programming education and offers insights into the author's philosophy of teaching and learning.

Uploaded by

ishovladab6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Programming Principles and Practice Using C 1st

Edition Bjarne Stroustrup pdf download

https://ebookname.com/product/programming-principles-and-
practice-using-c-1st-edition-bjarne-stroustrup/

Get Instant Ebook Downloads – Browse at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Object Oriented Programming Using C Fourth Edition


Joyce Farrell

https://ebookname.com/product/object-oriented-programming-using-
c-fourth-edition-joyce-farrell/

Programming Fundamentals A Modular Structured Approach


Using C Kenneth Leroy Busbee

https://ebookname.com/product/programming-fundamentals-a-modular-
structured-approach-using-c-kenneth-leroy-busbee/

Goddess Traditions in Tantric Hinduism History Practice


and Doctrine 1st Edition Bjarne Wernicke Olesen
(Editor)

https://ebookname.com/product/goddess-traditions-in-tantric-
hinduism-history-practice-and-doctrine-1st-edition-bjarne-
wernicke-olesen-editor/

An Introduction to Political Philosophy 1st Edition


Alexander Rainy Maclean Murray

https://ebookname.com/product/an-introduction-to-political-
philosophy-1st-edition-alexander-rainy-maclean-murray/
Democratic Theorizing from the Margins 1st Edition
Marla Brettschneider

https://ebookname.com/product/democratic-theorizing-from-the-
margins-1st-edition-marla-brettschneider/

Working With Dreams Initiation into the Soul s Speaking


About Itself 1st Edition Wolfgang Giegerich

https://ebookname.com/product/working-with-dreams-initiation-
into-the-soul-s-speaking-about-itself-1st-edition-wolfgang-
giegerich/

Syntax A Functional typological Introduction Volume II


Talmy Givon

https://ebookname.com/product/syntax-a-functional-typological-
introduction-volume-ii-talmy-givon/

Making the British Empire 1660 1800 1st Edition Jason


Peacey

https://ebookname.com/product/making-the-british-
empire-1660-1800-1st-edition-jason-peacey/

The Introduction to the Magee System of Technical


Analysis 2nd Edition W.H.C. Bassetti

https://ebookname.com/product/the-introduction-to-the-magee-
system-of-technical-analysis-2nd-edition-w-h-c-bassetti/
Encyclopedia of law enforcement 1st Edition Larry E.
Sullivan

https://ebookname.com/product/encyclopedia-of-law-
enforcement-1st-edition-larry-e-sullivan/
Programming
Programming
Principles and Practice
Using C++

Bjarne Stroustrup

./.,· Addison-Wesley
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products arc claimed as
trademarks. Where those designations appear in this book. and tl1c publisher was aware of a trademark
claim, the designations have been primed witl1 initial capital letters or in all capitals.

A complete list of photo sources and credits appears on pages 1235-1236.

The author and publisher have taken care in the preparation of this book, but make no expressed or im·
plied warran t y of any kind and assume no responsibility for errors or omissioru. No liability is assumed
for incidental or consequential damages in connection witl1 or arising out of the usc of the information or
programs contained herein.

The publisher offers excellent discounts on tllis book when ordered in quantity for bulk purcl!ases or spe­
cial sales, wllich may include electronic versions and/or custom covers and content particular to your busi­
ness. training goals. marketing focus. and branding interests. For more information. please contact:

U.S. Corporate and Govcnuncnt Sales


(800) 382·3419
corpsales@pcarsontcclJgroup.com

For sales outside tl1c United States, please contact:

International Sales
intcmational@pearsoncd.com

Copyright (C' 2009 Pearson Education, Inc.

Stroustrup, Bjame.
Programming principles and practice using C++ I Bjamc Stroustrup.
P· em.
Includes bibliographical references and index.
ISBN 978-0-321-54372·1 (pbk. : alk. paper) I. C++ (Computer program language) I. Title.

QA76.73.C153S82 2008
005.13'3-dc22
2008032595

AU rights reserved. Printed in the United States of America. ll1is publication is protected by copyright, and
permission must be obtained from tl1c publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means. electronic, mechanical, photocopying, recording, or
likewise. For information regarding pemlissions, write to:

Pearson Education. Inc.


Rights and Contracts Department
501 Boylston Street, Suite 900
Boston, MA 02116
Fax (617) 671·3447

ISBN-13: 978·0·321·54372·1
ISBN-10: 0-321-54372·6
Text printed in the United States on recycled paper at Courier in Kendallville, Indiana.
Ftrst printing, December 2008
Contents

Preface xxiii
Chapter 0 Notes to the Reader
0.1 The structure of this book 2
0.1. 1 General approach 3
0.1.2 Drills, exercises, etc. 4
0.1.3 What comes after this book? 5
0.2 A philosophy of teaching and learning 6
0.2.1 The order of topics 9
0.2.2 Programming and programming language 10
0.2.3 Portability 11
0.3 Programming and computer science 12
0.4 Creativity and problem solving 12
0.5 Request for feedback 12
0.6 References 13
0.7 Biographies 14
Bjame Stroustrup 14
Lawrence "Pete" Petersen 15

"
vi CONTENTS

Chapter 1 Computers, People, and Programming 17


1. 1 Introduction 18
1.2 Software 19
1.3 People 21
1.4 Computer science 24
1.5 Computers are everywhere 25
1 .5.1 Screens and no screens 26
1.5.2 Shipping 26
1.5.3 Telecommunications 28
1.5.4 Medicine 30
1.5.5 Information 31
1.5.6 A vertical view 32
1 ..5. 7 So what? 34
1.6 Ideals for progranuners 34

Part I The Basics 41

Chapter 2 Hello, World! 43

2. 1 Programs 44
2.2 T he classic first program 45
2.3 Compilation 47
2.4 Linking 51
2.5 Programming environments 52

Chapter 3 Objects, Types, and Values 59


3 . 1 Input 60
3.2 Variables 62
3.3 Input and type 64
3.4 Operations and operators 66
3 .5 Assignment and initialization 69
3.5.1 An example: delete repeated words 71
3.6 Composite assignment operators 73
3.6.1 An example: count repeated words 73
3.7 Names 74
3.8 Types and objects 77
3.9 Type safety 78
3.9.1 Safe conversions 79
3.9.2 Unsafe conversions 80

Chapter 4 Computation 89
4.1 Computation 90
4.2 Objectives and tools 92
CONTENTS vii

4.3 Expressions 94
4.3.1 Constant expressions 95
4.3.2 Operators 96
4.3.3 Conversions 98
4.4 Statements 99
4.4.1 Selection 101
4.4.2 Iteration 108
4.5 Functions 1 12
4.5.1 Why bother with functions? 114
4.5.2 Function declarations 115
4.6 Vector 1 16
4.6.1 Growing a vector 118
4.6.2 A numeric example 119
4 .6.3 A text example 121
4.7 Language features 123

Chapter 5 Errors 1 31
5. 1 Introduction 132
5.2 Sources of errors 134
5.3 Compile-time errors 134
5.3.1 Syntax errors 135
5.3.2 Type errors 136
.5.3.3 Non-errors 137
5.4 Link-time errors 137
5.5 Run-time errors 138
5.5.1 T he caller deals with errors 140
5.5.2 l11e callee deals with errors 141
5.5.3 Error reporting 143
5.6 Exceptions 144
5.6.1 Bad arguments 145
5.6.2 Range errors 146
5.6.3 Bad input 148
5.6.4 Narrowing errors 151
5.7 Logic errors 152
5.8 Estimation 155
5.9 Debugging 156
5.9.1 Practical debug advice 1S7
5. 10 Pre- and post-conditions 161
5.10.1 Post·conditions 163
5. 1 1 Testing 164
viii CONTENTS

Chapter 6 Writing a Program 1 71


6. 1 A problem 172
6.2 Thinking about the problem 173
6.2 .1 Stages of development 174
6.2.2 Strateg y 174
6.3 Back to the calculator! 176
6.3.1 Frrst attempt 177
6.3.2 Tokens 179
6.3.3 Implementing tokens 181
6.3.4 Using tokens 183
6.3.5 Back to the drawing board 185
6.4 Grammars 186
6.4.1 A detour: English grammar 191
6.4.2 Writing a grammar 192
6.5 Turning a grammar into code 193
6.5.1 Implementing grammar rules 194
6.5.2 Expressions 195
6.5.3 Terms 198
6.5.4 Primary expressions 200
6.6 Trying the first version 20 1
6.7 Trying the second version 206
6.8 Token streams 207
6.8.1 Implementing Token_stream 209
6.8.2 Reading tokens 211
6.8.3 Reading numbers 212
6.9 Program structure 2 13

Chapter 7 Completing a Program 21 9


7. 1 Introduction 220
7.2 Input and output 220
7.3 Error handling 222
7.4 Negative numbers 227
7.5 Remainder: % 228
7.6 Cleaning up the code 23 1
7.6.1 Symbolic constants 231
7.6.2 Use of functions 233
7.6.3 Code layout 234
7.6.4 Commenting 236
7.7 Recovering from errors 238
7.8 Variables 241
7.8.1 Variables and defmitions 241
7.8.2 Introducing names 246
7.8.3 Predefined names 249
7.8.4 Are we there yet? 249
C O N T E N TS ix

Chapter 8 Technicalities: Functions, etc. 253


8.1 Technicalities 254
8.2 Declarations and definitions 255
8.2.1 Kinds of declarations 259
8.2.2 Variable and constant declarations 260
8.2.3 Default initiali7.ation 261
8.3 Header files 261
8.4 Scope 264
8.5 Function call and return 269
8.5.1 Declaring arguments and return type 27 0
8.5.2 Returning a value 271
8.5.3 Pass·by-value 27 3
8.5.4 Pass-by-const-reference 27 3
8.5.5 Pass-by-reference 276
8.5.6 Pass-by-value vs. pass-by-reference 279
8.5.7 Argument checking and conversion 281
8.5.8 Function call implementation 282
8.6 Order of evaluation 287
8.6.1 Expression evaluation 288
8.6.2 Global initialization 288
8.7 Namespaccs 290
8.7.1 using declarations and using directives 291

Chapter 9 Technicalities: Classes, etc. 299


9.1 User·defmed types 300
9.2 Classes and members 301
9.3 Interface and implementation 302
9.4 Evolving a class 304
9.4.1 strud and functions 304
9.4.2 Member functions and constructors 306
9.4.3 Keep details private 308
9.4.4 Defming member functions 309
9.4.5 Referring to the current object 312
9.4.6 Reporting errors 313
9.5 Enumerations 314
9.6 Operator overloading 316
9.7 Class interfaces 318
9.7.1 Argument types 319
9.7.2 Copying 321
9.7.3 Default constructors 322
9.7.4 const member functions 325
9.7.5 Members and "helper functions" 326
9.8 T he Date class 328
X CONTE NTS

Part I I Input and Output 337

Chapter 10 Input and Output Streams 339


10.1 Input and output 340
10.2 T he 110 stream model 341
10.3 Ftles 343
10.4 Opening a ftle 344
10.5 Reading and writing a ftle 346
10.6 110 error handling 348
10.7 Reading a single value 352
10.7.1 Breaking the problem into manageable parts 353
10.7.2 Separating dialog from function 356
10.8 User-defined output operators 357
10.9 User-defined input operators 359
10.10 A standard input loop 359
10.11 Reading a structured ftle 361
10.11.1 In-memory representation 362
10.11.2 Reading structured values 364
10.11.3 Changing representations 368

Chapter 11 Customizing Input and Output 375


11.1 Regularity and irregularity 376
11.2 Output formatting 376
11.2.1 Integer output 37 7
11.2.2 Integer input 379
11.2.3 Floating-point output 380
11.2.4 Precision 382
11.2.5 Fields 383
11.3 Ftle opening and positioning 384
11.3.1 File open modes 385
11.3.2 Binary files 386
11.3.3 Positioning in files 389
11.4 String streams 390
11.5 Line-oriented input 391
11.6 Character classification 392
11.7 Using nonstandard separators 394
11.8 And there is so much more 401
Chapter 12 A Display Model 407
12.1 Why graphics? 408
12.2 A display model 409
12.3 A first example 410
C O N T E N TS xi

12.4 Using a GUI library 414


12.5 Coordinates 415
12.6 Shapes 416
12.7 Using Shape primitives 417
12.7.1 Graphics headers and main 417
12.7.2 An almost blank window 418
12.7.3 Axis 420
12.7.4 Graphing a function 422
12.7.5 Polygons 423
12.7.6 Rectangles 424
12. 7.7 Fill 427
12.7.8 Text 427
12.7.9 Images 429
12.7.10 And much more 430
12.8 Getting this to run 431
12.8.1 Source files 432
Chapter 13 Graphics Classes 437
13.1 Overview of graphics classes 438
13.2 Point and Line 440
13.3 Lines 443
13.4 Color 445
13.5 Line_style 448
13.6 Open_polyline 450
13.7 Closed_polyline 451
13.8 Polygon 453
13.9 Rectangle 455
13.10 Managing unnamed objects 459
13.11 Text 462
13.12 Circle 464
13.13 Ellipse 466
13.14 Marked_polyline 468
13.15 Marks 469
13.16 Mark 470
13.17 Images 472
Chapter 14 Graphics Class Design 479
14.1 Design principles 480
14.1.1 Types 480
14.1.2 Operations 482
14.1.3 Naming 483
14.1.4 Mutability 484
xii CONTENTS

14.2 Shape 485


14.2.1 An abstract class 487
14.2.2 Access control 488
14.2.3 Drawing shapes 491
14.2.4 Copying and mutability 494
14.3 Base and derived classes 496
14.3.1 Object layout 497
14.3.2 Deriving classes and defining virtual functions 499
14.3.3 Overriding 500
14.3.4 Access 501
14.3.5 Pure virtual functions 502
14.4 Benefits of object-oriented progranuning 504
Chapter 1 5 Graphing Functions and Data 509
15.1 Introduction 510
15.2 Graphing simple functions 510
15.3 Function 514
15.3.1 Default arguments 515
15.3.2 More exam ples 517
15.4 Axis 518
15.5 Approximation 521
15.6 Graphing data 526
15.6.1 Reading a file 528
15.6.2 General layout 530
15.6.3 Scaling data 531
15.6.4 Building the graph 532

Chapter 1 6 Graphical User lnteriaces 539


16.1 User interface alternatives 540
16.2 The "Next" button 541
16.3 A simple window 542
16.3.1 A callback function 544
16.3.2 A wait loop 547
16.4 Button and other Widgets 548
16.4.1 Widgets 548
16.4.2 Buttons 549
16.4.3 ln_box and Out_box 550
16.4.4 Menus 551
16.5 An example 552
16.6 Control inversion 556
16.7 Adding a menu 557
16.8 Debugging GUI code 562
CONTENTS xiii

Part Ill Data and Algorithms 567

Chapter I 7 Vector and Free Store 569


17.1 Introduction 570
17.2 vector basics 572
17.3 Memory, addresses , and pointers 574
17.3.1 The sizeof operator 576
17.4 Free store and pointers 577
17.4.1 Free·store allocation 578
17.4.2 Access through pointers 579
17.4.3 Ranges 580
17.4.4 Initialization 582
17.4.5 The null pointer 583
17.4.6 Free-store deallocation 584
17.5 Destructors 586
17.5.1 Generated destructors 588
17.5.2 Destructors and free store 589
17.6 Access to elements 590
17.7 Pointers to class objects 591
17.8 Messing with types: void* and casts 593
17.9 Pointers and references 595
17.9.1 Pointer and reference parameters 596
17.9.2 Pointers, references, and inheritance 598
17.9.3 An example: lists 598
17.9.4 List operations 600
17.9.5 List use 602
17.10 The this pointer 603
17.10.1 More link use 606
Chapter 18 Vectors and Arrays 611
18.1 Introduction 612
18.2 Copying 613
18.2.1 Copy constructors 614
18.2.2 Copy assignments 616
18.2.3 Copy terminology 618
18.3 Essential operations 620
18.3.1 Explicit constructors 621
18.3.2 Debugging constructors and destructors 622
18.4 Access to vector elements 625
18.4.1 Overloading on const 626
xiv CONTENTS

18.5 Arrays 627


18.5.1 Pointers to array elements 628
18.5.2 Pointers and arrays 631
18.5.3 Array initialization 633
18.5.4 Pointer problems 634
18.6 Examples: palindrome 637
18.6.1 Palindromes using string 637
18.6.2 Palindromes using arrays 638
18.6.3 Palindromes using pointers 640

Chapter 1 9 Vector, Templates, and Exceptions 645


19.1 The problems 646
19.2 Changing size 649
19.2.1 Representation 649
19.2.2 reserve and capacity 651
19.2.3 resize 652
19.2.4 push_back 652
19.2.5 Assignment 653
19.2.6 Our vector so far 655
19.3 Templates 656
19.3.1 Types as template parameters 656
19.3.2 Generic programming 659
19.3.3 Containers and inheritance 661
19.3.4 Integers as template parameters 662
19.3.5 Template argument deduction 664
19.3.6 Generalizing vector 665
19.4 Range checking and exceptions 668
19.4.1 An aside: design considerations 670
19.4.2 A confession: macros 671
19.5 Resources and exceptions 672
19.5.1 Potential resource management problems 673
19.5.2 Resource acquisition is initialization 675
19.5.3 Guarantees 676
19.5.4 auto_ptr 678
19.5.5 RAil for vector 678

Chapter 20 Containers and lterators 685


20.1 Storing and processing data 686
20.1.1 Working with data 687
20.1.2 Generalizing code 688
20.2 SIL ideals 690
CONTENTS

20.3 Sequences and iterators 694


20.3.1 Back to the example 696
20.4 Linked lists 698
20.4.1 List operations
699
20.4.2 Iteration
701
20.5 Generalizing vector yet again 703
20.6 An example: a simple text editor 704
20.6.1 Lines 707
20.6.2 Iteration 708
20.7 vector, list, and string 711
20.7.1 insert and erase 713
20.8 Adapting our vector to the STL 715
20.9 Adapting built-in arrays to the STL 718
20.10 Container overview 719
20.10.1 lterator categories 722
Chapter 21 Algorithms and Maps 727
21.1 Standard library algorithms 728
21.2 The simplest algorithm: find() 729
21.2.1 Some generic uses 731
21.3 The general search: find_if() 732
21.4 Function objects 734
21.4.1 An abstract view of function objects 736
21.4.2 Predicates on class members 737
21.5 Numerical algorithms 738
21.5.1 Accumulate 739
21.5.2 Generalizing accumulate() 740
21.5.3 Inner product 742
21.5.4 Generalizing inner_produd() 743
21.6 Associative containers 7 44
21.6.1 Maps 745
21.6.2 map overview 747
21.6.3 Another map example 750
21.6.4 unordered_map 753
21.6.5 Sets 755
21.7 Copying 757
21.7.1 Copy 757
21. 7.2 Stream iterators 758
21.7.3 Using a set to keep order 761
21.7.4 copy_if 761
21.8 Sorting and searching 762
xvi CONTENTS

Part IV Broadening the View 769

Chapter 22 Ideals and History 771


22.1 History, ideals, and professionalism 772
22.1.1 Progranuning language aims and philosophies 772
22.1.2 Progranuning ideals 774
22.1.3 St-yles/paradigms 781
22.2 Programming language history overview 783
22.2.1 T he earliest languages 784
22.2.2 T he roots of modem languages 786
22.2.3 T he Algol family 791
22.2.4 Simula 798
22.2.5 c 800
22.2.6 C++ 804
22.2.7 Today 807
22.2.8 Information sources 808

Chapter 23 Text Manipulation 81 3


23.1 Text 814
23.2 Strings 814
23.3 1/0 streams 819
23.4 Maps 820
23.4.1 Implementation details 826
23.5 A problem 828
23.6 T he idea of regular expressions 830
23.7 Searching with regular expressions 833
23.8 Regular expression syntax 836
23.8.1 Characters and special characters 836
23.8.2 Character classes 837
23.8.3 Repeats 838
23.8.4 Grouping 840
23.8.5 Alternation 840
23.8.6 Character sets and ranges 841
23.8.7 Regular expression errors 842
23.9 Matching with regular expressions 844
23.10 References 849
Chapter 24 Numerics 853
24.1 Introduction 854
24.2 Size, precision, and overflow 854
24.2.1 Numeric limits 858
24.3 Arrays 859
24.4 C-style multidimensional arrays 859
CONTENTS xvii

24.5 The Matrix library 861


24.5.1 Dimensions and access 862
24.5.2 1D Matrix 865
24.5.3 2D Matrix 868
24.5.4 Matrix 110 870
24.5.5 3D Matrix 871
24.6 An example: solving linear equations 872
24.6.1 Classical Gaussian elimination 874
24.6.2 P ivoting 875
24.6.3 Testing 876
24.7 Random numbers 877
24.8 The standard mathematical functions 879
24.9 Complex numbers 880
24.10 References 882
Chapter 25 Embedded Systems Programming 887
25.1 Embedded systems 888
25.2 Basic concepts 891
25.2.1 Predictability 894
25.2.2 Ideals 894
25.2.3 Living with failure 895
25.3 Memory management 897
25.3.1 Free-store problems 898
25.3.2 Alternatives to general free store 901
25.3.3 Pool example 902
25.3.4 Stack example 903
25.4 Addresses, pointers, and arrays 905
25.4.1 Unchecked conversions 905
25.4.2 A problem: dysfunctional interfaces 905
25.4.3 A solution: an interface class 909
25.4.4 Inheritance and containers 912
25.5 Bits, bytes, and words 916
25.5.1 Bits and bit operations 916
25.5.2 bitset 920
25.5.3 Signed and unsigned 922
25.5.4 Bit manipulation 926
25.5.5 Bitfields 928
25.5.6 An example: simple encryption 930
25.6 Coding standards 935
25.6.1 What should a coding standard be? 936
25.6.2 Sample rules 937
25.6.3 Real coding standards 943
xviii CONTENTS

Chapter 26 Testing 949


26.1 What we want 950
26.1.1 Caveat 951
26.2 Proofs 952
26.3 Testing 952
26.3.1 Regression tests 953
26.3.2 Unit tests 954
26.3.3 Algorithms and non-algorithms 961
26.3.4 System tests 969
26.3.5 Testing classes 973
26.3.6 Fmding assumptions that do not hold 976
26.4 Design for testing 978
26.5 Debugging 979
26.6 Performance 979
26.6.1 Trming 981
26.7 References 983
Chapter 27 The C Programming Language 987
27.1 C and C++: siblings 988
27.1.1 C/C++ compatibility 990
27.1.2 C++ features missing from C 991
27.1.3 T he C standard library 993
27.2 Functions 994
27.2.1 No function name overloading 994
27.2.2 Function argument type checking 995
27.2.3 Function defmitions 997
27.2.4 Calling C from C++ and C++ from C 998
27.2.5 Pointers to functions 1000
27.3 Minor language differences 1002
27.3.1 struct tag namespace 1002
27.3.2 Keywords 1003
27.3.3 Defmitions 1004
27.3.4 C-style casts 1006
27.3.5 Conversion of void" 1007
27.3.6 enum 1008
27.3.7 Namespaces 1008
27.4 Free store 1009
27.5 C-style strings 1011
27.5.1 C-style strings and const 1013
27.5.2 Byte operations 1014
27.5.3 An example: strcpyO 1015
27.5.4 A style issue 1015
CONTENTS xix

27.6 Input/output: stdio 1016


27.6.1 Output 1016
27.6.2 Input 1017
27.6.3 Files 1019
27.7 Constants and macros 1020
27.8 Macros 1021
27.8.1 Function-like macros 1022
27.8.2 Syntax macros 1023
27.8.3 Conditional compilation 1024
27.9 An example: intrusive containers 1025

Part V Appendices 1 035

Appendix A Language Summary 1 03 7


A.1 General 1038
A.l.l Terminology 1039
A.l.2 Program start and termination 1039
A.l.3 Comments 1040
A.2 Literals 1041
A.2.1 lnteger literals 1041
A.2.2 Floating-point-literals 1042
A.2.3 Boolean literals 1043
A.2.4 Character literals 1043
A.2.5 String literals 1044
A.2.6 T he pointer literal 1044
A.3 Identifiers 1045
A.3.1 Keywords 1045
A.4 Scope, storage class, and lifetime 1046
A.4.1 Scope 1046
A.4.2 Storage class 1047
A.4.3 Lifetime 1048
A.5 Expressions 1049
A.5.1 User-defined operators 1054
A.5.2 Implicit type conversion 1054
A.5.3 Constant expressions 1056
A.5.4 sizeof 1057
A.5.5 Logical expressions 1057
A.5.6 new and delete 1057
A.5.7 Casts 1058
A.6 Statements 1059
A.7 Declarations 1061
A.7.1 Defmitions 1061
xx CONTENTS

A.8 Built-in types 1062


A.8.1 Pointers 1063
A.8.2 Arrays 1064
A.8.3 References 1065
A.9 Functions 1066
A.9.1 Overload resolution 1067
A.9.2 Default arguments 1068
A.9.3 Unspecified arguments 1068
A.9.4 Linkage specifications 1069
A.10 User-defined types 1069
A.10.1 Operator overloading 1069
A.ll Enumerations 1070
A.12 Classes 1071
A.12.1 Member access 1071
A.12.2 Class member defmitions 1074
A.12.3 Construction, destruction, and copy 1075
A.12.4 Derived classes 1078
A.12.5 Bitfields 1082
A.12.6 Unions 1082
A.13 Templates 1083
A.13.1 Template arguments 1084
A.13.2 Template instantiation 1084
A.13.3 Template member types 1086
A.14 Exceptions 1086
A.15 Namespaces 1088
A.16 Aliases 1089
A.17 Preprocessor directives 1 090
A.17.1 #i nclude 1090
A.17.2 #defi ne 1090

Appendix B Standard Library Summary 1 09.3


B.1 Overview 1094
B.l.l Header files 1095
B.l.2 Namespace std 1098
B.l.3 Description st-yle 1098
B.2 Error handling 1098
B.2.1 Exceptions 1099
B .3 lterators 11 00
B.3.1 lterator model 1101
B.3.2 lterator categories 1103
CONTENTS xxi

B.4 Containers 1105


B.4.1 Overview 1107
B.4.2 Member types 1108
B.4.3 Constructors, destructors, and assignments 1108
B.4.4 lterators 1109
B.4.5 Element access 1109
B.4.6 Stack and queue operations 1110
B.4.7 List operations 1110
B.4.8 Size and capacity 1110
B.4.9 Other operations 1111
B.4.10 Associative container operations 1111
B.5 Algorithms 1112
B.5.1 NorunodifYing sequence algorithms 1113
B.5.2 ModifYing sequence algorithms 1114
B.5.3 Utility algorithms 1116
B.5.4 Sorting and searching 1117
B.S.S Set algorithms 1118
B.5.6 Heaps 1119
B.5.7 Permutations 1120
B.5.8 min and max 1120
B.6 STL utilities 1121
B.6.1 Inserters 1121
B.6.2 Function objects 1122
B.6.3 pair 1123
B.7 110 streams 1124
B.7.1 1/0 streams hierarchy 1126
B.7.2 Error handling 1127
B.7.3 Input operations 1128
B.7.4 Output operations 1128
B.7.5 Formatting 1129
B.7.6 Standard manipulators 1129
B.B String manipulation 1131
B.8.1 Character classification 1131
B.8.2 String 1132
B.8.3 Regular expression matching 1133
B.9 Numerics 1135
B.9.1 Numerical limits 1135
B.9.2 Standard mathematical functions 1137
B.9.3 Complex 1138
B.9.4 valarray 1139
B.9.5 Generalized numerical algorithms 1139
xxii CONTENTS

B.10 C standard library functions 1140


B.10.1 Files 1140
B.10.2 The printf() family 1141
B.10.3 C-style strings 1145
B.10.4 Memory 1146
B.10.5 Date and time 1147
B.10.6 Etc. 1149
B.11 Other libraries 1150
Appendix C Getting Started with Visual Studio 1 1 51
C.1 Getting a program to run 1152
C.2 Installing Visual Studio 1152
C.3 Creating and running a program 1153
C.3.1 Create a new project 1153
C.3.2 Use the std_lib_fa cilities.h header file 1153
C.3.3 Add a C++ source file to the project 1154
C.3.4 Enter your source code 1154
C.3.5 Build an executable program 1154
C.3.6 Execute the program 1155
C.3.7 Save the program 1155
C.4 Later 1155
Appendix D Installing FLTK 1 1 57
0.1 Introduction 1158
0.2 Downloading FLTK 1158
0.3 Installing FLTK 1159
0.4 Using FLTK in Visual Studio 1159
0.5 Testing if it all worked 1160

Appendix E GUI Implementation 1 1 61


E.1 Callback implementation 1162
E.2 Widget implementation 1163
E.3 Window implementation 1164
E.4 Vector_ref 1166
E.5 An example: manipulating Widgets 1167

Glossary 1171
Bibliography 1177
Index 1181
Preface

"Damn the torpedoes!


Full speed ahead."

-Admiral Farragut

Programming is the art of expressing solutions to problems so that a computer


can execute those solutions. Much of the effort in programming is spent fmding
and refining solutions. Often, a problem is only fully understood through the
process of programming a solution for it.
T his book is for someone who has never programmed before but is willing
to work hard to learn. It helps you understand the principles and acquire the
practical skills of programming using the C++ programming language. My aim
is for you to gain sufficient knowledge and experience to perform simple useful
programming tasks using the best up-to-date techniques. How long will that
take? As part of a first-year university course, you can work through this book in
a semester (assuming that you have a workload of four courses of average diffi­
culty). If you work by yourself, don't expect to spend less time than that (maybe
15 hours a week for 14 weeks).
Three months may seem a long time, but there's a lot to learn and you'll be
writing your first simple programs after about an hour. Also, all learning is grad­
ual: each chapter introduces new useful concepts and illustrates them with exam­
ples inspired by real-world uses. Your ability to express ideas in code - getting a
computer to do what you want it to do - gradually and steadily increases as you
go along. I never say, ..Learn a month's worth of theory and then see if you can
use it."

xxiii
xxiv PREFACE

Why would you want to program? Our civilization runs on software. With·
out understanding software you are reduced to believing in "magic" and will be
locked out of many of the most interesting, profitable, and socially useful techni­
cal fields of work. When I talk about programming, I think of the whole spec­
trum of computer programs from personal computer applications with G Uls
(graphical user interfaces), through engineering calculations and embedded sys­
tems control applications (such as digital cameras, cars, and cell phones), to text
manipulation applications as found in many humanities and business applica­
tions. Like mathematics, programming- when done well- is a valuable intellec­
tual exercise that sharpens our ability to think. However, thanks to feedback
from the computer, programming is more concrete than most forms of math, and
therefore accessible to more people. It is a way to reach out and change the world
- ideally for the better. Finally, programming can be great fun.
W hy C++? You can't learn to program without a progranmung language,
and C++ directly supports the key concepts and techniques used in real-world
software. C++ is one of the most widely used programming languages, found in
an unsurpassed range of application areas. You fmd C++ applications every·
where from the bottom of the oceans to the surface of Mars. C++ is precisely
and comprehensively defmed by a nonproprietary international standard. Qyal·
ity and/or free implementations are available on every kind of computer. Most of
the programming concepts that you will learn using C++ can be used directly in
other languages, such as C, C#, Fortran, andjava. Fmally, I simply like C++ as
a language for writing elegant and efficient code.
This is not the easiest book on beginning programming; it is not meant to
be. I just aim for it to be the easiest book from which you can learn the basics of
real-world programming. That's quite an ambitious goal because much modern
software relies on techniques considered advanced just a few years ago.
My fundamental assumption is that you want to write programs for the use
of others, and to do so responsibly, providing a decent level of system quality:
that is, I assume that you want to achieve a level of professionalism. Consc·
quently, I chose the topics for this book to cover what is needed to get started
with real-world programming. not just what is easy to teach and learn. If you
need a technique to get basic work done right, I describe it. demonstrate concepts
and language facilities needed to support the technique, provide exercises for it,
and expect you to work on those exercises. If you just want to understand toy
programs, you can get along with far less than I present. On the other hand, I
won't waste your time with material of marginal practical importance. If an idea
is explained here, it's because you'll almost certainly need it.
If your desire is to use the work of others without understanding how things
arc done and witl10ut adding significantly to the code yourself, tills book is not
for you. If so, please consider whether you would be better served by another
book and another language. If that is approximately your view of programming,
please also consider from where you got that view and whether it in fact is adc·
quate for your needs. People often underestimate the complexity of program-
Exploring the Variety of Random
Documents with Different Content
room, whose peculiar form or colour had attracted his attention? he
thinks nothing of taking the life of any thing he admires. Oh! it turns
me sick to think of it; had I flown one inch farther I might have been
thus impaled, and you also; no doubt you would not have escaped
his observation, and for the sake of your sting, or examining what
you carry your honey in, you would have been quickly dispatched;
various are the instruments he has got about him, and numberless
insects does he daily destroy."
"These are detestable creatures indeed," answered the Bee; "what
can't they be satisfied with viewing our forms as we pass along, but
must they pull us to pieces, by way of admiration? I fancy when they
have taken the most accurate survey, they could not make either a
Bee, or a Butterfly; it is a pity therefore that they should destroy that
life which they can never give. I declare the more I see of these
human beings, and think of their cruelty, as well as absurdities, it
makes me almost determine to quit the haunts of men, and if it ever
should be my lot again to seek another habitation, I would use all
my influence with my fellow Bees in order to remove to some wild
wood where they might never find us."
"You would be perfectly right," returned the Butterfly; "as for us, if
we escape them one summer, we willingly resign our lives at the end
of it, and led by instinct seek a place in which we die unlamented,
and soon forgotten; but this is not the case with you; while you live
you are useful, and at your death a whole society feels your loss; but
look," continued he, pointing towards a bottle that hung tied to the
branch of a fruit-tree, in which were several wasps decoyed thither
by the liquid it contained, and dying in the sweets they sought,
"there is another instance of their malice, don't you see those poor
creatures?"
"Oh! yes," returned the Bee, "and though I am no friend to wasps,
who are often wishing to share the fruits of our labour, without
having any right to them; and in many things are striving to imitate
us, though I believe their chief aim is to do mischief, yet I cannot
justify men who use such mean arts to entrap them to their
destruction; but what is that I see in yonder window?" continued he
with a hurried air, "something that more particularly demands my
attention, a Bee in distress; and hark, he calls to me for assistance;"
so saying, without waiting for the Butterfly to accompany him, he
flew towards the place, where was a Bee nearly drowning in a pot of
honey. "And one of my own hive too!" exclaimed he, as he drew
nearer; "my dear brother, how came you in such a situation?"
"Surely we are to see nothing but shocking sights to-day," observed
the compassionate Butterfly, who had hastily followed his friend, half
afraid that something still more terrible had happened, "but," said
he, on seeing the struggling captive, "he will not die; 'tis certain he
can keep his head above the edge till you have procured more
assistance; I fear I am not strong enough to help to pull him out."
While he was speaking, his companion had flown to the hive, and
with incredible swiftness returned with more of the community, who
altogether lent their aid, and after much toil and pains extricated the
poor exhausted Bee from the ill effects of seeking too large a share
of those sweets which only proved so, when moderately enjoyed,
'safe in themselves but dangerous in the excess.'
"I only rested on the edge of the pan," said he, as soon as he could
speak, "and after an unsuccessful flight was glad to see a store of
that which I had been so long searching for in vain; I thought I
would just take a sip or two, and perhaps bring home a little of it to
the hive."
On hearing this one of the oldest of the throng thus addressed him:
"Know, my brother, that what we make ourselves is only welcome
there, and that food for which we labour hardest, is the sweetest to
the palate of every industrious Bee; idle drones and wandering
wasps may sip the honey which others have prepared, but let the
danger you have escaped to-day teach you to use the powers nature
has given you, and taste the sweets of your own procuring rather
than that of others."
The trembling Bee thanked him for his advice, and promising to
follow it, he was escorted home by all the train, where he met with
other assistants, who cleared away the clammy substance that still
encumbered him, and he was suffered to rest within all that day to
recover himself. Meanwhile, the Butterfly waited without the hive, till
his friend returned, and they renewed their flight.
Nothing particular met their eye till they passed some flies, who
were round a piece of horse-flesh, the smell of which discovered
where it lay, and its half devoured state shewed the avidity with
which these buzzing insects fed upon it. "See," said the Bee, "what
opposite natures are within the circle of creation. These devouring
flies find as much pleasure in eating from this stinking carrion, as
from the choicest honey; nay, perhaps this is more agreeable to
them, though nothing in which they can thrust their devouring
trunks escapes their taste, but with this delicious morsel, that really
poisons the surrounding air, they are so delighted, that they even
chuse it for an habitation likewise. Here they lay their eggs, and
bring forth their young, and having no trouble to hunt for food for
them, they spend their time in flying round it, till their habitation and
provision being gone together, they are obliged to seek another
residence equally convenient. Though you bear the same name, my
friend," continued he, "I am witness that you have not their nature."
"Their nature!" interrupted the Butterfly, half offended at being
mentioned together, "no! I hope not, or their name either! what,
shall the beautiful winged tribe of Butterflies be put upon a footing
with these carrion-eaters, who live upon what, even in our crawling
state, we should reject with disgust. If I may speak my opinion, I
think their form, and the noise they make while flying, is more like
your race than ours, though alas! in one respect, I feel myself too
closely allied to them, that is, I must shortly resign my being; the
date of my life will soon be ended; I have felt the chilling blast of the
morning air long before you are out of your hive, and if you are not
already aware of it, can give you notice that winter is approaching."
"Indeed," replied the Bee, "I have seen some tokens of it myself; the
flowers are not in such plenty, and as their faded leaves fall off, no
young buds are seen to supply their place; however, such is the use
which we have made of the summer, that we are not afraid to look
forward to the time when every outward resource shall fail: but, my
friend, I fear you are of too delicate a frame to live through the
winter, though the place of your retreat be ever so warm; but have
you not thought of where you will retire to?" continued he.
"A place to die in is easily found," replied the Butterfly, "and you
must not be surprised if you see me no more; the damps of the
night will soon prove fatal, and I know not if I shall survive another."
"Do not speak so," returned the Bee, "how gladly would I afford you
an asylum if it was in my power; however, I cannot let you resign
your life so easily; green leaves are yet to be found, and now, within
our reach, I see a convenient crevice, into which you may creep;
there cherish life as long as you can, my friend, and by only
venturing out when the sun shines brightly, you may perhaps extend
your days beyond their usual period, and have your name recorded,
as a Butterfly who has survived the summer."
"Thank your kindness," returned the short-lived insect, "my life has
been already lengthened through your means, but you cannot
renovate my nature; may yours be extended."
"As long as it can be useful," said the Bee, interrupting him, "but to
you I owe all that I have gathered this summer," added he; "for had
it not been for your friendly and compassionate encouragement
when first we met, I should have sunk a victim to the consciousness
of deserved destruction; say not, therefore, that you have been of
no use in the world."
"I will not," returned the Butterfly, faintly fluttering his wings, as if
with his last breath he was desirous of rejoicing it had been in his
power to do good.
From this time the poor Butterfly was still more sensible of the
weakness of his frame, and flying towards the place his friend had
pointed out, he entered, never to quit it more, "self-buried 'ere he
died," for in the morning when the Bee visited the spot he was deaf
to his voice, and his pitying friend had to lament the sudden change
in one he had so very lately seen frisking about in all the gaiety of
health and spirits.
"Poor fly," said he, "thou hast been faithful to me, and has even
forgot thy wonted pleasures to afford me assistance; I will not leave
thee to the devouring jaws of thy fellow insects, at least thy little
body shall be preserved from being so destroyed," and with this
resolution he spent one whole day in gathering wax, and stopping
up the crevice which contained the remains of his friend—all the
return he could now make for his former kindness. After having
given this last proof of affection, he returned to the hive, and there
in the busy labors of the Commonwealth soon forgot the shock
which the unexpected death of his airy companion had occasioned.
During that winter they were suffered to remain unmolested, and as
the ensuing summer approached, (according to the plan he had
formed so long ago,) he proposed their taking a farther flight, and
seeking a refuge in some solitary wood; "I have seen more of
mankind than you have, my friends," said he, "and have observed
both their customs and manners; believe me, they are inconsistent
fickle creatures; their conduct towards one another shows that they
are not to be trusted; much more, then, have we reason to be afraid
of them. You very well know it is in our power to live without their
assistance; what is it which they procure us but just an empty shell
for our habitation? for this they expect our stock of honey, and to
obtain it scruple not to take our lives! We have already seen, in the
destruction of one or two of our neighbouring hives, the fate which
awaits us; but could I persuade all of my species to wing their flight
beyond their reach, they might be taught a little more humanity, and
would perhaps spare our lives, if we were again in their power.
Content to share with us what our labours have produced, they
might then leave us to die when our exhausted nature fails, and for
their own sakes also would not cut us off in the prime of life, and
while we have health and strength to add to the stock, which would
be as much for their benefit as our own."
This speech had the desired effect; the whole community seemed
roused by it, and entering into his scheme, on the appointed day not
a Bee was left behind, but altogether mounting the air they winged
their flight far beyond its usual extent, nor could all the clattering of
pots and kettles make them settle, till clear of the noise and out of
the sight of man they found an habitation for themselves, and under
the covert of a thick wood passed the remainder of their days in
peaceful industry.

THE END.

W. Lewis, Printer, Paternoster-row, London.

TRANSCRIBER'S NOTES
Obvious spelling, typographical and punctuation errors have been corrected after careful
comparison with other occurrences within the text and consultation of external sources.

Moved 'CHAP VI' heading in Chapter Summary section from incorrect place to before 'The
Bees swarm' Pg vii
Spacing retained in 'every where' Pg 26 and 'every thing' Pg 34
Spacing retained in 'well known' Pg 48
Spacing retained in 'any thing' Pg 65
Added missing end quotes; 'been feeding,' to 'been feeding,"' Pg 28
Added missing end quotes, 'no longer friends.' to 'no longer friends."' Pg 67
Added missing second end quotes, 'a toast, Sir?"' to 'a toast, Sir?""' Pg 89
Added missing end quotes, 'creature disagreeable?' to 'creature disagreeable?"' Pg 106
Added missing start quotes, 'I never' to '"I never' Pg 46
Removed bad quotes, 'hurting him:"' to 'hurting him:' Pg 46
Removed bad quotes, '"Though you bear' to 'Though you bear' Pg 125
Added missing end and start quotes, '"Oh! said he, I' to '"Oh!" said he, "I' Pg 73
Typo; changed 'laid' to 'said' Pg 29
Typo; changed 'littles' to 'little' Pg 42
Typo; changed 'flowers' to 'flower' Pg 47
Typo; changed 'gardon' to 'garden' Pg 65
Typo; changed 'surservient' to 'subservient' Pg 70
Typo; changed 'Bee,' to 'Bee.' Pg 72
Typo; changed 'he weapons' to 'the weapons' Pg 83
Archaic use of 'an' before 'h' retained; for example 'an humble' Pg 50 et al.
Archaic spelling of 'chace', 'chaced' and 'chacing' retained Pg 44 et al.
Archaic spelling of 'aukward' retained Pg 64
Archaic spelling of 'taylor' retained Pg 74
Archaic spelling of 'incumbered' and 'incumbrance' retained; one occurrence of
'encumbered' also retained Pg 19 et al.
Archaic spelling of 'chuse' retained; one occurrence of 'choose' in preface also retained Pg
113 et al.
Archaic spelling of 'fixt' retained; one occurrence of 'fixed' also retained Pg 92 et al.
Archaic spelling of 'encrease' and 'encreased' retained; three occurrences of 'increase'
etc. also retained Pg 52 et al.
Archaic spelling of 'gayly drest' retained Pg 106
*** END OF THE PROJECT GUTENBERG EBOOK THE
PERAMBULATIONS OF A BEE AND A BUTTERFLY, ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like