0% found this document useful (0 votes)
23 views34 pages

Topic 2 - Mac2024

The document discusses the basic elements of a C++ program including components like comments, identifiers, data types, operators and expressions. It covers topics such as built-in and derived data types as well as unary and binary operators.

Uploaded by

qbby44hgh8
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)
23 views34 pages

Topic 2 - Mac2024

The document discusses the basic elements of a C++ program including components like comments, identifiers, data types, operators and expressions. It covers topics such as built-in and derived data types as well as unary and binary operators.

Uploaded by

qbby44hgh8
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/ 34

TOPIC 2:

BASIC ELEMENTS OF
COMPUTER PROGRAM
(PART 1)
CSC126 – FUNDAMENTALS OF ALGORITHMS & COMPUTER PROBLEM
SOLVING
LEARNING OBJECTIVES
At the end of the lesson, the students should be
able to:
Understand basic program components
Define & use the identifier, variable & statement
Understand the standard data type
Use the input & output statement
Use the arithmetic operator
Understand the assignment statement
Write simple programs

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 2


SECTION 1:
BASIC C++ PROGRAM
COMPONENTS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 3


A computer program,
or program, is a
Programming is a
sequence of
process of planning &
statements whose
creating a program
objective is to
accomplish task

Some functions are


A C++ program is a
predefined by the
collection of one or
system & some
more subprograms,
functions are written by
called functions
the programmers

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 4


Syntax rules: Semantic rules:
Tell which
statements are
legal or accepted Determine the
by the meaning of the
programming statements
language, &
which are not

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 5


Comments
Written for the reader, not for the compiler

There are 2 types of comments: single-line


comment & multi-line comments

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 6


PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 7
PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 8
1. RESERVED WORDS

Reserved words are also called


keywords

Reserved words cannot be


redefined

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 9


2. OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 10


ARITHMETIC OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 11


RELATIONAL OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 12


LOGICAL OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 13


ASSIGNMENT OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 14


BITWISE OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 15


MISCELLANEOUS OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 16


3. STRING

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 17


4. NAMED CONSTANT

A named constant is a location in memory that can be referred to by


an identifier, and in which a data value that cannot be changed is
stored

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 18


4. SPECIAL CHARACTERS

Special characters or special symbols cannot be used for


anything other than their intended use

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 19


6. IDENTIFIERS
Identifiers are All identifiers A C++ identifier
names of things must obey C++ consists of
that appear in rules for letters, digits &
programs identifiers underscore

Identifiers can
C++ is case
be of any
sensitive
length
PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 20
PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 21
SECTION 2:
DATA TYPES
Data type can be defined as a set of values together with a set
of operations

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 23


BUILT-IN DATA TYPE

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 24


BUILT-IN DATA TYPE

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 25


DERIVED DATA TYPE

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 26


DERIVED DATA TYPES

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 27


SECTION 3:
ARITHMETIC OPERATOR &
OPERATOR PRECEDENCE

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 28


ARITHMETIC OPERATORS

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 29


ARITHMETIC EXPRESSION

An arithmetic expression is constructed using arithmetic operators & numbers

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 30


UNARY OPERATORS VS. BINARY
OPERATORS

Operators that Operators that


have only one have 2 operands
operand are called are called binary
unary operators operators

Example: Example:
-5 8+7

PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 31


PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 32
PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 33
PREPARED BY: NYCJ@KKPIM, UiTM CAWANGAN PERLIS KAMPUS ARAU 34

You might also like