Understanding of C++
Understanding of C++
C++ PROGRAMMING
BY: ELJO JALIEL CARIÑO
VIRTUAL TUTOR EDUCATION
GRADUATE OF BSIT 2017
INTRODUCTION OF C++
C++, as we all know is an extension to C language and was
developed by Bjarne stroustrup at bell labs. C++ is an
intermediate level language, as it comprises a confirmation
of both high level and low level language features. C++ is a
statically typed, free form, multiparadigm, compiled
general-purpose language.
C++ will help you instill good programming habits (i.e. clear
and consistent coding style, comment the code as you
write it, and limit the visibility of class internals to the outside
world), and because there’s hardly any abstraction, you’re
required to define just about every attribute to make your
code work.
OVERVIEW OF C++ TOOLS
In order to properly make C++ programs, you’ll need to be
familiar with a few tools and softwares: a text editor, a C++
compiler, a linker, and libraries.
TEXT EDITOR
In order to write a C++ program, you need a text editor.
Think of this like a blank Microsoft Word Document; it is
where you will actually write your code. Any text editor will
do, and there are even some that come built into your
computer, but we recommend using a text editor designed
for coding. There are many options out there, but some of
the most common text editors for C++ developers are:
Notepad++: open-access, lightweight, simple
Atom: free, supports many languages, limited plugins
Sublime Text: $80, unique features, simple layout
Bluefish: lightweight, fast, multi-platform, supports many
languages
COMPILERS
A compiler goes through your source code to accomplish
two important tasks: first, it checks that your code follows
the C++ language rules; second, it translates your code into
an object file. Some well-known compilers are GCC, Clang,
and the Visual Studio C++ compiler. We don’t recommend
Turbo C++, since it’s a bit out of date.
LINKER
Once the compiler does its magic, the object file is sent to a
linker program which completes three tasks: first, it combines
all your object files into a single program; second, it links
library files to your program; and third, it exposes any cross-
file naming or reference issues.
LIBRARIES
A library is essentially a prepackaged bundle of code that
can be reused. The C++ library is called the C++ Standard
Library, and this is linked to almost every C++ program. You
can also add other libraries to your program if you have
needs not met by the C++ Standard Library.
Goto
Float
Public
Class(1)
Int
VARIABLES
Variables are like containers that store values. To declare a
variable, you must give it a value and a type using the
correct keyword. All variables in C++ need a name, or
identifier. There are some basic syntax rules to follow when
making identifiers.
DATA TYPES
Data types are the classifications for different kinds of data
you can use in a program. Data types tell our variables what
data they can store. There are three data types in C++:
Primitive data types: these are the built-in data that you
can use to declare variables. They
include integer, character, boolean, floating
point, double floating point, void, and wide character.
Derived data types: these are derived from the
primitive data types. They
include function, reference, array, and pointer.
User-Defined data types: these are defined by you, the
programmer.
STRINGS
Strings are objects in C++. They are a set of characters
within ” “ quotes, like our ”Hello World” string. Since they are
objects, we can perform functions to them, like the length (
) function, which determines the length of a string.
OPERATORS
Operators are symbols that manipulate our data and
perform operations. In C++, we can overload operators to
make them work for programmer-defined classes.
Overloading an operator basically means that an operator
can have more than one function at a time. There are four
kinds of operators in the C++ language:
OBJECTS
An object is a collection of data that we can act upon. An
object in C++ has an attribute (its traits) and method (its
abilities). You construct objects using a class. Think of this like
a blueprint for an object.
You create a class using the class keyword. You must define
an access specifier, such as public, private, or protected.
The public keyword states that class is accessible from
outside that class. Once you define your class, you can
define your attributes and objects. Take a look below at an
example of a class and object.
FUNCTIONS
Functions are blocks of code that run when they are
invoked. They are the workhorse for your program and are
used to perform operations and manipulations on your
code.
CONDITIONAL STATEMENTS
These allow you to perform checks on whether a block of
code should be executed or not. There are four conditional
statements in C++:
if: a certain action will be performed if a certain
condition is met
else: a certain action will be performed instead if that
condition is not met
else if: a new condition will be tested if the first is not
met
switch: tests a variable against a list of values
LOOPS
Loops are similar to conditional statements. They execute
blocks of code as long as a certain condition is reached.
There are two types of loops in C++: