Beginning Programming with C++ For Dummies - Stephen R. Davis - E-Book

Beginning Programming with C++ For Dummies E-Book

Stephen R. Davis

0,0
22,99 €

oder
-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Learn to program with C++ quickly with this helpful For Dummies guide Beginning Programming with C++ For Dummies, 2nd Edition gives you plain-English explanations of the fundamental principles of C++, arming you with the skills and know-how to expertly use one of the world's most popular programming languages. You'll explore what goes into creating a program, how to put the pieces together, learn how to deal with standard programming challenges, and much more. Written by the bestselling author of C++ For Dummies, this updated guide explores the basic development concepts and techniques of C++ from a beginner's point of view, and helps make sense of the how and why of C++ programming from the ground up. Beginning with an introduction to how programming languages function, the book goes on to explore how to work with integer expressions and character expressions, keep errors out of your code, use loops and functions, divide your code into modules, and become a functional programmer. * Grasp C++ programming like a pro, even if you've never written a line of code * Master basic development concepts and techniques in C++ * Get rid of bugs and write programs that work * Find all the code from the book and an updated C++ compiler on the companion website If you're a student or first-time programmer looking to master this object-oriented programming language, Beginning Programming with C++ For Dummies, 2nd Edition has you covered.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 504

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Beginning Programming with C++ For Dummies®, 2nd Edition

Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com

Copyright © 2015 by John Wiley & Sons, Inc., Hoboken, New Jersey

Media and software compilation copyright © 2015 by John Wiley & Sons, Inc. All rights reserved.

Published simultaneously in Canada

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.

For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit www.wiley.com/techsupport.

Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com. For more information about Wiley products, visit www.wiley.com.

Library of Congress Control Number: 2014937186

ISBN 978-1-118-82387-3 (pbk); ISBN 978-1-118-82389-7 (ebk); ISBN 978-1-118-82393-4 (ebk)

Manufactured in the United States of America

10 9 8 7 6 5 4 3 2 1

Beginning Programming with C++ For Dummies®, 2nd Edition

Visit www.dummies.com/cheatsheet/beginningprogrammingcplusplus to view this book's cheat sheet.

Table of Contents

Introduction

About This Book

Foolish Assumptions

How This Book Is Organized

Part I: Getting Started with C++ Programming

Part II: Writing a Program: Decisions, Decisions

Part III: Becoming a Procedural Programmer

Part IV: Data Structures

Part V: Object-Oriented Programming

Part VI: Advanced Strokes

Part VII: The Part of Tens

Icons Used in This Book

Beyond the Book

Where to Go from Here

Part I: Getting Started with C++ Programming

Chapter 1: What Is a Program?

How Does My Son Differ from a Computer?

Programming a “Human Computer”

Creating the algorithm

Setting the tire-changing language

Constructing the program

Computer processors

Computer Languages

High-level languages

The C++ language

Chapter 2: Installing Code::Blocks

Reviewing the Compilation Process

Installing Code::Blocks

Windows installation

Ubuntu Linux installation

Mac OS installation

Setting up Code::Blocks

Testing the Code::Blocks Installation

Creating the project

Testing your default project

Chapter 3: Writing Your First Program

Creating a New Project

Filename extensions

Entering Your Program

Building the Program

Finding What Could Go Wrong

Misspelled commands

Missing semicolon

Using the Online Material

Running the Program

How the Program Works

The template

The Conversion program

Part II: Writing a Program: Decisions, Decisions

Chapter 4: Integer Expressions

Declaring Variables

Variable names

Assigning a value to a variable

Initializing a variable at declaration

Integer Constants

Expressions

Binary operators

Unraveling compound expressions

Unary Operators

The Special Assignment Operators

Chapter 5: Character Expressions

Defining Character Variables

Encoding characters

Example of character encoding

Encoding Strings of Characters

Special Character Constants

Chapter 6: if I Could Make My Own Decisions

The if Statement

Comparison operators

Say “No” to “No braces”

What Else Is There?

