0% found this document useful (0 votes)
96 views

Introduction To C++: Language, Standard Library and OO Design

This document provides an overview and outline of an introduction to C++ course. The course covers three main topics: the C++ language, the C++ standard library, and general design principles. For the C++ language section, it describes key concepts like data abstraction, relationships between objects, generic programming, and encapsulation. It outlines the main components of the standard library like containers, iterators, algorithms, and functors. For design, it discusses iterative design processes, requirements capture, analysis, design, implementation, and testing. It provides a schedule showing the different chapters to be covered over the course days.

Uploaded by

Hiro San Lorenzo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
96 views

Introduction To C++: Language, Standard Library and OO Design

This document provides an overview and outline of an introduction to C++ course. The course covers three main topics: the C++ language, the C++ standard library, and general design principles. For the C++ language section, it describes key concepts like data abstraction, relationships between objects, generic programming, and encapsulation. It outlines the main components of the standard library like containers, iterators, algorithms, and functors. For design, it discusses iterative design processes, requirements capture, analysis, design, implementation, and testing. It provides a schedule showing the different chapters to be covered over the course days.

Uploaded by

Hiro San Lorenzo
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Introduction to C++

Language, Standard Library and OO Design

Letters

uses

WordTree

WordsSoFar WordNode
has-a has-a

Game
has-a

Dice
is-a

is-a

PerqDice

RandomDice

1.

This course does not assume that you know any particular computer language or have any experience with software design, but it is aimed at people who have a university degree in a field related to computer science.

Outline
l l l l l l l l

Participants backgrounds Course overview The C++ Language The C++ Standard Library The Design Process History of C++ C++s place in the world Resources

1.

At the end of this chapter we will look at an overview of the exercises that will be done after each of the other chapters.

Participants Backgrounds
l For each participant

State name Give synopsis of relevant experience Explain current position State expectations

He who asks is a fool for a minute He who does not ask is a fool forever.
Chinese proverb

1. 2. 3. 4. 5.

Please use the name-cards provided; some instructors are good at remembering peoples names, but some have a hard time remembering their own :-) If you have taken any courses in programming languages or analysis and design, mention them. If you have had any experience programming in any language, summarise how much and what type of language. If you have read any books related to C++ or object-oriented programming, this would also be a good thing to point out. Your current position is important --- are you going to be using C++ right away? Are you already using it? Are you just learning it to see if it might be useful to you? Are you here because you want to be or because you were told to come? The most important thing here is to tell the instructor what you want to get out of the course. The instructor can try to shift the focus of the course to best suit the needs of most of the participants, but only if you are clear and open about what you want to hear about and what you are not interested in. Dont expect that everyone will get exactly what they want, but please provide feedback as the course progresses on what is most helpful and what is less helpful for you. Most instructors will not mind if, for part of the course you already know, you do something else like read a book or answer your mail. You probably want to avoid guffawing loudly at the daily comics, though :-) If you have terminals in the classroom, feel free to use them during the classes as long as it doesnt bother the other students. If you expect that you will be doing this a lot, consider sitting at the rear of the room. Students are sometimes called away unexpectedly for personal reasons or to put out fires in their offices... This is not a problem, but it is polite to tell the instructor either before or afterwards why you are leaving.

6.

7. 8. 9.

Course Overview

C++

Language

Library

Design

1. 2.

The topics we cover in this course fall into three main categories: the C++ language, the standard C++ library, and general design issues. Since this is a hands-on course, in order to facilitate doing the exercises, we will not cover these topics directly in order; instead, we will cover some language issues, some of the library components and some design issues in most of the chapters. To get an idea of the topics that will be covered, however, we will present them here broken down into language, library and design.

3.

The C++ Language


C++ Language

Data Abstraction

Relationships

Generic Programming

Encapsulation

Inheritance

Components

Protection Resource Ownership

Aggregation

Modeling Concepts Adaptors

Association

1.

Data abstraction separates the interface (how the object is used) from the implementation (how it works inside). It is one of the oldest design techniques in computer programming, and it has been recognized as important for a number of decades. Traditional (procedural) languages like C and Fortran do not provide any support for data abstraction, although programming conventions can be used in those languages. C++, like all object-oriented languages, provides explicit support for data abstraction, through classes that define both data and methods (encapsulation), protection (compiler enforces access only to the public part of a class), and resource ownership (classes can manage resources by prohibiting outside access to them). Relationships between objects and types are fundamental in object-oriented programming; inheritance defines a relationship between types corresponding to is-a, aggregation corresponds to has-a, and associations are more general relationships. We will look at the C++ mechanisms for representing these various relationships, and how they are used in the design process. Generic programming is a notion that has gained a lot of popularity in the last few years; originally used in Ada, the Standard Template Library (roughly a subset of the standard C++ library) made it popular in C++. Basically, generic programming involves defining small, simple components that can be fit together in many different and useful ways, somewhat similar to the idea behind Lego(TM). We will look at the components that make up the standard library, how they are defined in terms of concepts and modeling, and one of the essential concepts of generic programming: adapters that provide different interfaces to existing components.

2.

3.

The C++ Standard Library


Containers Adaptors Utilities

Iterators

Functors

Algorithms Numerics Locales

Diagnostics

Strings Streams

Allocators

C Library

1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Containers are objects that contain other objects, e.g., vector, set, map. Iteratorsrepresent locations in a container. Each container has its own iterator type. Algorithms are operations on containers, e.g., find, sort, random_shuffle. Functors are operations on objects, e.g., less, plus. Adaptors are objects that change an interface, e.g., not1. (That's a one at the end, not an ell; there is also a not2.) Utilities are components such as pairs, operations like comparison, etc. In the ANSI standard, allocators are included in the utilities section. Diagnostics are provided to deal with exceptions. Locales facilitate internationalization. Numerics are container types that are optimized for speed, less general than containers, e.g., valarray, complex. Strings replace Cs character arrays. Streams are used for input and output. Allocators customize memory allocation, e.g., malloc_alloc. We will not have time to cover every type in the standard library, as it is very large. However, we will cover the most important concepts, which will allow you to use standard documentation to use the other types. A large part of the standard C++ library (ANSI and ISO ratified the standard library along with the language definition in November 1997) consists of components taken from the STL (Standard Template Library), written by Alexander Stepanov while at HP (now at SGI). The STL has continued to grow since the standard was defined, so it is no longer a strict subset of the standard library. For example, it now includes hashed containers, ropes and singly -linked lists.

The Design Process

Iterative design
Inception Elaboration Construction Transition

Requirements capture Analysis and Design Implementation Test

preliminary

n+1

n+2

m+1

Time

1. 2.

This graph is adapted from the Rational Rose book Visual Modeling with The Unified Modeling Language by Terry Quatrani, with permission from Addison Wesley Longman. As the graph shows, object-oriented design is an iterative process. In the early phases of the design process, we concentrate on requirements capture: determining, with the aid of domain experts, exactly what the requirements of the system are. Next come analysis and design, which continue while implementation starts. Testing is done concurrently with implementation throughout the design process. Typically, the analysis and design phases will illustrate some shortcomings in the requirement capture, and the implementation will illustrate some shortcomings in the analysis and design. Therefore it is imperative that these phases continue in parallel, unlike the old waterfall method, where each phase was completed before the next phase was begun. Analysis is typically used to refer to a high-level description of the project, describing logical components and their interactions. Design is a description of an actual system to perform the required tasks, taking into account things like the programming language(s) to be used, the architecture of the machine(s) the software will be running on, the communication infrastructure, and so on. An important part of object-oriented design is communication between the different members of the design and implementation team, as well as between the members of the team and the domain experts who understand the goals of the system, though usually not the details of OO design and implementation. In order to facilitate this communication, using standard design diagrams and tools can be very helpful. The software industry is gradually moving towards the standard UML (unified modeling language) design notation, which is supported by such tools as Rational Rose. Round-trip engineering tools, which allow iterative design and implementation (that is, the design notation can be converted to code and vice-versa) are beginning to become available, though in practice many of them are still difficult to use or provide only a subset of the functionality one would want.

3.

4.

5.

Course Sections
Day Mon Chapter
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

Description
Introduction Getting Started Variables and strings Functions Control Flow Arrays Pointers Const and References Structures Data Abstraction Constructors Accessor Functions Dynamic Allocation and Responsibilities Exceptions Operators Templates and Generic Programming Containers, Iterators and Algorithms Functors and Adaptors

Focus
General General Language/Library Language Language Language Language Language Language Design Design Language Design Design Language Design/Language Library Library

Tue

Wed

Thu

Fri

1. 2. 3. 4.

The colors are not correct at the moment; eventually they will indicate whether the chapter is focusing on language, library, or design. After each chapter will be an exercise; the exercises constitute about 50% of the course. The exercises (apart from the first warm-up exercise) build on each other; by the end of the course we will have built a program based on the board game Perquackey. Green is language, Red is library, Blue is design

Course Sections
Day Mon Chapter
19 20 21 22 23
24 25

Description
Inheritance Polymorphism Associative Containers Relationships Streams User Interfaces Review

Focus
Design Design/Language Library Design Library Design General

Tue

Wed

Thu

Fri

1. 2.

After each chapter will be an exercise; the exercises constitute about 50% of the course. The exercises (apart from the first warm-up exercise) build on each other; by the end of the course we will have built a program based on the board game Perquackey.

History of C++
1960 Fortran Algol60 Algol68 C C with Classes C++ C++arm Ada9X
Java

Lisp
Smalltalk

1970

Simula67

1980 Ada 1990 2000

CLOS

C++std

1. 2.

Source: Stroustrup, the Design and Evolution of C++. C++ was developed by Bjarne Stroustrup at AT&T labs. It originated as an attempt to incorporate the Simula notion of class (providing explicit data abstraction) into C, which was at the time one of the most popular programming languages. Other features, such as inheritance, operator overloading and templates were added in successive versions of the language. The language continued to grow with the addition of exceptions, and refinements to the template mechanism, until November 1997, when the ANSI and ISO committees ratified the standard. This standard will remain unchanged for at least five years after the ratification, providing a solid foundation for users of the language. Along with the ratification of the standard language definition, the standard library, a very large set of classes and functions, was ratified by the standard. As of this writing (February 2000), no compilers fully support either the standard or the library, but the major compilers are now close to full support.

3.

10

Programming Languages
l

Characteristics of Languages

Efficiency Flexibility Ease of Design Ease of Maintenance Availability of Programmers Availability of Libraries

l l

Many of these are subjective Different languages useful for different tasks

1. 2. 3.

No one programming language is ideal for all tasks; it is important to choose a language appropriate for the kinds of applications you will be developing. However, practical and political considerations often outweigh technical considerations. General purpose languages have the advantages of more existing code and a larger base of programmers; these advantages often outweigh the disadvantages of a larger language and less specific language support for certain tasks.

11

Programming Languages
l Diagram

of programming languages, relating C++ to others, e.g. C, Java, Ada, perl/python, Objective C looking for material for this)

