You are on page 1of 12

The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes.

Distribution and modifications of the content is prohibited.

Lecture 3

Objective:

Basic Concepts of Object-Oriented Programming


1

07/26/2022 1
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

2
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

3
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• Before creating an object in C++, need to define a


class.
• It is defined as the blueprint for an object.
• The description of a number of similar objects is also
called a class.
• It serves as a plan or a template.

4
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• For example, if you had a class called


“Expensive Cars” it could have objects like
Mercedes, BMW, Toyota, etc. Its properties
(data) can be price or speed of these cars. While
the methods may be performed with these cars
are driving, taking reverse, braking etc.

5
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• For example If we can think of class as a sketch (prototype)


of a house.
• As, many houses can be made from the same description, we
can create many objects from a class.
• An object is not created by just defining a class.

• It has to be created explicitly.

• A class is a 3-compartment box containing the name, data


members (variables) and the member functions.

6
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

7
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• Example, furniture does not have any existence but tables and
chairs do exist.
• objects contain data, and code to manipulate that data.
• The entire set of data and code of an object can be made a user-
defined data type with the help of class.

8
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• Objects are variables of the type class.

• A class is also defined as a new data type, a user-defined type


which contains two things: data members and methods.

9
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

• A class is a collection of objects of similar types.

• For examples, Mango, Apple and orange members of

class fruit.

10
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

Class

Syntax to create object:-

• If Fruit has been defines as a class, and an object


Mango belonging to the class fruit then the
statement ,

Fruit Mango;

11
The material in this presentation belongs to St. Francis Institute of Technology and is solely for educational purposes. Distribution and modifications of the content is prohibited.

• A class definition starts with the keyword class followed by the class name; and the

class body, enclosed by a pair of curly braces.

• A class definition must be followed either by a semicolon or a list of declarations.

• For example, we defined the Box data type using the keyword class as follows −

class Box {
public:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};

12

You might also like