Top Banner
II I I IIIIHII m:m--r-^K% V—/ V^ I T Annotated Archives Art Friedman, Lars Klander, Mark Michaelis, and Herb Schildt
7

V—/ V^ I T Annotated Archives

Apr 05, 2022

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: V—/ V^ I T Annotated Archives

II I I IIIIHII m:m--r-^K%

V—/ V ^ I T

Annotated Archives

Art Friedman, Lars Klander, Mark Michaelis, and Herb Schildt

Page 2: V—/ V^ I T Annotated Archives

Contents

Foreword xiii By Herbert Schildt

1 Sorting 1 By Art Friedman

Introduction to Sorting 2 Bubble Sort 3 Selection Sort 7 Basic Quick Sort 11 Enhanced Quick Sort 17 Merge Sort 23

2 Linked Lists 29 By Art Friedman

Introduction to Linked Lists 30 Singly Linked Lists 32 Simple Singly Linked List 32 Singly Linked List Template 39 Doubly Linked Lists 47 Simple Doubly Linked List 48 Doubly Linked List Template 55

3 Binary Trees 67 By Art Friedman

Introduction to Binary Trees 68 Binary Search Trees 69 Simple Binary Search Tree Template 70 Balanced Binary Search Trees 91

Page 3: V—/ V^ I T Annotated Archives

C/C++ Annotated Archives

4 Hash Tables and Sparse Arrays 125 By Art Friedman

Introduction to Hash Tables and Sparse Arrays 126 Hash Table Design 126 Simple Hash Table with Integer Keys 128 Hash Table with char *Keys 136 Sparse Array Design 146 One-Dimensional Sparse Array 147 Two-Dimensional Sparse Array 151

5 Memory Management 161 By Art Friedman

Memory Management for C and C++ 162 Overloading the Global New Operator 163 Simple Array-Based Allocator 166 Simple List-Based Allocator 172

6 Working with Files and Directories 179 By Lars Klander

Search and Replace Text File 180 Working with the File System 194 Viewing File Contents 210

7 Encryption Fundamentals 217 By Lars Klander

A Better Understanding of Encryption 218 Strengthening the Encryption 225

A Slightly More Complex Encryption Algorithm 226 The Limitations of Conventional Single-Key Cryptosystems 236

Public-Key Cryptosystems 237 Digital Signatures 238 The Digital Signature's Construction 238

The Rivest, Shamir, and Adleman (RSA) Algorithm 241 Properties of the RSA Algorithm 241 The RSA Algorithm Itself 242 The RSA Algorithm's Math 243 Hash Values 244

The Windows Encryption API 244 Cryptographic Service Providers (CSPs) 245 The CryptoAPI Programming Model 247 Using the Cryptographic API's Basic Functions 248 Adding Digital Signatures with CryptoAPI 251

Page 4: V—/ V^ I T Annotated Archives

Contents

Adding CryptoAPI Support to Your MFC Programs 252 Code for the CCryptoDoc Class 253 Final Thoughts on CryptoNotes and Encryption 264

8 Managing Source Code 265 By Mark Michaelis

Code Manager Program Design 266 The Token Classes 268 The Scanner Class, CScanner 310 Initializing the Scanner for C++ 322 The Parser Class, CCodeParser 331 The Main Program 360 Compiling SCodeMnt.exe 369 Running SCodeMnt.exe 369 Things to Try 370

9 C/C++ for Internet Access 371 By Lars Klander

Internet Services 372 The WinSock API 372

WinSock Initialization 373 Name Service 374 Network Issues with Byte Ordering 375

Communication Through Sockets 375 The Blocking Problem and the select() Call 376 Asynchronous Socket Calls 376 Synchronous Operations and Serialization 377

The Simple Browser Project 377 Using the New CHtmlView Internet Class 427

The Web Browser Control 428 Creating a Project That Uses CHtmlView 428 Navigating Through CHtmlViews 429 Using the CHtmlView Class to Write a Simple

Browser Program 431 Tweaking a Browser to Look at Search Results 432

10 Performing Financial Calculations 435 By Lars Klander

Computing Depreciation 436 Straight-Line Depreciation 436 Code for Program Using Straight-Line Depreciation 438 Sum-of-Years Digits Depreciation 440 Code for Program Using Sum-of-the-Years Digits Depreciation . . 443