l (still

1. 2. 3.

Forth, Fortran, Python, Turbo Pascal, Prolog, Prolog++, OO-Cobol, Cobol, Haskel, Eiffel, Objective-C, Snobol, Algol, Ada Which ones are standard and which are not Try to put in many languages, make size represent importance, or market-share, perhaps.

12

Why C++?
l l l l l l

Almost as efficient as C Appropriate for many design methodologies Large base of programmers Extensive standard library Designed to scale well ANSI/ISO standard

1. 2.

Well-written C++ code is almost as efficient as C code. Without a basic understanding of how C++ works, however, it is easy to write very inefficient C++ code. C was designed with efficiency as one of its main goals. C code is typically almost as fast as assembler. C has existed for a long time, compared to most programming languages in common use, and therefore most platforms have highly optimized C compilers. C is the language used to write many operating systems and games, two types of applications where efficiency is critical. The biggest disadvantage of C is that it does not provide facilities that make object-oriented and generic programming easy. C++ supports procedural, object-oriented and generic programming techniques. There is support for development in C++ in many standard methodologies and their design tools (e.g., Software Through Pictures, Unified Modeling Language, Object Modeling Technique). IDS estimated that 1.2 million C++ Implementations were sold in 1996. Stroustrup estimates the growth rate at 20% (+/- 10%) per year. The Standard C++ library was ratified by the ISO and ANSI committees in November 1997.

3. 4. 5. 6.

13

Books
l

Learning C++

Lippman: C++ Primer Dewhurst and Stark: Programming in C++ Thinking in C++ Stroustrup: The C++ Language, 3rd Edition Austen: Generic Programming and the STL Josuttis Meyers: Effective C++, More Effective C++ Lippman: C++ Gems Cline: C++ FAQs Coplien: Advanced C++ Koenig: Ruminations on C++ Gamma et al: Design Patterns Larman: Applying UML and Patterns The Tao of Objects (oldish, though)

Reference

Advanced C++ and OO Design


1. 2. 3. 4.

Stanley Lippmans C++ Primer (now in the 3rd edition) is one of the classic texts for learning C++, and still one of the best. Thinking in C++ is recommended by many people; it is a free C++ tutorial, Dewhurst and Starks Programming in C++ does not cover the entire language, but has very good sections on design, something that is lacking in many other books on C++. Scott Meyers has written several books that are considered essential reading by many C++ experts. Effective C++ provides 50 simple rules of thumb, with extensive explanations of the rationales behind them. More Effective C++ is not a replacement for Effective C++, but a continuation, with 35 more rules of thumb. There is now a second edition of Effective C++, about 80% rewritten from the first edition. Stanley Lippmans C++ Gems is a collection of articles based on threads in the Usenet newsgroup comp.lang.c++. They cover important topics such as advanced template techniques, using exceptions, and design issues. Clines book C++ FAQs is based on the C++ Frequently Asked Questions posted monthly in the newsgroup comp.lang.c++, with many of the answers considerably expanded from the newsgroup. James Copliens Advanced C++ covers advanced techniques in excellent detail. Andrew Koenig and Barbara Moos Ruminations on C++ gives some very good insights into C++ development by two long-time practitioners from AT&T labs. Negative recommendations: avoid Schildt. See accu.org's reviews for details.

5. 6. 7. 8. 9.

14

Internet Resources
l

Web sites

http://www.sema4usa.com/ http://www.sema4usa.com/clients/<clientname>/<date>.html http://triple.des.encrypted.net/ comp.lang.c++ comp.lang.c++.moderated comp.std.c++ EFnet/#c++, #coders, #winprog, #c++builder DALnet/#c++

Newsgroups

IRC channels

1. 2.

There are more references and summaries on Semaphores web site. Comp.lang.c++ is a very-high volume newsgroup suitable for asking pretty much any question about C++. Comp.lang.c++.moderated gets about 100 messages a day. Read it for several months before posting there. Many of the worlds most knowledgeable C++ people read and post to this newsgroup (e.g., Bjarne Stroustrup, Francis Glassboro, Scott Meyers, Andy Lippman, Andy Koenig) This page needs a lot more added to it. cscene, bytamin-c, accu.org Should also mention C++ journals, Dr Dobbs.

3. 4. 5.

15

You might also like