Table of • Contents • Index C++ for Business Programming, Second Edition By John C Molluzzo - Pace University, New York Publisher : Prentice Hall Pub Date : August 02, 2005 Print ISBN-10 : 0-13-046700-6 Print ISBN-13 : 978-0-13-046700-3 eText ISBN-10 : 0-13-128899-7 eText ISBN-13 : 978-0-13-128899-7 Pages : 848 This text provides a student-friendly, highly readable introduction to C++ programming for beginning programming students, especially those majoring in Information Systems and Business It guides readers through complete and clear descriptions of sample programs, with a wealth of exercises included along the way to help reinforce the important points of each chapter Throughout the text, a strong emphasis is placed on business applications, rather than those in mathematics or computing C++ for Business Programming, Second Edition By John C Molluzzo - Pace University, New York Publisher : Prentice Hall Pub Date : August 02, 2005 Print ISBN-10 : 0-13-046700-6 Print ISBN-13 : 978-0-13-046700-3 Table of eText ISBN-10 : 0-13-128899-7 • Contents eText ISBN-13 : 978-0-13-128899-7 • Index Pages : 848 Copyright Preface Changes From the First Edition Chapter Overview Part I: C++ Basics Chapter 1 Introduction to C++ Why Study C++? Section 1.1 Our First C++ Program Section 1.2 Integers and Arithmetic Section 1.3 Solving a Problem with Integers Section 1.4 Other Integer Data Types Chapter Review Chapter 2 Real Numbers Section 2.1 Real Numbers Section 2.2 Solving Problems with Real Numbers Section 2.3 More on Arithmetic Section 2.4 Three Difficulties When Displaying Decimal Numbers with cout Chapter Review Chapter 3 Iteration Section 3.1 Relation Conditions Section 3.2 Indefinite Iteration: The while and do Statements Section 3.3 Solving a Problem with Indefinite Iteration xv xvi xvii 1 20 32 36 42 45 45 52 64 75 78 80 80 83 96 Section 3.4 Definite Iteration Section 3.5 Nested Loops Chapter Review Chapter 4 Decision Making Section 4.1 Basic Decision Making Section 4.2 Compound ConditionsThe Logical Operators Section 4.3 Nested if Statements Section 4.4 The switch Statement Chapter Review Chapter 5 Functions Section 5.1 The Function Concept Section 5.2 User-Defined Functions that Return a Value Section 5.3 Programs that Use Functions Section 5.4 The C++ Math Library Functions Chapter Review Chapter 6 Arrays Section 6.1 Basic Concepts Section 6.2 Processing an Array: for Loops Section 6.3 Sorting an Array Section 6.4 Multidimensional Arrays Chapter Review Chapter 7 Pointers and C-Strings Section 7.1 Pointers Section 7.2 C-Strings Section 7.3 Arrays of Strings and Pointers Chapter Review Chapter 8 Pointers, Arrays, and Functions Section 8.1 Pointers, Reference Variables, and Functions Section 8.2 Arrays and Functions Section 8.3 Strings and Functions Section 8.4 The Standard Library String Functions Section 8.5 Character Classification and Conversion Functions Section 8.6 Dynamic Memory Allocation Chapter Review Chapter 9 User-Defined Data Types and Tables Section 9.1 The typedef and enum Statements Section 9.2 Structures Section 9.3 Arrays of Structures: Tables Section 9.4 Structures, Functions, and Pointers 105 118 126 128 128 139 146 161 172 174 175 191 203 227 231 234 234 242 250 256 264 266 266 277 290 297 299 299 309 318 326 336 351 360 363 364 371 379 407 Chapter Review Part II: Object-Oriented Programming Chapter 10 The string Class: An Introduction to Classes and Objects Section 10.1 Objects, Classes, and Object-Oriented Systems Section 10.2 Introduction to string Objects Section 10.3 Operations on string Objects Section 10.4 Making Decisions with Strings Section 10.5 Functions and string Objects Section 10.6 Manipulating string Objects Section 10.7 Putting Strings to Work Section 10.8 Arrays of Strings Chapter Review Chapter 11 Programmer-Defined Classes and Objects Section 11.1 Declaring Objects and Classes Section 11.2 A More Useful Class Accessor and Mutator Methods Section 11.3 Constructor Overloading and Destructors Section 11.4 Default Arguments and Object Assignment Section 11.5 General Function Overloading and Function Templates Chapter Review Chapter 12 Manipulating Objects Section 12.1 Using Arrays, Pointers, and Dynamic Memory Allocation Section 12.2 The Copy Constructor Section 12.3 Using const with Classes Section 12.4 Objects, Functions and Pointers Section 12.5 Dynamic Allocation of Objects Section 12.6 Static Data Members and Functions Chapter Review Chapter 13 Inheritance Section 13.1 Inheritance Section 13.2 Functions in Class Hierarchies Section 13.3 Polymorphism Section 13.4 Abstract Base Classes Chapter Review Chapter 14 Files Section 14.1 Input/Output Streams Section 14.2 Processing a File One Character at a Time Section 14.3 Random File Access Section 14.4 Binary Sequential File Processing Section 14.5 Random Record Input/Output 424 426 426 427 430 438 444 446 451 458 470 473 476 476 487 496 504 511 517 519 520 528 540 556 581 588 598 600 601 618 629 649 661 664 665 686 692 699 709 Chapter Review Chapter 15 Special Topics: Friends, Operator Overloading, Macros, and Inline Functions Section 15.1 friend Functions Section 15.2 Overloading Basic Arithmetic Operators Section 15.3 Overloading Assignment and the this Pointer Section 15.4 Overloading the Insertion and Extraction Operators Section 15.5 Overloading Compound Assignment Operators Section 15.6 Overloading Relational Operators Section 15.7 Overloading Unary Operators Section 15.8 Macros and Inline Functions Chapter Review Appendix A Computers and Data Section A.1 A Model Computer System Section A.2 Data RepresentationCharacters Section A.3 Data RepresentationIntegers Section A.4 Data RepresentationReal Numbers Exercises Appendix A Appendix B Program Control Section B.1 Sequence Section B.2 Selection Section B.3 Iteration Section B.4 Combinations Index 727 730 731 738 745 754 763 768 775 779 788 791 791 794 797 799 800 802 802 803 808 812 Copyright [Page ii] Library of Congress Cataloging-in-Publication Data Molluzzo, John C C++ for business programming / John C Molluzzo. 2nd ed p cm Includes bibliographical references and index ISBN 0-13-046700-6 C++ (Computer program language) 2 Business-Computer programs I Title HF5548.5.C125M65 2006 005.13'3-dc22 2005014365 Vice President and Editorial Director, ECS: Marcia J Horton Senior Acquisitions Editor: Tracy Dunkelberger Editorial Assistant: Christianna Lee Executive Managing Editor: Vince O'Brien Managing Editor: Camille Trentacoste Director of Creative Services: Paul Belfanti Managing Editor, AV Management and Production: Patricia Burns Art Editor: Gregory Dulles Cover Design Director: Jayne Conte Cover Designer: Kiwi Designs Manufacturing Manager, ESM: Alexis Heydt-Long Manufacturing Buyer: Lisa McDowell Executive Marketing Manager: Pamela Shaffer Marketing Assistant: Barrie Reinhold © 2006 Pearson Education, Inc Pearson Prentice Hall Pearson Education, Inc Upper Saddle River, NJ 07458 All rights reserved No part of this book may be reproduced in any form or by any means, without permission in writing from the publisher Pearson Prentice Hall® is a trademark of Pearson Education, Inc The author and publisher of this book have used their best efforts in preparing this book These efforts include the development, research, and testing of the theories and programs to determine their effectiveness The author and publisher make no warranty of any kind, expressed or implied, with regard to these programs or the documentation contained in this book The author and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs Printed in the United States of America 10 9 8 7 6 5 4 3 2 1 Pearson Education Ltd., London Pearson Education Australia Pty Ltd., Sydney Pearson Education Singapore, Pte Ltd Pearson Education North Asia Ltd., Hong Kong Pearson Education Canada, Inc., Toronto Pearson Educación de Mexico, S.A de C.V Pearson EducationJapan, Tokyo Pearson Education Malaysia, Pte Ltd Pearson Education, Inc., Upper Saddle River, New Jersey [Page xv] Preface C++ for Business Programming, Second Edition is an introduction to C++ programming The power of C++ lies in its object-oriented extensions of the C language However, we believe that for beginning students it is best to learn the basics of programming without the extra encumbrance of having to learn object-oriented concepts Therefore, the book is divided into two sections Part I, "Basic C++," covers the procedural parts of C++ Part II, "Object-Oriented Programming," covers all the essential object-oriented ideas through inheritance and polymorphism Unlike most books on C++, which emphasize applications to computing or mathematics, this book emphasizes business applications Therefore, the book is most appropriate for business and information systems students The entire book can be covered in one semester in a class of students who have a good background in programming in another language In such a class, it is possible to quickly cover the essential programming constructs from Part I and then concentrate on object-oriented concepts and programming in Part II For students who have little programming experience, we suggest covering Part I in one semester and Part II in a second semester The material in Part I can be supplemented as needed by material from Appendix A, "Computers and Data," and Appendix B, "Program Control." Throughout the book, we emphasize good pedagogy Each chapter begins with a set of learning objectives Each chapter ends with a review section that includes important terms, a chapter summary, and review exercises errors in cycle execute program program design testing and debugging the program Program module Programming problems, discussed Programming, structured Prompts calculations and protected protected access specifier pseudocode 2nd put() method Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Quiz grades averaging Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Random record input/output Read ahead rule read() method [See also Member function] syntax Real estate commission calculation Real numbers [See also Arithmetic] data representation decimal number display difficulties exponents floating point input and output of mantissa problems cash register simulation metric conversion quiz grades averaging sales tax calculation real number variables and constants Records binary sequential file in text files 2nd relative record number Reference variables 2nd References [See also Structure references] external passing objects by Relation conditions testing value of Relational condition Relational operators overloading Reserved words Resolution, external references return statement Return value 2nd 3rd [See also Value functions and] Run-time error 2nd Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Sales tax calculation Scope variable global/local 2nd scope resolution operator overloaded using Scrap value, depreciation and Search key Searching [See also Sorting] arrays binary 2nd linear/sequential 2nd 3rd tables 2nd Selection Sequence Sequential search short "Short circuit" evaluation, for logical expressions Simple interest calculation sizeof() operator files overloaded Sorting [See also Searching] arrays 2nd ascending order bubble sort tables 2nd Source code Source program Spaces, not allowed in identifiers Standard library functions Statements [See also Assignment statements; Macros] coding semicolon use in Static class data members Static class member functions Static data members Static memory Static methods Storage [See also Memory] of strings of variables row major order Straight-through principle string counting characters in 2nd counting words in defining and initializing displaying in reverse functions and, counting characters in input and output inserting using function to reverse string class accessing individual characters in arrays of 2nd assignment character searching class method concatenation of decision making with equality inequality input length of objects functions instantiating of manipulation of operations on output outputting of printing words from removing words from substring extraction substring occurrence usage of String constants [See also Constants] as pointers 2nd String functions standard library [See also Functions] in general program dem08-9.cpp strcat() function strcmp() function strcpy() function strlen() function struct, relation to class Structure references [See also References] using Structure variable [See also Variables] assigning Initialization Structured programming Structures arrays of, tables complicated defining functions and pointers to relation to classes structure members accessing data type of reference reading table definition with Student averages program Subclasses Substring insertion of removal of switch statement case structure and Syntax errors [See also Errors] checking for semicolon use and System header files Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Table key Tables defining with structures definition searching 2nd sorting 2nd 3rd 4th values loading Templates [See Function templates] Testing digits equality loop loop condition overloaded assignment operator palindromes programs with functions relation conditions relational operators Text files 2nd [See also Files] of records this pointer 2nd [See also Pointers] meaning of 2nd typedef statement format using Types and type casts [See also Data types] mixed Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Unary operators 2nd overloading Unicode Uninitialized Strings UNIX, EOF value entering unsigned using directive Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Value in expressions 2nd loading into table of assignment of relation conditions of variables passing arguments by passing object by return value 2nd 3rd Value swapping, variables Variables [See also Functions; Pointers] addresses of 2nd automatic compared to parameters constant counter data types declaring 2nd 3rd double 2nd duration-storage class file position indicator flag float 2nd functions and garbage in global 2nd int real number reference scope of static structure 2nd value of values swapping Virtual destructors [See also Destructors] virtual functions [See also Functions] pure virtual methods [See also Methods] polymorphism and Visual Basic void, in declaration Index [SYMBOL] [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] Warnings, from compiler 2nd while loops 2nd 3rd [See also Nested while loops] understanding using 2nd while statement Word processors, text files and Words [See also Characters] counting in strings write() method [See also Methods] syntax ... Pearson Education Malaysia, Pte Ltd Pearson Education, Inc., Upper Saddle River, New Jersey [Page xv] Preface C++ for Business Programming, Second Edition is an introduction to C++ programming The power of C++ lies in its... learn object-oriented concepts Therefore, the book is divided into two sections Part I, "Basic C++, " covers the procedural parts of C++ Part II, "Object-Oriented Programming," covers all the essential object-oriented ideas through inheritance and... Note that in some cases, you do steps 3, 4, 5, and 6 (which follow) in an Integrated Development Environment (IDE) Examples of IDEs are Visual Studio.NET and Borland Enterprise Studio for C++ for the Windows platform, and Code Forge for the Linux environment and KDevelop for the UNIX environment