Buy. Rent. Access.
Access student data fi les and other study
tools on cengagebrain.com.
For detailed instructions visit
http://solutions.cengage.com/ctdownloads/
Store your Data Files on a USB drive for maximum effi ciency in
organizing and working with the fi les.
Macintosh users should use a program to expand WinZip or PKZip archives.
Ask your instructor or lab coordinator for assistance.
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C++ PROGRAMMING:
PROGRAM DESIGN INCLUDING DATA STRUCTURES
SEVENTH EDITION
D.S. MALIK
Australia Brazil Japan Korea Mexico Singapore Spain United Kingdom United States
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C++ Programming: Program Design
Including Data Structures, Seventh Edition
D.S. Malik
Product Director: Kathleen McMahon
Senior Product Manager: Jim Gish
Senior Content Developer: Alyssa Pratt
Product Assistant: Gillian Daniels
Content Project Manager: Jennifer
Feltri-George
Art Director: GEX Publishing Services
Print Buyer: Julio Esperas
Cover Designer: GEX Publishing Services
Cover Photo: ª OlegDoroshin/Shutterstock.com
Proofreader: Andrea Schein
Indexer: Sharon Hilgenberg
Compositor: Integra Software Services
Cengage Learning
ª
WCN: 02-200-203
ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
any means—graphic, electronic, or mechanical, including but not limited
to photocopying, recording, scanning, digitizing, taping, Web distribution,
information networks, or information storage and retrieval systems,
except as permitted under Section
Copyright Act—without the prior written permission of the publisher.
United States
or
of the
For product information and technology assistance, contact us at
Cengage Learning Customer & Sales Support, www.cengage.com/
support.
For permission to use material from this text or product,
submit all requests online at www.cengage.com/permissions.
Further permissions questions can be emailed to
permissionrequest@cengage.com.
Library of Congress Control Number:
ISBN-
:
- -
-
-
Cengage Learning
First Stamford Place, 4th Floor
Stamford, CT
USA
Cengage Learning is a leading provider of customized learning solutions
with office locations around the globe, including Singapore, the United
Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office
at: www.cengage.com/global
Cengage Learning products are represented in Canada by Nelson
Education, Ltd.
Purchase any of our products at your local college store or at our
preferred online store: www.cengagebrain.com
Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or
registered trademarks of their respective manufacturers and sellers.
Microsoft product screenshots used with permission from Microsoft
Corporation.
Unless otherwise credited, all art and tables ª 2015 Cengage Learning,
produced by Integra.
Cengage Learning reserves the right to revise this publication and make
changes from time to time in its content without notice.
Any fictional data related to persons or companies or URLs used
throughout this book is intended for instructional purposes only. At the
time this book was printed, any such data was fictional and not
belonging to any real persons or companies.
The programs in this book are for instructional purposes only. They have
been tested with care, but are not guaranteed for any particular intent
beyond educational purposes. The author and the publisher do not offer
any warranties or representations, nor do they accept any liabilities with
respect to the programs.
Printed in the United States of America
1 2 3 4 5 6 7 20 19 18 17 16 15 14
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TO
My Parents
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
BRIEF CONTENTS
ª HunThomas/Shutterstock.com
PREFACE
1. An Overview of Computers and Programming Languages
2. Basic Elements of C++
3.
Input/Output
4. Control Structures I (Selection)
5. Control Structures II (Repetition)
6. User-Defined Functions
7. User-Defined Simple Data Types, Namespaces,
and the string Type
8. Arrays and Strings
9. Records (structs)
10. Classes and Data Abstraction
11. Inheritance and Composition
xxxv
1
27
123
185
263
345
465
519
609
649
737
12. Pointers, Classes, Virtual Functions, Abstract Classes, and Lists
811
13. Overloading and Templates
14. Exception Handling
15. Recursion
16. Linked Lists
17. Stacks and Queues
18. Searching and Sorting Algorithms
901
997
1039
1071
1165
1265
Copyright 2015 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.