0% found this document useful (0 votes)
13 views

Learn Programming With C

The document provides an introduction to programming and C++, explaining that programming involves creating instructions for computers using languages like C++. It highlights C++ as a high-level language suitable for various applications and emphasizes the need for a compiler to translate C++ code into machine code. Additionally, it covers essential concepts such as IDEs, syntax, variables, and constants in C++ programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Learn Programming With C

The document provides an introduction to programming and C++, explaining that programming involves creating instructions for computers using languages like C++. It highlights C++ as a high-level language suitable for various applications and emphasizes the need for a compiler to translate C++ code into machine code. Additionally, it covers essential concepts such as IDEs, syntax, variables, and constants in C++ programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Learn Programming with C++:

A Step-by-Step Introduction
What is Programming ?
Computer programming, or coding, involves
creating sequences of instructions that
computers follow to perform tasks (Wikipedia).
What is Programming ?
Computer programming, or coding, involves
creating sequences of instructions that
computers follow to perform tasks (Wikipedia).
What is Programming ?
Computer programming, or coding, involves
creating sequences of instructions that
computers follow to perform tasks (Wikipedia).

Instruction

CPU
What is Programming ?
Computer programming, or coding, involves
creating sequences of instructions that
computers follow to perform tasks (Wikipedia).

Instruction
R
CPU
What is Programming ?
• Computer programming, or coding, involves
creating sequences of instructions that
computers follow to perform tasks (Wikipedia).
• These instructions can be written using
programming languages like C++.
What is C++ ?
• C++ is a high-level programming language used
to write a software.
• It's widely used for system software, game
development, and applications requiring high
performance.
What is C++ ?
• High-level programming language are languages
that are easy to learn and use, and are
convenient for managing complex tasks.
Can the computer understand C++?
• High-level programming language are languages
that are easy to learn and use, and are
convenient for managing complex tasks.
What is C++ ?
• No, a computer cannot directly understand C++
programming language;
What is C++ ?
• No, a computer cannot directly understand C++
programming language;
• It needs a compiler to translate the C++ code
into machine code, which is the only language a
computer can understand.
What is C++ ?
• It needs a compiler to translate the C++ code
into machine code, which is the only language a
computer can understand.

Compiler
What is C++ ?
• It needs a compiler to translate the C++ code
into machine code, which is the only language a
computer can understand.

Hello World!
Compiler
What is C++ ?
• C++ is a high-level programming language used
to write a software.
• It's widely used for system software, game
development, and applications requiring high
performance.
What is C++ ?
• C++ is a high-level
programming language
used to write a software.
• It's widely used for
system software, game
development, and
applications requiring
high performance.
Integrated Development
Environment (IDE)
Integrated Development
Environment (IDE)
• IDE (Integrated Development Environment): A
tool that helps write, compile, and debug code.

• Example: Dev-C++, Code::Blocks, Visual Studio,


and CLion.
Integrated Development
Environment (IDE)
• IDE (Integrated Development Environment): A
tool that helps write, compile, and debug code.

• Example: Dev-C++, Code::Blocks, Visual Studio,


and CLion.
Dev-C++
What is Dev-C++ ?
What is Dev-C++ ?
• Dev-C++ is a free, integrated development
environment (IDE) for writing, compiling, and
debugging C/C++ programs.
• It's a popular tool for learning C++ and is used by
universities worldwide.
How do download ?
How do download ?
C++ Syntax
• Line 1: #include <iostream> is a header file library
that lets us work with input and output objects,
such as cout (used in line 5). Header files add
functionality to C++ programs.
• Line 2: using namespace std means that we can use
names for objects and variables from the standard
library.
• Line 3: A blank line. C++ ignores white space. But
we use it to make the code more readable.
• Line 4: Another thing that always appear in a C++
program is int main(). This is called a function. Any
code inside its curly brackets {} will be executed.
C++ Syntax
• Line 5: cout (pronounced "see-out") is an
object used together with the insertion
operator (<<) to output/print text. In our
example, it will output "Hello World!".
• Note: C++ is case-sensitive: "cout" and "Cout" has
different meaning.
• Note: Every C++ statement ends with a semicolon ;.
• Note: The body of int main() could also been
written as: int main () { cout << "Hello World! ";
return 0; }
• Line 6: return 0; ends the main function.
• Line 7: Do not forget to add the closing curly bracket } to
actually end the main function.
C++ Statements
• A computer program is a list of "instructions" to
be "executed" by a computer.
• In a programming language, these programming
instructions are called statements.
• The following statement "instructs" the
compiler to print the text "Hello World" to the
screen:
C++ Output (Print Text)
• The cout object, together
with the << operator, is
used to output values and
print text.
• Just remember to surround
the text with double quotes
(""):
C++ Output Numbers
• You can also use cout() to print numbers.
• However, unlike text, we don't put numbers
inside double quotes:
C++ Output Numbers
• You can also use cout() to print
numbers.
• However, unlike text, we don't
put numbers inside double
quotes:
• You can also perform
mathematical calculations:
C++ New Lines
• To insert a new
line in your
output, you can
use the \n
character:
C++ Statements
• Comments can be used to explain C++ code, and to make it
more readable. It can also be used to prevent execution
when testing alternative code. Comments can be singled-
lined or multi-lined.
C++ Variables
• Variables are containers for storing data values.
• In C++, there are different types of variables (defined with different
keywords), for example:

• int - stores integers (whole numbers), without decimals, such as 123 or -


123
• double - stores floating point numbers, with decimals, such as 19.99 or -
19.99
• char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
• string - stores text, such as "Hello World". String values are surrounded by
double quotes
• bool - stores values with two states: true or false
Declaring (Creating) Variables
• To create a variable, specify the type and assign it a
value:

• Where type is one of C++ types (such as int), and


variableName is the name of the variable (such as x
or myName). The equal sign is used to assign values
to the variable.
C++ Identifiers
• All C++ variables must be identified with unique names.
• These unique names are called identifiers.
• Identifiers can be short names (like x and y) or more
descriptive names (age, sum, totalVolume).
• Note: It is recommended to use descriptive names in order to
create understandable and maintainable code:
C++ Identifiers
• The general rules for naming variables are:
• Names can contain letters, digits and underscores
• Names must begin with a letter or an underscore (_)
• Names are case-sensitive (myVar and myvar are different
variables)
• Names cannot contain whitespaces or special characters like !, #,
%, etc.
• Reserved words (like C++ keywords, such as int) cannot be used as
names
C++ Constants
When you do not want others (or yourself) to change existing
variable values, use the const keyword (this will declare the
variable as "constant", which means unchangeable and read-
only):

When you declare a constant variable, it must be assigned with a value:

You might also like