Scientific and Engineering C++

所需积分/C币:43 2018-10-17 10:19:16 24.62MB PDF
17
收藏 收藏
举报

More Effective C++ 作者推荐的书籍,原版资源。此书第一部分为FORTRAN程序员解释C++,然后应用template达到炉火纯青的步骤。
Editor: Tom Stone/Debbie Lafferty tion Supervisor: Helen wythe Superscript Editorial Production Services Windfall Software(Paul C Anagnostopoulos/Joe Snowden, using ZZTEX) Vilson Graphics &x design (Kenneth J. Wilson) Marshall henrichs ing Manager: Roy Logan ures and applications presented in this book have been included for their in value. They have been tested with care but are not guaranteed for any purpose er does not offer any warranties or representations, nor does it accept any lia respect to the programs and applications designations used by manufacturers and sellers to distinguish their products as trademarks. Where those designations appear in this book, and Addiso aware of a trademark claim, the designations have been printed in initial caps ongress Cataloging -in-Publication Dat fic and engineering C++: an introduction with advanced d examples/John J. Barton, Lee R Nackman s bibliographical references and index. 201-53393-6 . Computer program language) I Nackman, Lee R C153B381994 --dc20 93-40343 CIP )1994 by Addison Wesley Longman, Inc. eserved. No part of this publication may be reproduced, stored in a stem,or transmitted in any form or by any means, electronic photocopying, recording, or otherwise, without prior written of the publisher. Printed in the United States of America. Published 10MA02010099 January 1999 for Ava nackman Cynthia butler y PREFACE IKE many scientists and engineers, much of our work involves writing com- puter programs. Recently we have been writing those programs in C++. We think that our programs are better and that we can do better science and engineering with these programs because they are written in C++. We think you should try C++, and we wrote this book to help you get started C++ is one of several new languages that use a programming style called object-oriented programming To write large programs that are correct, readable, modifiable, affordable, and efficient requires the same creative effort and persis tence characteristic of other endeavors in science and engineering. Traditional pro- gramming languages, including FORTRAN and C, force us to communicate with the computer in a demeaningly simplistic manner. C++ and an object-oriented programming style elevate the communication to a more abstract level: They pro- vide means for investing intellectual effort to produce better-quality programs and thus better-quality science and engineering, from a given programming p roject Learning C++ will be exciting. Although most of the programming ideas used in languages like FORTRaN, PASCAL, and C are still used in object-oriented pro- grams, the new concepts reorganize the work. Like all new fields, object-oriented programming will seem foreign and exotic. C++ embodies a decade of new ideas from computer science backed up by practical experience. These new ideas will stimulate your thinking about programming and its role in your work. We hope you will find, as we have, that this new view changes programming from a te dious, albeit engaging, process to an intellectual enterprise more comparable to the processes we employ in other scientific and engineering work. Purpose The purpose of this book is to teach you how to use C++ and the object oriented programming style to produce better-quality programs, with an em phasis on scientific and engineering programs. Most such programs today are written in FORTRAN or C and without the benefit of any particular program- ming methodology For small programs of strictly numerical content, FORTRAN or c may be adequate. However, larger programs and programs containing non- numerical code are too expensive to understand to revise, and to improve if writ- ten in FORTRAN or C We present object-oriented programming as a design and vi Preface Programming style that addresses these problems and Ct+ as a programming lan guage designed to allow efficient use of he object-oriented style. If you are still us. ing FoRtRan or Cin your programming, we invite you to explore a new world, the world of object-oriented programming in ct+ Audience Our book teaches object-oriented programming in C++, using examples from science and engineering. It is not a book about scientific computing or numerical analysis nor an introduction to programming. The book moves rapidly throug. the basic features and syntax of C++, material readily assimilated by an engineer or scientist experienced in progranming or, indeed, by any experienced program- mer. Our aim is to move quickly beyond syntax and rules to the more interesting and important concepts and techniques of object-oriented programming in C+t The latter part of the book applies the concepts and techniques developed to sub stantive examples. The examples are drawn primarily from science and engineer- ing, but the concepts and techniques are broadly applicable We expect the book to be useful to three(overlapping)groups: Engineers and scientists who are experienced programmers in FORTRAN or c Professional programmers experienced in C or C++ looking for a new system- atic discussion of object-oriented programming in C++ C++ programmers interested in advanced examples useful as a basis for sci- entific and engineering programming. In addition to programming experience, some of the examples assume the math ematical maturity typical of an undergraduate student in an engineering or scien- tific field Learning C++ and object-oriented programming will be a challenge regard less of your background. We were frankly amazed that computer programming could be so different. We hope you find this challenge stimulating and rewarding on its own; we are confident that once you understand C++ and object-oriented programming, you will not be satisfied with less Acknowledgments This book was made possible by the considerable patience of our empl the Research Division of the IBM Corporation, and the personal patience and en couragement of our managers, colleagues, friends, and families. We began work Preface vii on this book when we were in the Physical Sciences(Barton)and Manufacturing Research(Nackman departments. Our managers in those departments-Reac McFeely, Franz Himpsel, and Bruce Scott; Mike Wesley, Warren Grobman, and Russ Lange supported and encouraged our work a special thanks to the late Mike Wesley, manager, mentor, and friend for a decade: He recognized the im portance of producing quality software for engineering applications and provided the environment, encouragement, and support for learning something about how to do it. We have completed work on the book in the Computer Science depart- ment, where we enjoy the considerable support and encouragement of our man- ager Mark Wegman We are indebted to all of our colleagues at IBM Research for having made it a special place to work and learn. We especially thank Michael Karasick and Derek Lieber for helping us, over many years, to learn C++ and how to use it, and Louis Terminello for timely and gracious encouragement. We also thank bjarne Stroustrup and the developers of IBM's C++ compiler, especially Mark Mendell, Dave Streeter, and Ernest Choi, for correspondence and encouragement while we learned and relearned c++ We were also fortunate to have the help of many reviewers; their comments improved many aspects of the book, ranging from typography to the book's or ganization. The comments of James Coplien, Tom Lyons, and William Press had an especially large impact on the book. As deadlines loomed, Michael Karasick read furiously through several drafts to help us weed out the worst confusions We also thank John L. Bradberry, Goodwin Chin, Marshall Cline, Chris Codella, Margaret Ellis, Martin Giles, Franklin Gracer, Peter Juhl, Derek Lieber, Mark Lin ton, Tom Linton, Stanley Lippman, Alistair McClean, John Morar, Dean Pentcheff, V.T. Rajan, John Rehr, Chris Seekamp, Steve Stevenson, Bjarne Stroustrup, Bob Sutor, Dave Tolle, Hank Walker, and robert Wang for their many suggestions. The efforts of all these people spared you the early drafts of the book. Debbie Lafferty, our editor at Addison-Wesley, gently prodded and encour- aged us at each step of the way, carefully balancing between pushing too little and too hard The love of our families--Ava, Rachel samuel and Joel Nackman; Cynthia Butler and John Anthony and Andrew Butler Barton-has been essential. We thank them for their patience and understanding during all those times when working on the book took time away from them CONTENTS Preface PART I Getting Started 1 Chapter i Introduction 3 1. 1 Object-Oriented Programming 4 12WhyC++?5 1. 3 What About 1. 4 Program Design 7 1.5 Organization of the book 8 1.6 Source Code 9 1.7 Contacting the Authors 1. 8 Notes and Comments 10 1.9 Exercis Chapter 2 Basics for FORTRAN Programmers 13 2.1 A First Program 13 2.2 Variables, Objects, and Types 18 2.3 C++ Fundamental Types and Operations 21 2. 4 Input and Output 27 2.5 Operator Precedence and associativity 30 2.6 if Statements 32 2.7 Loops 34 2. 8 Declarate 2.9 Ar 40 2.10 Pointers 43 2.11 Pointers and Arrays 44 2.12 const Pointers and pointers to const Objects 46 2.13 Runtime Array size 47 2.14 Character Strings 50 .15Re 2. 16 Functions 52 2.17 Notes and Comments 61 2.18 Exercises 63 apter 3 Basics for C Programmers 67 3. 1 A First Program 67 3.2 Variables, Objects, and Types 68 3.3 C++ Built-In Types and operations 70 3.4 Operator Precedence and Associativity 71 3.5 Input and Output 71 3.6 Declarations 75 3.7 Pointers 76 3.8 Memory Management 77 3.9 References 78 3.10 Functions 80 3.11 Notes and Comments 83 3.12 Exercises 8 pter 4 Classes 85 4.1 Two Simple classes 85 4.2 An Array class 95 4.3 Class Templates 100 4.4 Function Templates 104 4.5 Exceptions 105 4.6 Nested Classes 110 4.7 Overview of c++ Programs 113 4.8 Notes and Comments 114 4.9 Exercises 116 apter 5 Functions 119 5. 1 Declarations and Definitions 119 5.2 Function Declarations 121 5.3 Function Arguments 124 5.4 Function Return Types 131 5.5 Overloaded Functions 132 5.6 Function Templates 136 Contents 5.7 Notes and Comments 139 5.8 Exercises 140 Chapter Functions and Classes 143 6.1 Member Functions and overloading 143 6.2 Initialization 145 6.3 Copying 148 6.4 Conversion 150 6.5 Operator Functions 159 6.6 Assignment 163 6.7 Special Operators 164 6.8 Destruction 165 6.9 Static Member Functions 166 6.10 friend Functions 167 6.11 Input/Output Operators for Classes 171 6.12 Notes and comments 172 6.13 Exercises 173 Chapter Object Lifetime and memory management 175 7.1 Object Life Cycle 175 7.2 Object Lifetime 176 7.3 Static Objects 178 7.4 Automatic Objects 185 7.5 dynamic Objects 188 7.6 Preventing Dangling References and Garbage 190 7.7 Notes and comments 194 7.8 Exercises 196 Chapter 8 An Example program 199 8.1 The Problem: Representing a Mesh 199 8.2 Solution One: A 202 8.3 Abstraction and Encapsulation 206 8.4 Solution Two: Introducing Classes 208 8.5 Solution Three: Information Hiding 212 8.6 Notes and comments 218 8.7 Exercises 21

...展开详情
试读 127P Scientific and Engineering C++
立即下载 低至0.43元/次 身份认证VIP会员低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
  • 分享精英

关注 私信
上传资源赚钱or赚积分
最新推荐
Scientific and Engineering C++ 43积分/C币 立即下载
1/127
Scientific and Engineering C++第1页
Scientific and Engineering C++第2页
Scientific and Engineering C++第3页
Scientific and Engineering C++第4页
Scientific and Engineering C++第5页
Scientific and Engineering C++第6页
Scientific and Engineering C++第7页
Scientific and Engineering C++第8页
Scientific and Engineering C++第9页
Scientific and Engineering C++第10页
Scientific and Engineering C++第11页
Scientific and Engineering C++第12页
Scientific and Engineering C++第13页
Scientific and Engineering C++第14页
Scientific and Engineering C++第15页
Scientific and Engineering C++第16页
Scientific and Engineering C++第17页
Scientific and Engineering C++第18页
Scientific and Engineering C++第19页
Scientific and Engineering C++第20页

试读结束, 可继续阅读

43积分/C币 立即下载 >