Object Oriented
Programming
Eng. (Ms.) H.C. Ganege
From last Session …
• Course introduction
• What is the programming language?
• Software Evaluation
• OOP and POP
• Memory concepts
• Operators
• Control Structures
• IDE (Dec C++/ Visual Studio)
• Exercise 01
• Use Dev-C++ IDE for your program.
• Use C++ programming language for answering questions.
• Use procedure-oriented programming concepts for this tutorial.
• Instructions to the candidates for saving and submitting flies.
• Create a directory on the desktop with your Index Number as follows.
• Example: TG_201X_XXX
• Save answers to Questions inside that directory as follows.
o Save the .cpp for each question following the naming convention given below.
• Example: Question Y: CPP_QY
o Further, save your code and results in a screenshot to a pdf for each question following the given
naming convention
• Example: Question Y: PDF_QY
• Zip answers directory with your Index Number as follows.
• Example: TG_201X_XXX
• Upload your Zip file to the given link in LMS
Why Object-Oriented Programming?
• Faster and easier to execute
• Provides a clear structure for the programs
• Helps to keep the code DRY "Don't Repeat Yourself",
and makes the code easier to maintain, modify and
debug
• Makes it possible to create full reusable applications
with less code and shorter development time
Why Object-Oriented Programming?
• More Reliable
• More Flexible
• More Maintainable
• More data Security
• Reusable
• Productivity
Outline
• How to declare/ write a class
• How to create an object?
• How to access class?
Object and Class
• What is an object?
What is an object?
Computer
Pen Car
Book
Apple Cat
Physical Objects
What is an object?
Bank Account
Results
Logical Objects
What is an Object ?
• Objects are entities in a software system that represent instances of
real-world and system entities
What is an Object ?
• Object has two main properties:
• State:
• the object encapsulates information about itself
- attributes
• Behaviour:
• the object can do some things on behalf of other
objects
– methods
Attributes and Methods of an object
Object : Person
Object : Car Object : Bank Account
Attributes
Attributes Attributes
Name
Type AccountNo
Age
Company HolderName
Weight
Fuel AccountType
Methods
Methods Methods
Eat
Start Deposit
Sleep
Drive Withdraw
Walk
Stop Transfer
Class
In an object-oriented system, objects are created from
something called a CLASS
Class
A Class is a blueprint of an object
A Class describe the object
Class
Car
Properties (Describe)
Company
Model
Methods (Functions)
Color
Start
Mfg. year
Drive
Price
Park
Fuel type
Mileage
From car class
Constructing Objects from Classes
Once a class has
been defined, it
can be used to
create any
number of
objects of that
class
What is a Class?
• A class is the blueprint of an object
• When we write OO programs we don't define individual objects, we
define classes, and then use them as templates for constructing
objects. Each individual object is called an instance of its class.
• A class is a general, abstract representation of an object, that
specifies the fields and methods that such an object has.
Class car
class Car {
Car // The class ( The class
keyword is used to create a
Attributes class called car)
Price
Mileage
Methods
};
Start
Drive
Class car
class Car {
int price;
Car float mileage;
Attributes
Price
void start(){}
Mileage
void start(){}
Methods
Start };
Drive
A simple class Example
• A typical class declaration would look like:
class Item {
int number;
float cost;
public:
int getdata(int a, float b);
void putdata(void);
};
22
Thank you …