ebook img

The Book of Bytes for Neophytes: A Guide to C++ PDF

206 Pages·2017·3.093 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview The Book of Bytes for Neophytes: A Guide to C++

The Book of Bytes for Neophytes: A Guide to C++ by A.S. Giedraitis Copyright © 2018 A.S. Giedraitis FIRST EDITION: 2018 All rights reserved. This book or parts thereof may not be reproduced in any form, stored in any retrieval system, or transmitted in any form by any means—electronic, mechanical, photocopy, recording, or otherwise—without prior written permission of the publisher, except as provided by the United States of America copyright law, or for the inclusion of brief quotations in a review. ISBN: 978-0-692-93367-1 (eBook edition) Published by Ziz Studios [email protected] Warning and Disclaimer This book is designed to provide information about learning how to program using the C++ programming language. Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information is provided on an as-is basis. The author and Ziz Studios shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained within this book. Permissions Permission to use screenshots of and references to the Code::Blocks compiler granted by Yiannis Mandravellos of the Code::Blocks Team. Code::Blocks. Version 16.01. The Code::Blocks Team. 2016. Windows is a registered trademark of Microsoft. The Win32 API and its features are property of Microsoft. All uses within the code and references of the API and its features in this book are made in accordance with the GNU Lesser General Public License. Permission to use information on frequencies of notes granted by B.H. Suits, Physics Department of Michigan Technological University. Suits, B. H. "Frequencies for Equal- tempered Scale, A4 = 440 Hz." Frequencies of Musical Notes, A4 = 440 Hz. Michigan Technological University, 2015. Web. 2017. Credits Illustrations, cover and book design by A.S. Giedraitis Editing by A.S. Giedraitis Visit the author’s website at asgiedraitis.com This book is dedicated to my mentors, family, all those who believe in me, and you, the reader. You have all driven me to help others find what drives them in life. This work is a token of my thanks. Thank you. Table of Contents Introduction ........................................................................................................... 1 Section 1: Libraries ...................................................................................... 13 Putting libraries in programs ........................................................................................ 15 Section Summary .......................................................................................................... 15 Section 2: Types, Objects, Variables & Operators ...... 16 Analogies ....................................................................................................................... 17 Additional Operators ...................................................................................................... 19 Varieties of types for Variables ..................................................................................... 20 When to Declare Objects ............................................................................................... 20 Section Summary .......................................................................................................... 21 Section 3: Input/Output .......................................................................... 22 Outputting data .............................................................................................................. 23 Inputting data ................................................................................................................ 25 Inputting/Outputting Data to File .................................................................................. 25 Tutorial One .................................................................................................................... 27 Tutorial Two ................................................................................................................... 27 Challenges ..................................................................................................................... 28 Section Summary .......................................................................................................... 28 Section 4: Strings/Characters ......................................................... 29 Understanding Characters ............................................................................................ 30 Understanding Strings .................................................................................................. 30 Declaring Characters ..................................................................................................... 30 Declaring Strings ........................................................................................................... 31 String Indexing ............................................................................................................... 31 String Length ................................................................................................................. 32 Observing Single Characters in Strings ........................................................................ 33 Observing Substrings .................................................................................................... 33 Comparing Strings ......................................................................................................... 34 Tutorial One .................................................................................................................... 34 Tutorial Two ................................................................................................................... 35 Challenges ..................................................................................................................... 36 Section Summary .......................................................................................................... 36 Section 5: If-Then Statements ......................................................... 37 Analogies ....................................................................................................................... 38 Comparisons .................................................................................................................. 38 Multiple comparisons .................................................................................................... 40 Switch-Case-Break Comparisons .................................................................................. 40 Relating If-Then Statements ......................................................................................... 41 Tutorial One .................................................................................................................... 42 Tutorial Two ................................................................................................................... 44 Challenges ..................................................................................................................... 45 Section Summary .......................................................................................................... 45 Section 6: Math Functions .................................................................. 46 Trigonometry Functions ................................................................................................ 47 Rounding Functions ...................................................................................................... 48 Power Functions ............................................................................................................ 48 Randomization Function ............................................................................................... 49 Tutorial One .................................................................................................................... 50 Tutorial Two ................................................................................................................... 51 Challenges ..................................................................................................................... 52 Section Summary .......................................................................................................... 52 Section 7: For-Loops & While-Loops ......................................... 53 Understanding loops ..................................................................................................... 54 For-Loops ....................................................................................................................... 54 While-Loops ................................................................................................................... 55 Nested For-Loops .......................................................................................................... 56 Nested While-Loops ....................................................................................................... 57 Tutorial One .................................................................................................................... 58 Tutorial Two ................................................................................................................... 59 Challenges ..................................................................................................................... 60 Section Summary .......................................................................................................... 60 Section 8: Arrays ............................................................................................ 61 Understanding Arrays .................................................................................................... 62 Types of Arrays .............................................................................................................. 64 Reading Arrays .............................................................................................................. 65 Writing to Arrays ............................................................................................................ 66 Tutorial One .................................................................................................................... 70 Tutorial Two ................................................................................................................... 71 Challenges ..................................................................................................................... 73 Section Summary .......................................................................................................... 73 Section 9: Functions .................................................................................. 74 Understanding Functions .............................................................................................. 75 Different Kinds of Functions: ........................................................................................ 75 Declaring Functions....................................................................................................... 75 Using Functions ............................................................................................................. 76 Declaring Void Functions .............................................................................................. 77 Using Void Functions .................................................................................................... 77 Calling Functions ........................................................................................................... 78 Calling Void Functions .................................................................................................. 78 Tutorial One .................................................................................................................... 79 Tutorial Two ................................................................................................................... 81 Challenges ..................................................................................................................... 83 Section Summary .......................................................................................................... 83 Section 10: Graphics & Sound ......................................................... 84 Enabling Graphics Manipulation ................................................................................... 85 Color ............................................................................................................................... 86 Animation ....................................................................................................................... 86 Sound ............................................................................................................................. 88 Animation Tips ............................................................................................................... 88 Sound Tips ..................................................................................................................... 91 Tutorial One .................................................................................................................... 92 Tutorial Two ................................................................................................................... 97 Challenges ..................................................................................................................... 99 Section Summary .......................................................................................................... 99 Section 11: Keyboard Functionality ........................................ 100 Working with Keyboard Press Registering ................................................................. 101 Tutorial One .................................................................................................................. 102 Challenges ................................................................................................................... 108 Section Summary ........................................................................................................ 108 Conclusion .......................................................................................................... 109 Index .......................................................................................................................... 194 Troubleshooting ............................................................................................ 111 Challenge Help ................................................................................................ 132 References .......................................................................................................... 180 Introduction Introduction o r t n I 2 Co ngratulations for making the first step into this book. By having taken the time to open to this page, a vast new realm awaits you: the realm of C++ programming. This book is going to lead you step-by-step in learning to harness the power of using the C++ programming language and how to develop a strong set of foundations for working with it. If you, the reader, happen to be someone who had an interest in C++ but only delved into it shortly and have not worked with it until now, welcome back. If you happen to be a first-time learner of C++, it is a pleasure to help set you on the right path to learning it. This book is in no way meant to be a heap of text to cram into your mind; it is a book specifically designed to walk you through, make things clear, answer questions, solve problems, and most importantly, enjoy your time learning. That is the ultimate goal for every page in this book: to allow you to enjoy yourself while learning C++. To make this possible, this book has been divided up into different sections that build upon each other. Every section will cover a topic involved in C++, give two tutorial programs to try, and two challenge programs which can be attempted on your own but still be understood with helpful answers found in the back of the book. Each section also has its own part of a troubleshooting section in which some issues that may be faced while making programs in the respective section are encountered. It should be noted that the pages for answers to the challenges should serve as examples of how the challenges could be done; you may have a completely different way of doing it, and the challenge answers are for help and inspiration. It should also be mentioned that the troubleshooting section will not always have the solution to the error you encounter; the errors described have common solutions provided, but a good programmer always problem solves to the best of their ability on their own before looking for outside help. Every section will also have troubleshooting pages to refer to at the back should you ever get stuck with particular issues in the programs you will be making. Before we get started together in this book, it is best to go over some terms which will make you familiar with programming in C++. Here is a visual which will also be important to understand with the terms:

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.