關(guān)于我們
書(shū)單推薦
新書(shū)推薦
|
雙語(yǔ)版C++程序設(shè)計(jì)(第2版)
本書(shū)由在計(jì)算機(jī)程序設(shè)計(jì)方面有著豐富教學(xué)和實(shí)踐經(jīng)驗(yàn)的中外作者合作編寫(xiě)。本書(shū)內(nèi)容共分14章,由淺入深、全面介紹C++程序設(shè)計(jì)方法。本書(shū)通俗易懂,例子貼近生活,尤其強(qiáng)調(diào)讀者的親自參與意識(shí)。所有實(shí)例經(jīng)過(guò)精心挑選。每章都為初學(xué)者提供了常見(jiàn)錯(cuò)誤分析,每章結(jié)尾有很多有趣的習(xí)題,可以提高讀者上機(jī)編程的興趣。本書(shū)是國(guó)內(nèi)首次出版的中英文對(duì)照混排式雙語(yǔ)版C++程序設(shè)計(jì)教材的更新版,既方便初學(xué)者熟悉相關(guān)概念和內(nèi)容,也便于英文非母語(yǔ)的讀者熟悉英文專(zhuān)業(yè)詞匯。
This textbook teaches the fundamentals of programming using C++, a programming language which supports the development of software using the object-oriented paradigm. Although the book is primarily intended as a textbook for a programming module in a computer science course, it is equally suited to an individual familiar with another programming language and who now wants to learn how to program in C++. This book focuses on core concepts and features of C++ while keeping the explanations as simple as possible. Drawing on their professional experience, the authors teach C++ programming largely by way of examples that are organized for easy step-by-step learning. Like so many other programming languages, C++ contains numerous English technical terms that are difficult for all students, including the native English speaking student. Learn C++ through English and Chinese explains C++ concepts and terminology in English with additional explanatory annotations in Chinese. This bi-lingual approach will be appreciated by Chinese students and will help them focus on the C++ language without being over-burdened by English technical terminology. Despite C++ being available on a wide variety of platforms, this book is not specific to any particular machine, compiler, or operating system. All programs are designed to be portable with little or no modification to a wide variety of platforms. Learn C++ through English and Chinese Is a comprehensive introduction to programming in C++. Uses practical examples to explain difficult theoretical examples. Uses a step-by-step approach with detailed explanation of programming examples. Uses explanatory annotations written in Chinese. Provides end-of-chapter ‘programming pitfalls’ commonly experienced by learners. Provides a ‘quick syntax reference’ at the end of each chapter that summarises the C++ syntax covered in the chapter. This is a useful resource for experienced programmers as well as for learners. Provides end-of-chapter exercises, allowing the learner to test and re-enforce their understanding of C++. Is suitable for students new to programming and those familiar with some other language, such as C or Basic, and who now wish to learn C++. Is accompanied by a web site containing the example programs, solutions to selected exercises, frequently asked questions and links to other useful resources. Typographic Conventions The line numbers to the left of the program examples are for reference purposes only and are not part of the C++ language. When a new term is introduced it is in italic type. C++ statements, keywords, program variables and values are in this font. This font is used in examples to show values that should be typed at the keyboard by the user. Paul Kelly Dublin Institute of Technology 前 言 針對(duì)國(guó)內(nèi)大學(xué)逐漸與國(guó)際接軌的發(fā)展趨勢(shì),英語(yǔ)教學(xué)和雙語(yǔ)教學(xué)逐漸被人們重視起來(lái)。一方面,在教育部的大力支持下,許多課程建設(shè)成了教育部雙語(yǔ)教學(xué)示范課程,但是這些課程大多采用英文原版教材,而面向雙語(yǔ)教學(xué)的雙語(yǔ)版教材在國(guó)內(nèi)實(shí)屬罕見(jiàn)。另一方面,以“國(guó)際化、工業(yè)化”為辦學(xué)理念,注重國(guó)際化、工業(yè)化人才培養(yǎng)的國(guó)家示范軟件學(xué)院的部分課程還邀請(qǐng)了一些外籍教師進(jìn)行全英語(yǔ)授課,但是由于目前國(guó)內(nèi)學(xué)生的英語(yǔ)水平參差不齊,導(dǎo)致全英語(yǔ)授課的教學(xué)效果不是非常理想。本書(shū)正是在此背景和需求下應(yīng)運(yùn)而生的。 本書(shū)的第一作者是愛(ài)爾蘭都柏林工業(yè)大學(xué)(DIT)的高級(jí)講師Paul Kelly。Kelly 老師長(zhǎng)期從事程序設(shè)計(jì)類(lèi)課程的教學(xué)工作,在程序設(shè)計(jì)類(lèi)課程教學(xué)方面教學(xué)實(shí)踐經(jīng)驗(yàn)豐富,在國(guó)外已先后出版多本程序設(shè)計(jì)語(yǔ)言類(lèi)書(shū)籍。自哈爾濱工業(yè)大學(xué)軟件示范學(xué)院成立以來(lái),一直作為外聘教師在哈爾濱工業(yè)大學(xué)軟件示范學(xué)院從事程序設(shè)計(jì)方面的教學(xué)工作,對(duì)中國(guó)學(xué)生比較了解,針對(duì)其在教學(xué)中發(fā)現(xiàn)的問(wèn)題,即初學(xué)者面臨著既不熟悉專(zhuān)業(yè)術(shù)語(yǔ)和基本概念、又不熟悉英文專(zhuān)業(yè)詞匯的雙重困難,提出了出版英漢對(duì)照混排式雙語(yǔ)版教材的思路,幫助學(xué)生在克服語(yǔ)言障礙的同時(shí),能夠更快更好地熟悉和掌握計(jì)算機(jī)程序設(shè)計(jì)方面的基礎(chǔ)知識(shí),為國(guó)內(nèi)的雙語(yǔ)教學(xué)提供了一種最佳的解決方案。 本書(shū)內(nèi)容共分14 章,由淺入深、全面介紹C++程序設(shè)計(jì)方法,既適合于以C++作為入門(mén)語(yǔ)言的讀者,也適合于學(xué)習(xí)過(guò)其他程序設(shè)計(jì)語(yǔ)言后想再學(xué)習(xí)C++ 的讀者。本書(shū)的特點(diǎn)如下: 1. 使用非常實(shí)用和貼近生活的例子以及圖示來(lái)通俗易懂地講解難于理解的概念,在介紹面向?qū)ο蟪绦蛟O(shè)計(jì)方法的同時(shí),尤其強(qiáng)調(diào)讀者的親自參與意識(shí)。 2. 采用案例驅(qū)動(dòng)和循序漸進(jìn)方式,從一個(gè)應(yīng)用實(shí)例出發(fā),先利用現(xiàn)有知識(shí)編寫(xiě)出一個(gè)較為簡(jiǎn)單的程序,然后在此基礎(chǔ)上,不斷擴(kuò)充,在擴(kuò)充的過(guò)程中引入一個(gè)新的概念和知識(shí)點(diǎn),逐漸編寫(xiě)出一個(gè)較大的程序,每個(gè)例程都有詳細(xì)的講解。有的章以一個(gè)例子為中心貫穿始終講解,后面章節(jié)的例子還會(huì)重用已有的部分程序代碼,前后章節(jié)之間既有內(nèi)容上的聯(lián)系,也有例程上的聯(lián)系。 3. 重點(diǎn)內(nèi)容和段落給出了中文注解。 4. 每章后面都有一節(jié)介紹初學(xué)者編程時(shí)易犯的錯(cuò)誤,以幫助初學(xué)者在程序設(shè)計(jì)中避免這些錯(cuò)誤。 5. 每章后面都有快速語(yǔ)法索引,總結(jié)本章內(nèi)容,便于讀者快速查詢(xún)相關(guān)內(nèi)容。 6. 每章后面都有精心設(shè)計(jì)的、有趣的習(xí)題,便于讀者測(cè)試和強(qiáng)化對(duì)相關(guān)內(nèi)容的理解。 7. 有相關(guān)的教學(xué)網(wǎng)站(華信教育資源網(wǎng),網(wǎng)址http://www.hxedu.com.cn),方便讀者下載示例的源代碼、部分習(xí)題解答及教學(xué)課件等資料。 本書(shū)由在計(jì)算機(jī)程序設(shè)計(jì)方面有著豐富教學(xué)和實(shí)踐經(jīng)驗(yàn)的中外作者合作編寫(xiě)。本書(shū)是國(guó)內(nèi)首次出版的中英文對(duì)照混排式雙語(yǔ)版教材的更新版,適合低年級(jí)的學(xué)生對(duì)照閱讀,既方便初學(xué)者熟悉相關(guān)概念和內(nèi)容,也便于母語(yǔ)不是英語(yǔ)的讀者熟悉英文的專(zhuān)業(yè)詞匯,尤其適合作為雙語(yǔ)教學(xué)示范課程的教材。 Paul Kelly是一位治學(xué)非常嚴(yán)謹(jǐn)?shù)慕處,本?shū)的第二作者蘇小紅在與他合著過(guò)程中,經(jīng)常為一個(gè)細(xì)節(jié)內(nèi)容的編寫(xiě)進(jìn)行反復(fù)交流與討論,書(shū)稿完成后又進(jìn)行了多次校對(duì)工
Paul Kelly,愛(ài)爾蘭都柏林工業(yè)大學(xué)(DIT)的高級(jí)講師Paul Kelly。Kelly 老師長(zhǎng)期從事程序設(shè)計(jì)類(lèi)課程的教學(xué)工作,在程序設(shè)計(jì)類(lèi)課程教學(xué)方面教學(xué)實(shí)踐經(jīng)驗(yàn)豐富,在國(guó)外已先后出版多本程序設(shè)計(jì)語(yǔ)言類(lèi)書(shū)籍。蘇小紅,哈爾濱工業(yè)大學(xué)計(jì)算機(jī)學(xué)院博士生導(dǎo)師,計(jì)算機(jī)應(yīng)用技術(shù)專(zhuān)家,研究領(lǐng)域主要是色彩匹配,信息融合,空間計(jì)算,人工神經(jīng)網(wǎng)絡(luò),進(jìn)化算法,計(jì)算機(jī)圖形學(xué),灰色預(yù)測(cè),彩色圖像處理等。
Chapter One Typographic Conventions(緒論) 1
1.1 What is a computer program (什么是計(jì)算機(jī)程序 ) 1 1.2 Developing a computer program(開(kāi)發(fā)計(jì)算機(jī)程序) 2 1.2.1 Program development cycle 2 1.3 Learning C++(學(xué)習(xí) C++) 4 1.4 Web site for this book(本書(shū)的網(wǎng)站) 4 1.5 Brief history of C++(C++簡(jiǎn)史) 4 1.6 ANSI/ISO C++ standard(ANSI/ISO C++標(biāo)準(zhǔn)) 5 Chapter Two Beginning to Program in C++(C++編程入門(mén)) 6 2.1 Constants(常量) 6 2.2 Variables(變量) 6 2.3 Simple output to the screen(簡(jiǎn)單的屏幕輸出) 7 2.4 Comments(注釋?zhuān)?9 2.5 Data types(數(shù)據(jù)類(lèi)型) 10 2.5.1 Short integer data types 10 2.5.2 Long integer data types 10 2.5.3 Boolean data types 11 2.5.4 Double floating-point data types 11 2.5.5 Unsigned integer data types 11 2.6 Data type sizes(數(shù)據(jù)類(lèi)型的大。 11 2.7 Operators (運(yùn)算符) 12 2.7.1 The assignment operator 12 2.7.2 Arithmetic operators 12 2.7.3 Increment and decrement operators 13 2.7.4 Combined assignment operators 15 2.8 Operator precedence(運(yùn)算符的優(yōu)先級(jí)) 16 2.9 Data type conversions and casts(類(lèi)型轉(zhuǎn)換和強(qiáng)轉(zhuǎn)) 18 Programming pitfalls 20 Quick syntax reference 21 Exercises 22 Chapter Three Keyboard Input and Screen Output(鍵盤(pán)輸入和屏幕輸出) 26 3.1 Simple keyboard input(簡(jiǎn)單的鍵盤(pán)輸入) 26 3.2 Manipulators(流操縱符) 28 3.3 Single-character input and output(單個(gè)字符的輸入和輸出) 30 Programming pitfalls 32 Quick syntax reference 32 Exercises 32 Chapter Four Selection and Iteration(選擇與循環(huán)) 34 4.1 Selection(選擇) 34 4.1.1 The if statement 34 4.1.2 The if-else statement 35 4.1.3 Compound statements 35 4.1.4 Logical operators 37 4.1.5 Nested if statements 37 4.1.6 The switch statement 37 4.1.7 The conditional operator : 39 4.2 Iteration(循環(huán)) 40 4.2.1 The while statement 40 4.2.2 The do-while loop 42 4.2.3 The for statement 43 4.2.4 Nested loops 45 Programming pitfalls 47 Quick syntax reference 49 Exercises 50 Chapter Five Arrays and Structures(數(shù)組和結(jié)構(gòu)體) 53 5.1 Arrays(數(shù)組) 53 5.1.1 Introduction 53 5.1.2 Initialising an array 56 5.1.3 Two-dimensional arrays 57 5.1.4 Initialising a two-dimensional array 59 5.1.5 Multi-dimensional arrays 60 5.2 Structures(結(jié)構(gòu)體) 60 5.2.1 Introduction 60 5.2.2 Declaring a structure 61 5.2.3 Initialising a structure variable 63 5.2.4 Nested structures 64 5.3 The typedef statement(typedef 語(yǔ)句) 65 5.4 Arrays of structures(結(jié)構(gòu)體數(shù)組) 66 5.5 Enumerated data types(枚舉數(shù)據(jù)類(lèi)型) 66 Programming pitfalls 68 Quick syntax reference 68 Exercises 69 Chapter Six Strings(字符串) 72 6.1 C-strings(C 風(fēng)格字符串) 72 6.2 C-string input and output(C 風(fēng)格字符串的輸入和輸出) 73 6.3 Accessing individual characters of a C-string(訪問(wèn)C 風(fēng)格字符串中的單個(gè)字符) 77 6.4 C-string functions(C 風(fēng)格字符串函數(shù)) 77 6.4.1 Finding the length of a C-string 78 6.4.2 Copying a C-string 78 6.4.3 C-string concatenation 79 6.4.4 Comparing C-strings 79 6.4.5 Other C-string functions 79 6.4.6 Converting numeric C-strings to numbers 80 6.5 C++ strings(C++ 字符串) 80 6.5.1 string initialisation and assignment 82 6.5.2 string concatenation 84 6.5.3 string length, string indexing and sub-strings 85 6.5.4 string replace, erase, insert and empty strings 86 6.5.5 string searching 88 6.5.6 string comparisons 89 6.5.7 string input 91 6.5.8 string conversions 92 6.6 Arrays of strings(string 類(lèi)型的數(shù)組) 93 6.7 Character classification(字符分類(lèi)) 94 Programming pitfalls 96 Quick syntax reference 96 Exercises 97 Chapter Seven Functions(函數(shù)) 100 7.1 Introduction(引言) 100 7.2 Function arguments(函數(shù)實(shí)參) 102 7.3 Default parameter values(默認(rèn)的形參值) 105 7.4 Returning a value from a function(從函數(shù)返回一個(gè)值) 106 7.5 Inline functions(內(nèi)聯(lián)函數(shù)) 107 7.6 Passing arguments by value(按值傳遞實(shí)參) 108 7.7 Passing arguments by reference(按引用傳遞實(shí)參) 109 7.8 Passing a one-dimensional array to a function(向函數(shù)傳遞一維數(shù)組) 112 7.9 Passing a multi-dimensional array to a function(向函數(shù)傳遞多維數(shù)組) 115 7.10 Passing a structure variable to a function(向函數(shù)傳遞結(jié)構(gòu)體變量) 116 7.11 Passing a string to function(向函數(shù)傳遞字符串) 118 7.11.1 Passing a C++ string to a function 118 7.11.2 Passing a C-string to a function 119 7.12 Recursion(遞歸) 120 7.13 Function overloading(函數(shù)重載) 122 7.14 Storage classes auto and static (auto 和static 存儲(chǔ)類(lèi)型) 123 7.14.1 auto 123 7.14.2 static 124 7.15 The scope of a variable(變量的作用域) 125 7.15.1 Block scope 125 7.15.2 Global scope 126 7.15.3 Reusing a variable name 127 7.16 Mathematical functions(數(shù)學(xué)函數(shù)) 129 7.16.1 Some trigonometric functions 129 7.16.2 Pseudo-random number functions 130 Programming pitfalls 132 Quick syntax reference 132 Exercises 133 Chapter Eight Objects and Classes(對(duì)象和類(lèi)) 137 8.1 What is an object (什么是對(duì)象 ) 137 8.2 What is a class (什么是類(lèi) ) 137 8.3 Further examples of classes and objects(類(lèi)和對(duì)象的更進(jìn)一步的示例) 140 8.3.1 A student class 140 8.3.2 A bank account class 140 8.4 Abstraction(抽象) 141 8.5 Constructing a class in C++(用C++構(gòu)造一個(gè)類(lèi)) 142 8.6 Using a class: defining and using objects(使用類(lèi):定義和使用對(duì)象) 144 8.7 Abstract data types(抽象數(shù)據(jù)類(lèi)型) 145 8.8 Constructors(構(gòu)造函數(shù)) 146 8.9 Default class constructor(默認(rèn)的類(lèi)構(gòu)造函數(shù)) 148 8.10 Overloading class constructors(重載類(lèi)構(gòu)造函數(shù)) 149 8.11 Constructor initialisation lists(構(gòu)造函數(shù)初始化列表) 151 8.12 Default argument values in a constructor(構(gòu)造函數(shù)中的默認(rèn)實(shí)參值) 152 8.13 static class data members(靜態(tài)類(lèi)數(shù)據(jù)成員) 154 8.14 Using return in a member function(在成員函數(shù)中使用return) 157 8.15 Inline class member functions(內(nèi)聯(lián)成員函數(shù)) 159 8.16 Class interface and class implementation(類(lèi)的接口和類(lèi)的實(shí)現(xiàn)) 160 8.16.1 Separation of class interface and class implementation 162 8.16.2 Use of namespaces in header files 164 Programming pitfalls 167 Quick syntax reference 167 Exercises 167 Chapter Nine Pointers and Dynamic Memory(指針和動(dòng)態(tài)內(nèi)存分配) 171 9.1 Variable addresses(變量的地址) 171 9.2 Pointer variables(指針變量) 172 9.3 The dereference operator *(解引用運(yùn)算符*) 173 9.4 Using const with pointers(使用const 修飾指針變量) 174 9.5 Pointers and one-dimensional arrays(指針和一維數(shù)組) 175 9.6 Pointers and multi-dimensional arrays(指針和多維數(shù)組) 177 9.7 Pointers to structures(指向結(jié)構(gòu)體的指針) 178 9.8 Pointers to class objects(指向類(lèi)對(duì)象的指針) 179 9.9 Pointers as function arguments(指針變量作為函數(shù)實(shí)參) 180 9.10 Dynamic memory allocation(動(dòng)態(tài)內(nèi)存分配) 182 9.10.1 Allocating memory dynamically for an array 183 9.10.2 Initialisation with new 184 9.10.3 Allocating memory for multi-dimensional arrays 186 9.10.4 Out of memory error 187 Programming pitfalls 189 Quick syntax reference 190 Exercises 190 Chapter Ten Operator Overloading(運(yùn)算符重載) 193 10.1 The need for operator overloading(運(yùn)算符重載的必要性) 193 10.2 Overloading the addition operator +(重載加法運(yùn)算符+) 193 10.3 Rules of operator overloading(運(yùn)算符重載的規(guī)則) 200 10.4 Overloading ++(重載運(yùn)算符++) 200 10.4.1 Overloading prefix and postfix forms of ++ 203 10.4.2 Improving the prefix ++ operator member function 206 10.5 Overloading relational operators(重載關(guān)系運(yùn)算符) 206 10.6 Overloading << and >> (重載運(yùn)算符<<和>>) 209 10.7 Conversion operators(轉(zhuǎn)換運(yùn)算符) 214 10.8 Use of friend functions(使用友元函數(shù)) 217 10.9 Overloading the assignment operator =(重載賦值運(yùn)算符=) 218 10.9.1 A class with a pointer data member 218 10.9.2 Assigning one object to another 220 10.10 The copy constructor(拷貝構(gòu)造函數(shù)) 229 10.11 Overloading the index operator [](重載下標(biāo)運(yùn)算符[ ]) 233 Programming pitfalls 236 Quick syntax reference 237 Exercises 237 Chapter Eleven Inheritance(繼承) 240 11.1 What is inheritance (什么是繼承 ) 240 11.2 Inheritance syntax(繼承語(yǔ)法) 241 11.3 Passing arguments to a base class constructor(向基類(lèi)的構(gòu)造函數(shù)傳遞實(shí)參) 249 11.4 Protected class members(受保護(hù)的類(lèi)成員) 253 11.5 Types of inheritance: public, protected and private(繼承的類(lèi)型:public、 protected和private) 256 11.6 Composition(組合) 258 11.7 Multiple inheritance(多重繼承) 259 11.8 Virtual base classes(虛基類(lèi)) 262 Programming pitfalls 265 Quick syntax reference 265 Exercises 266 Chapter Twelve Polymorphism(多態(tài)) 271 12.1 What is polymorphism (什么是多態(tài) ) 271 12.2 Virtual functions(虛函數(shù)) 274 12.2.1 When to use virtual functions 279 12.2.2 Overriding and overloading 279 12.3 Abstract base classes(抽象基類(lèi)) 280 Programming pitfalls 284 Quick syntax reference 284 Exercises 285 Chapter Thirteen Templates(模板) 288 13.1 Introduction(引言) 288 13.2 Function templates(函數(shù)模板) 288 13.3 Class templates(類(lèi)模板) 292 Programming pitfalls 297 Quick syntax reference 297 Exercises 297 Chapter Fourteen Files and Streams(文件和流) 300 14.1 The C++ input/output class hierarchy(C++ 輸入/ 輸出類(lèi)的層次結(jié)構(gòu)) 300 14.2 Opening a file(打開(kāi)文件) 301 14.3 File error checking(文件出錯(cuò)檢查) 303 14.4 Single character I/O and detecting the end of a file(單字符的I/O 和文件末尾 的檢測(cè)) 304 14.5 Appending data to the end of a file(向文件末尾添加數(shù)據(jù)) 308 14.6 Reading lines from a file(從文件中讀取行) 309 14.7 Random access(隨機(jī)存。 310 14.8 Object I/O(對(duì)象I/O) 313 14.9 Binary I/O(二進(jìn)制I/O) 314 14.9.1 Serial writing of objects to a binary file 315 14.9.2 Serial reading of objects from a binary file 319 14.9.3 Binary I/O as class member functions 320 14.9.4 Binary file random access 321 Programming pitfalls 325 Quick syntax reference 325 Exercises 326 Appendix A List of C++ Keywords 329 Appendix B Precedence and Associativity of C++ Operators 330 Appendix C ASCII Character Codes 332 Appendix D Fundamental C++ Built-in Data Types 334 Appendix E Common iomanip Manipulators 335 Appendix F Escape Sequences 336 Appendix G The C++ Preprocessor 337
你還可能感興趣
我要評(píng)論
|