Nesting if Statements

Compound Conditional Expressions

Chapter 7: Switching Paths

Controlling Flow with the switch Statement

Control Fell Through: Did I break It?

Implementing an Example Calculator with the switch Statement

Chapter 8: Debugging Your Programs, Part I

Identifying Types of Errors

Avoiding Introducing Errors

Coding with style

Establishing variable naming conventions

Finding the First Error with a Little Help

Finding the Run-Time Error

Formulating test data

Executing the test cases

Seeing what’s going on in your program

Part III: Becoming a Procedural Programmer

Chapter 9: while Running in Circles

Creating a while Loop

Breaking out of the Middle of a Loop

Nested Loops

Chapter 10: Looping for the Fun of It

The for Parts of Every Loop

Looking at an Example

Getting More Done with the Comma Operator

Chapter 11: Functions, I Declare!

Breaking Your Problem Down into Functions

Understanding How Functions Are Useful

Writing and Using a Function

Returning things

Reviewing an example

Passing Arguments to Functions

Function with arguments

Functions with multiple arguments

Exposing main()

Defining Function Prototype Declarations

Chapter 12: Dividing Programs into Modules

Breaking Programs Apart

Breaking Up Isn’t That Hard to Do

Creating Factorial.cpp

Creating an #include file

Including #include files

Creating main.cpp

Building the result

Using the Standard C++ Library

Variable Scope

Chapter 13: Debugging Your Programs, Part 2

Debugging a Dys-Functional Program

Performing unit level testing

Outfitting a function for testing

Returning to unit test

Part IV: Data Structures

Chapter 14: Other Numerical Variable Types

The Limitations of Integers in C++

Integer round-off

Limited range

A Type That “doubles” as a Real Number

Solving the truncation problem

When an integer is not an integer

Discovering the limits of double

Variable Size — the “long” and “short” of It

How far do numbers range?

Types of Constants

Passing Different Types to Functions

Overloading function names

Mixed-mode overloading

Chapter 15: Arrays

What Is an Array?

Declaring an Array

Indexing into an Array

Looking at an Example

Initializing an Array

Chapter 16: Arrays with Character

The ASCII-Zero Character Array

Declaring and Initializing an ASCIIZ Array

Looking at an Example

Looking at a More Detailed Example

Foiling hackers

Do I Really Have to Do All That Work?

Chapter 17: Pointing the Way to C++ Pointers

What’s a Pointer?

Declaring a Pointer

Passing Arguments to a Function

Passing arguments by value

Passing arguments by reference

Putting it together

Reference argument types

Playing with Heaps of Memory

Do you really need a new keyword?

Don’t forget to clean up after yourself

Looking at an example

Chapter 18: Taking a Second Look at C++ Pointers

Pointers and Arrays

Operations on pointers

Pointer addition versus indexing into an array

Using the pointer increment operator

Why bother with array pointers?

Operations on Different Pointer Types

Constant Nags

Differences Between Pointers and Arrays

My main() Arguments

Arrays of pointers

Arrays of arguments

Chapter 19: Programming with Class

Grouping Data

The Class

The Object

Arrays of Objects

Looking at an Example

Chapter 20: Debugging Your Programs, Part 3

A New Approach to Debugging

The solution

Entomology for Dummies

Starting the debugger

Fixing the (first) bug

Finding and fixing the second bug

Part V: Object-Oriented Programming

Chapter 21: What Is Object-Oriented Programming?

Abstraction and Microwave Ovens

Procedural nachos

Object-oriented nachos

Classification and Microwave Ovens

Why Build Objects This Way?

Self-Contained Classes

Chapter 22: Structured Play: Making Classes Do Things

Activating Our Objects

Creating a Member Function

Defining a member function

Naming class members

Calling a member function

Accessing other members from within a member function

Keeping a Member Function after Class

Overloading Member Functions

Chapter 23: Pointers to Objects

Pointers to Objects

Arrow syntax

Calling all member functions

Passing Objects to Functions

Calling a function with an object value

