ebook img

Demystified Object-Oriented Programming with C++ PDF

568 Pages·2021·4.144 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Demystified Object-Oriented Programming with C++

Demystified Object-Oriented Programming with C++ Implement proven object-oriented design principles to write better code and create robust software Dorothy R. Kirk BIRMINGHAM—MUMBAI Demystified Object-Oriented Programming with C++ Copyright © 2021 Dorothy R. Kirk All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the author, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Group Product Manager: Aaron Lazar Publishing Product Manager: Alok Dhuri Senior Editor: Rohit Singh Content Development Editor: Ruvika Rao Technical Editor: Gaurav Gala Copy Editor: Safis Editing Project Coordinator: Francy Puthiry Proofreader: Safis Editing Indexer: Pratik Shirodkar Production Designer: Nilesh Mohite First published: March 2021 Production reference: 1250321 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-83921-883-5 www.packt.com To my family, especially my children. For my oldest, a brilliant physicist, astronomer, and astrophysicist. For my youngest, a superlative writer and advocate for equality. May they make our world (and universe) a better place. Contributors About the author Dorothy R. Kirk has specialized in OO technologies since nearly their inception. She began as an early adopter of C++ at General Electric in R&D. After working on various projects, she was one of 10 charter members to start GE's Advanced Concepts Center to commercially utilize OO technologies. She later started her own OO Training and Consulting business, specializing in OOP using C++ and Java. She additionally programs in Python. Ms. Kirk has many OO courses and has clients spanning industries such as finance, transportation, software, embedded systems, manufacturing, and medical imaging. Ms. Kirk earned a B.S. in Computer and Information Sciences from the University of Delaware and an M.S. in Computer Science from Temple University. I want to thank those who have consistently supported my endeavors, including my husband, children, parents, sister (and her family), extended family, and close friends. I also want to thank the many people at Packt who have contributed to this project, especially Alok Dhuri and Ruvika Rao, who have worked with me often and tirelessly. About the reviewer Vinícius G. Mendonça is a professor at PUCPR and a mentor at Apple Developer Academy. He has a master's degree in Computer Vision and Image Processing (PUCPR) and a specialist degree in Game Development (Universidade Positivo). He is also one of the authors of the book Learn OpenCV 4 by Building Projects, also by Packt. He has been working in the field since 1996. His former experience includes designing and programming a multithreaded framework for PBX tests at Siemens, coordination of the Aurelio Dictionary software – including its apps for Android, iOS, and Windows Phone – and coordination of an augmented reality educational activity for Positivo's "Mesa Alfabeto," presented at CEBIT. Currently, he works with server-side Node.js at a company called Cluster For Change. First of all, I would like to thank Thais, my spouse and the love of my life, for being a wonderful partner and supporting me every day. I would also like to thank my daughters, Mariana, Alice, Laura, Helena, and Renata: you're the best, girls! Also, my compliments to my stepson, Bruno, who makes me proud, since he is also becoming a skilled programmer and listens to my technical mumbo jumbo all day. You are all my reason to live and I love you all. Table of Contents Preface Section 1: C++ Building Block Essentials 1 Understanding Basic C++ Assumptions Technical requirements 4 Looping constructs: while, do while, and for loops 11 Reviewing basic C++ language syntax 4 Reviewing C++ operators 14 Variable declarations and standard Revisiting function basics 15 data types 4 Reviewing user-defined Variables and array basics 5 type basics 17 Comment styles 7 struct 17 Recapping basic I/O 7 typedef 18 The iostream library 7 class 19 Basic iostream manipulators 9 enum 20 Revisiting control structures, Recapping namespace basics 21 statements, and looping 10 Summary 23 Control structures: if, else if, and else 10 Questions 24 2 Adding Language Necessities Technical requirements 26 Working with function Using the const qualifier 26 prototypes 29 Const variables 26 Defining function prototypes 30 Const qualification with functions 29 ii Table of Contents Naming arguments in function Learning the basics of function prototypes 31 overloading 36 Adding default values to function Eliminating excess overloading with prototypes 32 standard type conversion 39 Prototyping with different default Ambiguities arising from function values in different scopes 34 overloading and type conversion 41 Understanding function Summary 43 overloading 36 Questions 44 3 Indirect Addressing: Pointers Technical requirements 46 Passing pointers as arguments to functions 63 Understanding pointer basics and memory allocation 46 Using pointers as return values from functions 66 Revisiting pointer basics 47 Using the address-of and dereference Using the const qualifier with operators 47 pointers 68 Using the operators new() and delete() 48 Using pointers to constant objects 69 Creating and using pointers to user Using constant pointers to objects 70 defined types 49 Using constant pointers to constant objects 71 Allocating and deallocating arrays at run time 51 Using pointers to constant objects as function arguments and as return Dynamically allocating single- types from functions 72 dimension arrays 51 Dynamically allocating 2-D arrays: Using pointers to objects of arrays of pointers 55 unspecified types 75 Dynamically allocating 2-D arrays: Creating void pointers 76 pointers to pointers 58 Dynamically allocating N-D arrays: Summary 78 pointers to pointers to pointers 60 Questions 78 Using pointers with functions 63 4 Indirect Addressing: References Technical requirements 82 Understanding reference basics 83 Table of Contents iii Declaring, initializing, and accessing Using references to constant objects 94 references 83 Using pointers to constant objects Referencing existing objects of user as function arguments and as return defined types 86 types from functions 95 Using references with functions 87 Realizing underlying implementation and restrictions 98 Passing references as arguments to functions 88 Understanding when we must use Using references as return values pointers instead of references 99 from functions 91 Summary 100 Using the const qualifier with Questions 101 references 93 Section 2: Implementing Object-Oriented Concepts in C++ 5 Exploring Classes in Detail Technical requirements 107 Creating conversion constructors 133 Introducing object-oriented Understanding destructors 139 Applying destructor basics and terminology and concepts 107 proper usage 140 Understanding object-oriented terminology 107 Applying qualifiers to data Understanding object-oriented members and member concepts 109 functions 144 Adding inline functions for potential Understanding class and efficiency 144 member function basics 109 Adding const data members and the Examining member function member initialization list 148 internals; the "this" pointer 114 Using const member functions 152 Using access labels and Utilizing static data members and access regions 119 static member functions 156 Understanding constructors 124 Summary 163 Applying constructor basics and Questions 164 overloading constructors 124 Creating copy constructors 127

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.