You are on page 1of 18

ICT S112: FUNDAMENTALS OF COMPUTING

INTRODUCTION TO
C++
PREPARED BY MR. JOHN PATRICK S. PAULINO
OBJECTIVES

01 02 03
Discuss the basics Apply the general Develop a program
of C++ structure of C++ using C++
programming programming programming
language. language. language.
Writing a
C++ Program
Properly written C++ programs have a
particular structure. The syntax must be
correct, or the compiler will generate error
messages and not produce executable
machine language.
Syntax
The set of rules that defines the
combinations of symbols that are
considered to be correctly structured
statements or expressions in that language.
TRY THIS!
Input the codes on the compiler and execute to see the output.
C++ BASIC PROGRAM STRUCTURE
#include <iostream>
➢ This line is a preprocessing directive.

➢ All preprocessing directives within C++ source code begin with a # symbol.

➢ It allows to use the standard input (cin) and output (cout) statements.

using namespace std;


➢ tells the compiler to use the std (standard) namespace.

int main () {
➢ The starting point of the program execution.
➢ The opening curly brace { at the end of the line marks the
beginning of the body of a function. The body of a function
contains the statements the function is to execute.
C++ BASIC PROGRAM STRUCTURE
cout << “Hello, World!”;
➢ This statement directs the executing program to print the message
Hello, World! on the computer screen.
➢ All statements in C++ end with a semicolon (;).

return 0;
➢ This will terminate the int main() function and causes it to return
the value 0 to the calling process.

}
➢ Closing curly brace closes the body of the main function.
VARIABLE
- A name the programmer uses
to refer to the computer
storage locations. Used to hold
values.

- Variables and constants are


objects that a program
manipulates.

Ex. int age;


- defines a variable
with the name age which
stores data of type int (integer)
VARIABLE DECLARATION
Assignment Statement
● Stores the value of an expression into a variable.
● Syntax: Variable = “Expression”;

Expression
● An arrangement of identifier, literals, and operators that can be
evaluated to compute a value of a given type.
Evaluate
● To compute a new value by performing a specified set of operations
on the given values.
Identifier
● It refers to a name composed of a sequence of letters, digits, and
underscores.
● Variable names in C++ can
range from 1 to 255
characters.
● All variable names must
begin with a letter of the
RULES IN alphabet or an underscore (_).
DECLARING A ● After the first initial letter,
variable names can also
VARIABLE IN C++ contain letters and numbers.
● Variable names are case
sensitive.
● No spaces or special
characters are allowed.
● You cannot use a C++
keyword/reserved word as a
variable name.
KEYWORDS IN C++
Keywords in C++ are also known as reserved words, which means they
must be used only for their specified purpose.

auto default goto public this


break do if register template
case double inline return typedef
catch else int short union
char enum long signed unsigned
class extern new sizeof virtual
const float overload static void
continue for private struct volatile
delete friend protected switch while
BASIC INPUT/OUTPUT
C++ uses a convenient abstraction called streams to perform input and
output operations in sequential media such as the screen, the keyboard
or a file. A stream is an entity where a program can either insert or
extract characters to/from.

STREAM DESCRIPTION

cin Standard input stream

cout Standard output stream

cerr Standard error (output) stream

clog Standard logging (output) stream


A set of data that specifies the possible range of
DATA TYPE values of the set, the operations that can be
performed on the values, and the way in which
the values are stored in memory.
PRIMITIVE DATA TYPES
These data types are built-in or predefined data types and can be use
directly by the user to declare variables.
TYPE KEYWORD Description
Boolean bool Stores either value true or false.
Character char Storing a single character.
Integer int Positive and negative number without
a decimal point.
Floating Point float Number containing decimal point or
exponent
Double Floating Point double A double-precision floating point
value.
Valueless void Without value.
Wide Character wchar_t A wide character type.
RELATIONAL OPERATORS
Refers to the construct or operator that tests or defines some kind of
relation between two entities.

OPERATORS MEANING

> is greater than

< is less than

== is equal to

>= is greater than or equal to

<= is less than or equal to

!= is not equal to
LOGICAL OPERATORS
Used to combine two or more conditions/constraints or to complement
the evaluation of the original condition in consideration. The result is a
Boolean value either TRUE or FALSE.

Logical AND ‘&&’ – returns true when both the conditions in


consideration are satisfied, otherwise it returns false.

Logical OR ‘| |’ – returns true when one (or both) of the conditions in


consideration is satisfied, otherwise it returns false.

Logical NOT ‘!’ – returns true the condition in consideration is not


satisfied, otherwise it returns false.
ARITHMETIC OPERATORS

OPERATORS DESCRIPTION

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulo
QUESTION?

You might also like