Calling a function with an object pointer

Looking at an example

Allocating Objects off the Heap

Chapter 24: Do Not Disturb: Protected Members

Protecting Members

Why you need protected members

Making members protected

So what?

Who Needs Friends, Anyway?

Chapter 25: Getting Objects Off to a Good Start

The Constructor

Limitations on constructors

Can I see an example?

Constructing data members

Destructors

Looking at an example

Destructing data members

Chapter 26: Making Constructive Arguments

Constructors with Arguments

Looking at an example

Overloading the Constructor

The Default default Constructor

Constructing Data Members

Initializing data members with the default constructor

Initializing data members with a different constructor

Looking at an example

New with C++ 2011

Chapter 27: Coping with the Copy Constructor

Copying an Object

The default copy constructor

Looking at an example

Creating a Copy Constructor

Avoiding Copies

Part VI: Advanced Strokes

Chapter 28: Inheriting a Class

Advantages of Inheritance

Learning the lingo

Implementing Inheritance in C++

Looking at an example

Having a HAS_A Relationship

Chapter 29: Are Virtual Functions for Real?

Overriding Member Functions

Early binding

Ambiguous case

Enter late binding

When Is Virtual Not?

Virtual Considerations

Chapter 30: Overloading Assignment Operators

Overloading an Operator

Overloading the Assignment Operator Is Critical

Looking at an Example

Writing Your Own (or Not)

Chapter 31: Performing Streaming I/O

How Stream I/O Works

Stream Input/Output

Creating an input object

Creating an output object

Open modes

What is binary mode?

Hey, file, what state are you in?

Other Member Functions of the fstream Classes

Reading and writing streams directly

Controlling format

What’s up with endl?

Manipulating Manipulators

Using the stringstream Classes

Chapter 32: I Take Exception!

The Exception Mechanism

Examining the exception mechanism in detail

Special considerations for throwing

Creating a Custom Exception Class

Restrictions on exception classes

Part VII: The Part of Tens

Chapter 33: Ten Ways to Avoid Bugs

Enable All Warnings and Error Messages

Adopt a Clear and Consistent Coding Style

Comment the Code While You Write It

Single-Step Every Path in the Debugger at Least Once

Limit the Visibility

Keep Track of Heap Memory

Zero Out Pointers after Deleting What They Point To

Use Exceptions to Handle Errors

Declare Destructors Virtual

Provide a Copy Constructor and Overloaded Assignment Operator

Chapter 34: Ten Features Not Covered in This Book

The goto Command

The Ternary Operator

Binary Logic

Enumerated Types

Namespaces

Pure Virtual Functions

The string Class

Multiple Inheritance

Templates and the Standard Template Library

Lambda Functions

About the Author

Cheat Sheet

Guide

Table of Contents

Begin Reading

Pages

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

55

56

57

58

59

60

61

62

63

64

65

66

67

69

70

71

72

73

74

75

76

77

79

80

81

82

83

84

85

86

87

88

89

90

91

93

94

95

96

97

98

99

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

181

182

183

184

185

186

187

188

189

190

191

192

193

194

199

195

196

197

198

200

201

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

445

446

Introduction

Welcome to Beginning Programming with C++ For Dummies, Second Edition. This book is intended for the reader who wants to learn to program.

Somehow over the years, programming has become associated with mathematics and logic calculus and other complicated things. I never quite understood that. Programming is a skill like writing advertising or drawing or photography. It does require the ability to think a problem through, but I’ve known some really good programmers who had zero math skills. Some people are naturally good at it and pick it up quickly, others not so good and not so quick. Nevertheless, anyone with enough patience and “stick-to-itiveness” can learn to program a computer. Even me.

About This Book

Learning to program necessarily means learning a programming language. This book is based upon the C++ programming language. Versions of the suggested compiler for Windows and Macintosh are included with the online materials accompanying this book. Linux versions are available for download at www.codeblocks.org. (Don’t worry: I include step-by-step instructions for installing the package and building your first program in the book.)

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!