0% found this document useful (0 votes)
5 views3 pages

OOP_Lecture_3(Class and Object)

The document provides an overview of Object Oriented Programming (OOP), detailing the differences between structural programming and OOP, how to define classes and create objects, and access class members. It includes examples of class definitions, access modifiers, and built-in operators, as well as methods for setting and getting values in a class. Additionally, it illustrates the use of a Clock class with methods for time management and display.

Uploaded by

TECNICAL GURU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

OOP_Lecture_3(Class and Object)

The document provides an overview of Object Oriented Programming (OOP), detailing the differences between structural programming and OOP, how to define classes and create objects, and access class members. It includes examples of class definitions, access modifiers, and built-in operators, as well as methods for setting and getting values in a class. Additionally, it illustrates the use of a Clock class with methods for time management and display.

Uploaded by

TECNICAL GURU
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object Oriented Programming (OOP)

Lecture(Classes and Objects)


-------------------------------------
1: Difference Structural Programming and OOP.
2: How to Define Classes
3: How to Create Objects
4: How to Access Class Member
5: How to Add Function(Behaviour) to Class
6: Which operation are supported on objects
7: Member Access Specifier

--------------------------------------
1: Programming Paradigm
1: Imperative Paradigm
a: Structural Paradigm
b: Object Oriented Paradigm
2: Descriptive Paradigm
a: Functional Paradigm
b: Logical Paradigm
--------------------------------------
2: How to define Class

struct StructName
{
member1;
member2;
.......
memberN;
};

class ClassName
{
member1;
member2;
.......
memberN;

Method1();
Method2();
....
MethodN();
};

class Person
{
string name;
int age;
float height;

void displayInfo()
{
cout<<"Name: " <<name<<" Age: "<<age<<" Height: "<<height<<endl;
}

};

------------------------------
3: Create variable(object/instance)
DataType NameVar;
int a;
struct student
{
string name;
int age;
};

student s1;
s1.name="Ali";
s1.age=20;

Person p1;
--------------------------------
4: Access Modifiers
a): Private // Attribute/Methods define under private access modifier will
not
access outside the class.
b): Public // Attribute/Methods define under public access modifier will be
accessible outside the class through object of that class.
c): Protected // Discuss in detail at Inheritance

----------------------------------
5: Built-in Operator
a) dot/period (.)
b) assignment(=)
p2=p1;

----------------------------------
6: Add getter setter methods in class

-------------------------------------
Example 2:

class Clock{
private:
int hr, min , sec;

public:

void setHr(int h)
{
if(h>=0 && h<24 )
hr=h;
else
hr=0;
}
void setMin(int m)
{
if(m>=0 && m<60 )
min=m;
else
min=0;
}
void setSec(int s)
{
if(s>=0 && s<60 )
sec=s;
else
sec=0;
}
int getHr()
{
return hr;
}
int getMin()
{
return min;
}
int getSec()
{
return sec;
}
void incHr()
{
hr++;
if(hr>23)
hr=0;
}

void incMin()
{
min++;
if(min>59)
{min=0;
incHr();
}
}
void incSec()
{
sec++;
if(sec>59)
{sec=0;
incMin();
}
}

void DisplayTime()
{
cout<<"Current Time is: " <<hr<< ":"<<min<<":"<<sec<<" (HH:MM:SS)"<<endl;
}
};

You might also like