You are on page 1of 10

Object

Oriented
Concepts
Advanced c++ course
By Manar Elsheref
Good knowledge of
Course
variables perquisites
functions
Data Tasks

Name
Human Wakeup
Age Eat
Address Walk
job talk

Adam othman Sarah

Sample
Class
Variables Functions
Human
Name Wakeup
Age Eat
Address Walk
job talk

Adam othman Sarah

object
Object Oriented Concepts
Object Oriented Concepts

Adam is a sample of human

Adam is an Object (instance )of a Class human

Class has
- Attributes/Class Variables/Data
-Methods/Functions/Tasks
That is consumed (used)using an Object

@genius_minds_designers_coders
Class Definition
A class is a user-defined data type that we can use in our program

To create a class use class keyword

C++ is the class Human { // The class


programming public: // Access specifier
Language int Age; // Attribute (int variable)
string Name; // Attribute (string variable)
Used };
Object Oriented Concepts class Human { // The class Example.cpp
Access attributes and set values
public: // Access specifier
int Age; // Attribute (int variable)
string FullName; // Attribute (string variable)
};
int main() {

C++ is the Human Adam; // Create an object of Human

programming // Access attributes and set values


Adam .Age = 15;
Language Adam.Name = “Adam Sam";
Used // Print attribute values
cout << “Adam AGE”<<Adam .Age << "\n";
cout << “Adam full name”<< Adam.Name;
return 0;
}
Object Oriented Concepts Class Methods
 Methods are functions that belongs to the class.
Access functions and execution
 There are two ways to define functions that belongs to a class:
 Inside class definition
 Outside class definition

class Human { // The class

C++ is the public:


void walk() {
// Access specifier
Inside class definition

programming // Method/function defined inside the class


cout << “walking ….walking!";
Language }
};
Used
void Human :: walk() { outside class definition
// Method/function defined outside the class
cout << “walking ….walking!";
}
class Human { // The class Example.cpp
public: // Access specifier
Output of the code int Age; // Attribute (int variable)
string Name; // Attribute (string variable)
Adam AGE :15 void walk() // Method/function defined inside the class
Adam full name: Adam Sam {
eats…………………eats cout<<“walking……………..walking” <<“\n”;}
walking……………..walking void eat() // Method/function defined inside the class
{
cout<<“eats…………………eats”<<“\n”;}
};

int main() {
Human Adam; // Create an object of Human

// Access attributes and set values


Adam .Age = 15;
Adam.Name = “Adam Sam";

Object Oriented // Print attribute values


Concepts cout << “Adam AGE :”<<Adam .Age << "\n";
cout << “Adam full name : ”<< Adam.Name << "\n";
using
C++ programming Language Adam.eat(); // calling functions
Adam.walk(); // calling functions
return 0;
}
Object Oriented Concepts class Human { // The class Example.cpp
Access attributes and set values public: // Access specifier
int Age; // Attribute (int variable)
string FullName; // Attribute (string variable)
};
int main() {
C++ is the Human Adam; // Create an object of Human

programming // Access attributes and set values


Language Adam .Age = 15;
Adam.Name = “Adam Sam";
Used
// Print attribute values
cout << “Adam AGE”<<Adam .Age << "\n";
cout << “Adam full name”<< Adam.Name;
return 0;
}

You might also like