Page 5: V—/ V^ I T Annotated Archives

C/C++ Annotated Archives

Using Double-Declining Balance Depreciation 447 Code for Program Using Double-Declining Balance

Depreciation 449 Financial Functions for Handling Annuities 454

Computing the Future Value Based on a Single Payment 455 Code for Computing Future Value Based on a Single Payment . . 456 Computing the Future Value of a Series of Payments 458 Code for Computing Future Value Based on a Series of

Payments 459 Computing a Single Payment to Reach a Future Value 462 Code for Computing a Single Payment to Reach a Future

Value 462 Computing the Contributions Necessary to Reach a Specified

Ending Value 464 Code for Computing Series of Payments Toward a Goal 464

Writing a Simple Loan Calculator 466 Code for Calculating Loan Payments 466

Putting Together Multiple Computations 468 Code for Computing Retirement Fund Contributions 469

11 Performing Statistical Calculations 473 By Lars Klander

Introduction to Averages 474 The Arithmetic Mean, the Median, and the Mode 475

Other Common Average Computations 484 Weighted Mean 484 Geometric Mean 485 Computing the Root Mean Square and the Root Sum Square . . . . 487

Considering Probability 493 The Second Law of Probability 494 The Third Law of Probability 495 The Fourth Law of Probability 495

Regression Analysis 503

12 Creating Fractals with Graphics Routines 511 By Lars Klander

Introduction to Fractals 513 A Brief Note on Graphs 514 Overview of MFC Document/View Architecture 515

Page 6: V—/ V^ I T Annotated Archives

Contents

13 An Object-Oriented Expression Parser 557 By Herbert Schildt

Parsing Fundamentals 558 Expressions 558 Parsing Expressions: The Problem 559 Parsing an Expression 560 Tokenizing an Expression 561

A Simple Expression Parser 564 A Parser That Accepts Variables 573 A Generic Parser 583 Enhancing and Improving the Parser 592

14 Implementing Language Interpreters in C++ 595 By Herbert Schildt

The Small BASIC Expression Parser 597 Small BASIC Expressions 598 Small BASIC Tokens 599

The Small BASIC Interpreter 612 The Keywords 625 Loading the Program 627 The Main Loop 627 The Assignment Function 629 The PRINT Command 630 The INPUT Command 632 The GOTO Command 632 The IF Statement 636 The FOR Loop 636 The GOSUB 639

Using Small BASIC 641 Enhancing and Expanding the Interpreter 643 Creating Your Own Computer Language 644

15 Exploring the Standard Template Library 645 By Andrew Gayter

Standard Template Library Overview 646 Containers 646 Iterators 647 Algorithms 648 User-Defined Function Objects 648

Page 7: V—/ V^ I T Annotated Archives

C/C++ Annotated Archives

STL Sorting 649 The sort() Algorithm 649 The partiaLsort Algorithm 651 The sort_heap() Function 653 Sorting User-Defined Elements within STL Containers 655 User-Defined Sorting Criteria 657 Searching STL Containers 660 The find() Algorithm 661 The binary_search() Algorithm 663 Using Function Objects 665 Reading and Writing Containers to Streams 668 Reading Container Elements from Files 669 Comparing Strings 671 STL Set Algorithms 673 Finding a Subset of Strings 674 Serving Prioritized Messages 677 Binary Tree Container 681

16 C/C++ for CGI Design 705 By Lars Klander

The CGI Architecture 706 FTP and HTTP: State vs. Stateless 707 The Efficiency of Stateless Communications 708

The Four-Step HTTP Transaction 709 Step 1: Establish a Connection 709 Step 2: Client Issues a Request 709 Step 3: Server Issues a Response 711 Step 4: Server Terminates the Connection 711

A Closer Look at URIs 712 Inside the URL 713 Relating URLs, Protocols, and File Types 713 URL Fragments 714

Looking at URLs and HTML 714 Absolute and Relative URLs 714

CGFs Place in the Web Model 715 Introducing the Clock Component 716

The Clock Component 716 A CGI Script That Uses the HTTP POST Method 723 Using CGI Applications 740

The Server/CGI Program Relationship 741 Accessing the CGI Script/Program from the Browser 741

Index 745