Академический Документы
Профессиональный Документы
Культура Документы
Learning a
programming
language is
like learning
to become a
chef.
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Basics of Programming
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
The C++ Language
case sensitive
1Bjarne Stroustrup, designer of C++
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
A C++ Program
Pre-processor directive –
instructs the compiler to
locate the file that contains
allows you to use cout and
codepoint
Entry for the
for <iostream>
the library
application
endl without the prefix std::
when program execution
Opening starts.
curly brace
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
A C++ Program
1.
2.
3.
4.
5.
6.
7.
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Processing a C++ Program
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Processing a C++ Program
PREPROCESSOR DIRECTIVES
- statements that begin with the symbol #
- processed by preprocessor program
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Processing a C++ Program
LINKER
- A program that combines the LOADER
object program with other - Loads the executable
programs in the library, and is program into main
used in the program to create memory for execution.
the executable code.
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
C++ Tokens
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Special Symbols
MATH
SYMBOLS
PUNCTUATION
MARKS
two
characters
regarded as
a single
symbol
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Reserved Words
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Identifiers
LEGAL ILLEGAL
There can be no
space between
Employee and Salary
first Employee Salary
Exclamation mark
conversion Hello! cannot be used in an
identifier
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
C++ Data Types
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Simple Data Types
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Integral Data Types
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Integral Data Types
Storage
Data Type Values
(in bytes)
(signed) -128 to 127
char 1
(unsigned) 0 to 255
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Floating-Point Data Types
- single precision
FLOAT - maximum number of significant
digits (decimal places) is 6 or 7.
- double precision
DOUBLE - maximum number of significant
digits (decimal places) is 15.
Precision – maximum number of significant digits
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Arithmetic Operators
In the division 5 / 2,
the quotient is 2
and the remainder
is 1. Therefore, 5 / 2
with the integral
operands
evaluates to the
quotient, which is
2.
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Arithmetic Operators
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Order of Precedence
Higher level of
precedence
Example:
3*7–6+2*5/4+6
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Order of Precedence
Example:
3*7–6+2*5/4+6
Solution:
= ((21 – 6) + 2) + 6
= (15 + 2) + 6
= 17 + 6
= 23
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Expressions
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Expressions
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Expressions
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Casting
FORM:
static_cast<dataTypeName> (expression)
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Casting
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
String
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Constants and Variables
EXAMPLES:
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Assignment Statement
FORM:
Assignment operator
QUESTION:
How are we going to code the following?
FORM:
FINGER EXERCISE:
Create a program that will input the following:
• First Name, Last Name
• Age Note: one value per line
can be entered during
• Weight
program execution
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Output Statement
FORM:
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Escape Sequences
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Preprocessor Directives
FORM:
Library
Statements:
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Program Style and Form
Syntax
Use of Blanks
Semantics
Naming Identifiers
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
Program Style and Form
ASSIGNMENT STATEMENT
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE
End of Lecture.
THANK YOU!
UST – Faculty of Engineering Lecture 2: Introduction to C++ Ma. Madecheen S. Pangaliman, ECE