C++ PROGRAMMING
After work guide to master C++ on your own. Build your coding skills and learn how to solve
common problems. Transform your passion in a possible job career as a computer programmer.
Michail Klling
Contents
Introduction
Welcome to the wonderful world of programming, the chapters contained in this book will give you a basic understanding of programming in C++. By its final chapter, you will be able to create a complete program on your own, using C++.
This guide is aimed at newcomers to C++. If, however, you are entirely new to programming, I recommend first reading our primer to programming. It covers all the concepts, terms, programming paradigms, and coding techniques that a complete novice needs to know.
This guidebook is going to take some time to look over all of the things that we can do with the C++ language, and how beneficial learning this language can be.
This object-oriented programming course in C++ language presents learners with the concepts and techniques necessary to design, develop and implement a robust program model effectively. As a learner, you will be able to grasp practical knowledge on how to apply the fundamental concepts of object-oriented analysis and design and solve various problems in your day to day activities.
C++ is a computer programming language widely used for general-purpose programming. It is an extension of C-language. The basic understanding of C++ can be acquired from C. Thats why both computer languages are represented as C/C++. Bjarne Stroustrup developed this multi-paradigm language in 1979.
In todays world, many operating systems use C++ as their basic language. Some system drivers, browsers, and games are based on C++ programs. It is a free form, compiled, and statically typed programming language. Many professionals believe that C++ is the most efficient language to achieve the desired results.
Learning code is ultimately the language of the future. We have all heard something close to that at some point in our lives.
By the time you reach the end, you should have no problem reading C++ code and writing programs that are both interesting and useful. So, lets dive in and learn C++.
Chapter 1: Anatomy of C++
Introduction to programming languages
As you already know, the program is nothing but a set of instructions. These instructions are executed by the hardware, which is the physical computer machinery. Though modern computers are fast, they have their limitations. Computers can only understand a set of instructions given in their native language. For this, you should understand the concepts of machine language, assembly language, and high-level languages.
Machine language
Though computers are very advanced machines, they cannot understand languages like C++ directly. A computer only understands 0s and 1s. They are called bits. And they can only understand instructions given in the binary format. Every set of instructions that we give to sleep you are translated into a set of instructions that tell the processor to do a particular job. You should understand that different types of processors have different types of instruction sets. For example, the Pentium processors will only understand their instructions set. It is a similar case with Macintosh. In the very beginning, programmers had to write their instructions in the binary language. It was very time-consuming and challenging. Luckily, we don't have to go through all of that.
Assembly language
As the machine language is tough to deal with, a new language called the assembly language was invented. Here every instruction is given a short name, and the variables are replaced by names and not by binary digits, making it easy for a programmer to write code. You may ask how you can understand and assembly language. It cannot. The assembly language will be converted into machine language with the help of an assembler. You should remember that each CPU has its assembly language. So, the assembly language of a CPU cannot be run on a different CPU. Even assembly language has got its drawbacks. They require large sets of instructions, even for simple tasks.
High-level language
The high-level programming languages came into existence to solve those problems that the assembly and machine languages were causing. These can run on any computer. High-level languages come with A program called a compiler. The role of a compiler is to generate an executable file or a program that a CPU can directly understand. These programs are standalone programs. The modern compilers that are available today are very efficient and fast and converting the code into an executable format. Some of the programming languages use the interpreter. The job of an interpreter is to execute the code but without compiling it to the machine code. But here we wont learn about an interpreter. Any given programming language can be interpreted or compiled. Languages like C, C++, and PASCAL are compiled while scripting languages like JavaScript and Perl are interpreted.
Ask this question, and you will get a dozen different answers, but, put simply, C++ is a compiled, object-orientated computer-programming language. If you are new to programming, even that has probably left you somewhat confused, so lets break it down a bit more.
There are two types of programming language one is interpreted, and the other is compiled. Interpreted languages are run on an interpreter this reads the code and executes the commands inside one at a time. The CPU reads compiled languages on your computer instead of a program. Computers cannot read letters; they can only read binary numbers so, when you write your code, it has to be translated into binary first. This is called compiling.
The object-orientated part of the explanation just describes how the code is structured, but I will be going into more detail on that later on.
What does this all mean to me?
To be successful at learning C++, you need to use both a text editor and a compiler. If you are using a Windows PC to do this on, you can use Notepad, which is already installed, on your computer as your text editor and, as your compiler, which is going to convert your code into an executable format, you should use GNU C/C++.
Linux/Unix
A simple way to check whether GCC is installed on your Linux/Unix computer is to bring up the command line and type in:
$ g++ -v
If GCC is installed you will get the following message, or something very like it:
Using builtin specs
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr .......
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)
If GCC is not installed, you can follow the instructions on http://gcc.gnu.org/install/ to do so.
Mac OS X
The best way to get GCC for Mac OS X is to go to http://developer.apple.com/technologies/tools, download xCode, and follow the installation instructions.
Windows
To get GCC on your Windows PC, you must first download MinGW from http://www.mingw.org. Make sure you download the latest version of MinGW, as well as installing gcc-core, binutils, gcc-g++, and MinGW runtime these are minimum requirements.