Koya Technical Institute Object Oriented Program: K.T.I 2016-2017 by M.Wshyar
Koya Technical Institute Object Oriented Program: K.T.I 2016-2017 by M.Wshyar
Lecture 2
Oct 26, 2017
1
K.T.I 2016-2017 By M.Wshyar
What is a Constants?
- Constants are expressions with a fixed value.
2
K.T.I 2017-2018 By M.Wshyar
Example
3
K.T.I 2017-2018 By M.Wshyar
Preprocessor definitions (#define)
4
K.T.I 2017-2018 By M.Wshyar
Example
5
K.T.I 2017-2018 By M.Wshyar
Functions
- In C++, a function is a group of statements that is
given a name, and which can be called from some
point of the program.
- The most common syntax to define a function is:
type name ( parameter1, parameter2, ...)
{ statements }
7
K.T.I 2017-2018 By M.Wshyar
Function Example
8
K.T.I 2017-2018 By M.Wshyar
Function
- Multi function:
9
K.T.I 2017-2018 By M.Wshyar
What is a Class?
- A class is a blueprint for the object.
- Before you create an object in C++, you need
to define a class.
- We can think of class as a sketch
(prototype) of a house. It contains all the
details about the floors, doors, windows etc.
Based on these descriptions we build the
house. House is the object.
- As, many houses can be made from the
same description, we can create many
objects from a class.
10
K.T.I 2017-2018 By M.Wshyar
How to define a class in C++?
- A class is defined in C++ using keyword class
followed by the name of class.
- The body of class is defined inside the curly
brackets and terminated by a semicolon at the
end.
class className
{
// some data
// some functions
};
11
K.T.I 2017-2018 By M.Wshyar
Example: Class in C++
12
K.T.I 2017-2018 By M.Wshyar
private and public in the above example.
- The private keyword makes data and functions
private. Private data and functions can be
accessed only from inside the same class.
- The public keyword makes data and functions
public. Public data and functions can be accessed
out of the class.