Introduction to OOP With

Introduction to OOP With

Library: Udžbenici Book Number: 16 Main Editor: prof. dr Safet Krkić Technical Review: prof. dr Senad Burak prof. dr Dražena Tomić Language Review: Authors Book Covers: Mirza Hadžikadunić DTP: Authors Copyright © Authors, 2005 FIT Mostar, 2005 Edicions de la Universitat de Leida, 2005 All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the copyright owners. Printed by Štamparija "FOJNICA" d.o.o. Fojnica Supported by TEMPUS project CD JEP 16110-2001 CIP Katalogizacija u publikaciji Edicions de la Universitat de Leida Nacionalna i univerzitetska biblioteka Bosne i Hercegovine, Sarajevo 004.42(075.8) RIBO, Josep Maria RIBO, Josep Maria Introduction to OOP with C++ / Introduction to OOP with C++ / Josep Maria Ribo, Ismet Maksumić, Josep Maria Ribo, Ismet Maksumić, Siniša Čehajić – Mostar: Siniša Čehajić – Mostar: Univerzitetska knjiga, 2005. – 333. str: graf. prikazi; 25 cm. – (Biblioteka Udžbenici; knj. 16) Bibliografija: str. 331-332 ISBN 9958-603-22-5 ISBN 84-8409-199-6 1. Maksumić, Ismet 2. Čehajić, Siniša 1. Maksumić, Ismet 2. Čehajić, Siniša COBISS.BH-ID 14230534 Published by Univerzitetska knjiga Mostar, 2005 Edicions de la Universitat de Leida, 2005 Josep Maria Ribó Ismet Maksumić Siniša Čehajić Introduction to OOP with C++ Published by Univerzitetska knjiga Mostar Edicions de la Universitat de Leida, July, 2005 Table of contents Chapter 1: Principles od OOP. Classes. Objects...................................................1 1.1. Modelling concepts.........................................................................................1 1.1.1. Abstract types...........................................................................................2 1.2. Concept of class ..............................................................................................4 1.3. Concept of object ..........................................................................................10 1.3.1. State .......................................................................................................11 1.3.2. Behaviour...............................................................................................11 1.3.3. Identity ...................................................................................................12 1.3.4. Classes vs. objects..................................................................................13 1.3.5. The object orientation programming paradigm......................................14 1.4. Class contracts ..............................................................................................15 1.4.1. Defining a class contract........................................................................16 1.4.2. Preconditions..........................................................................................16 1.4.3. Postconditions........................................................................................20 1.4.4. Class invariants ......................................................................................21 1.4.5. Correctness of a class implementation...................................................23 1.4.6. Example: Contract for the class Date...................................................24 1.5. Detailed class and object definition in C++..................................................26 1.5.1. Private and public members...................................................................29 1.5.2. Operation declaration and implementation ............................................30 1.5.3. Object creation.......................................................................................30 1.5.4. Access to members ................................................................................37 1.5.5. References vs. pointers ..........................................................................39 1.5.6. Splitting class definition into different files...........................................40 1.6. Some (pleasant) consequences of class definition ........................................42 1.7. Guided problems. The class MyString......................................................44 1.7.1. The problem...........................................................................................44 1.7.2. Solution..................................................................................................45 1.7.3. The file Makefile...............................................................................50 1.8. Guided problems. The word counter.............................................................50 1.8.1. The class WordCounter .....................................................................50 1.8.2. A client program ....................................................................................56 1.8.3. The class WordCounterInterface................................................57 Chapter 2: Special members .................................................................................61 2.1. Constructors ..................................................................................................61 2.1.1. Notion of constructors............................................................................61 2.1.2. Constructor overloading.........................................................................64 2.1.3. Default constructor.................................................................................65 2.1.4. Default parameters .................................................................................65 2.1.5. Copy constructor....................................................................................66 2.1.6. Construction call in the creation of arrays of objects.............................71 2.1.7. Creation of temporary objects................................................................71 2.1.8. Dynamic object construction .................................................................72 2.1.9. Construction of dynamic arrays of objects.............................................73 2.1.10. An example ..........................................................................................74 2.2. Destructors ....................................................................................................75 2.2.1. Why are destructors necessary? The garbage .......................................75 2.2.2. The operator delete............................................................................78 2.2.3. Destructors in C++.................................................................................78 2.2.4. Destruction of dynamic objects..............................................................80 2.2.5. Destructors and sharing of identity: warnings .......................................81 2.3. Friend functions and classes .........................................................................83 2.4. Operator overloading ....................................................................................85 2.4.1. Operator = ..............................................................................................85 2.4.2. Operator ==............................................................................................88 2.4.3. Operator []..............................................................................................89 2.4.4. Operator ()..............................................................................................90 2.4.5. Operators << and >>..............................................................................91 2.5. What operations any C++ class should offer ................................................92 2.6. Guided problems. The class MyString......................................................92 2.6.1. Solution: File MyString.h.................................................................93 2.6.2. Solution: File MyString.cpp............................................................93 2.6.3. Solution: File userString.cpp .......................................................97 Chapter 3: Generic classes and functions............................................................99 3.1. Generic classes..............................................................................................99 3.1.1. Implementation of operations out of the template class definition ......102 3.1.2. Templates with more than one template parameter and non-type parameters......................................................................................................103 3.2. Generic functions........................................................................................103 3.2.1. Incorporating functions as template parameters ..................................106 3.2.2. Explicit instantiation of a template function ........................................108 3.3. File organization with templates.................................................................109 3.4. Guided problems: A generic stack..............................................................110 3.4.1. The problem.........................................................................................110 3.4.2. Solution: File Stack.h......................................................................111 3.4.3. Solution: File userStack.cpp........................................................113 Chapter 4: Associations. Composite objects. References .................................117 4.1. Associations, aggregations and

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    343 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us