Introduction to C++ Programming and Graphics
Constantine Pozrikidis Department of Mechanical and Aerospace Engineering (MAE) University of California, San Diego 9500 Gilman Drive La Jolla, CA 92093-0411 email@example.com
Cover illustration: The illustration on the front cover shows a twisted nanoring consisting of a warped hexagonal lattice of carbon atoms. Library of Congress Control Number: 2007921582
ISBN-10: 0-387-68992-3 ISBN-13: 978-0-387-68992-0
Printed on acid-free paper.
e-ISBN-10: 0-387-68993-1 e-ISBN-13: 978-0-387-68993-7
© 2007 Springer Science+Business Media, LLC All rights reserved. This work may not be translated or copied in whole or in part without the written permission of the publisher (Springer Science+Business Media, LLC, 233 Spring Street, New York, NY 10013, USA), except for brief excerpts in connection with reviews or scholarly analysis. Use in connection with any form of information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed is forbidden. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.
9 8 7 6 5 4 3 2 1
The C++ programming language was introduced by Bjarne Stroustrup of the AT&T laboratories in 1985 as an extension of C, with additional features borrowed from the esoteric language Simula. Since then, C++ has grown rapidly in response to the practical need for a programming language that is able to eﬃciently handle composite and diverse data types. The language implementation is pivoted on the ingenious concept of object oriented programming (OOP). Today, C++ dominates the commercial market and is favored among system programmers and application developers.
Object oriented programming
To illustrate the advantages of an object oriented programming language compared to a structured language such as Matlab, Fortran 77, or C, we assume that an international sports competition has been entered by runners from many countries around the globe. The record of each runner consists of several ﬁelds including name, country of origin, city of birth, date of birth, and best performance time. In a structured language, each one of these ﬁelds is normally registered in a separate data vector. In an OOP language, each runner becomes an object deﬁned as a member of the class of runners, and each member is described by the collection of these ﬁelds. This formalism allows us to record, recall, and manipulate in any desired way the personal data of each runner using simple symbolic operators. Sub-classes consisting, for example, of runners of a particular nationality can be readily deﬁned to facilitate more detailed manipulations. An OOP language allows us to introduce a data type of our choice viewed as an object in a deﬁned class, and then use the class as a building block for further development. This ﬂexibility essentially allows us to build a language without building a compiler. In this sense, an OOP language is an ultimate language.
C and C++
C++ is a generalization of C, but accomplishes much more than C, to the extent that it should be regarded, studied, and taught as a separate language. It is neither necessary nor recommended to study C as a prerequisite of C++, though knowledge of C can be helpful.
This book is a brief and basic introduction to C++ for everyone and especially for scientists and engineers. The text oﬀers a venue for eﬀectively teaching and rapidly learning the language at the level of an undergraduate course in any discipline of the physical sciences and computer science and engineering. The discussion illustrates step-by-step the grammar, syntax, and...