SlideShare a Scribd company logo
1 of 14
Object Oriented Programming
(OOP)
Lecture 01
Important Features of OOP
 There are three major features of
Object Oriented Programming
1. Encapsulation: Achieved by dividing
a program into classes (similar to
structures)
2. Inheritance: Classes are derived
from other classes
3. Polymorphism: Achieved by use of
virtual functions and pointers
Structures …
 A collection of related data items is
called structure
 In array all elements are of same type,
unlike array the elements of structure
can be of different types
 Structure is also known as record
(collection of related fields of different or
same type)
 Structures are used in files processing
as a file is the collection of related
records (structures)
Defining Structure …
 Defining names, types and number of data
items inside structure is called defining
structures
 The struct keyword is used for defining a
structure
struct structurename
{
type a;
type b;
type c;
};
Defining Structures …
 Example of structure
struct address
{
char name [20];
char city [15];
float age;
};
Structure Variable
 Variables of structure data type are
declared for defined structures called
structure variables
 Memory is reserved in computer
memory after declaration of structure
variable
 The size of memory reserved is equal
to the size of each data member of
each variable
Structure Variable …
 Example of structure variable
struct address
{
char name[20];
char city[15];
float age;
};
address var1, var2, abc;
Accessing Members of a
Structure
 The members of a structure are
accessed using dot operator (.)
 Strucvariable.structelement;
struct address
{
char name[20];
char city[15];
float age;
};
main()
{
address var1;
cout<< “enter name, city and age”;
cin>>var1.name;
cin>>var1.city;
cin>>var1.age;
}
Refer to program struct.cpp
Structure …
Lab Assignment
Write a program to copy one structure
variable to another variable and then
print it on the screen without using
built-in function
Initialization of Structure
Variables
 The values to a structure variable can be
assigned during its declaration time as
well (same like variable or array
initialization)
 Actually, data members (usually
variables) are initialized that are used
inside structure
 The order of data members and type
must be kept same in initialization with
the order and type as used inside
structure during definition
Initialization of Structure
Variables
Example of Structure variable initialization
struct address
{
char name [20];
float age;
};
address var1 = { “M. Ali”, 22};
 The values to a structure variable are
assigned in curly braces separated by
comma
Structure Variables as Arrays
 Structure variable can be also
declared as of an array type to
manage large number of records
(each element of the array represents
a complete record)Example of array structure variable
struct address
{
char name [20];
float age;
};
Address var[4]; //address var1, var2, var3, var4;
Initialization of Array of Structure
 The data into an array of structure can
be initialized at the time of declaration
same like two dimensional array is
initialized
Example of initializing array structure variable
struct address
{
char name [20];
float age;
};
Address var[4] = {{ “M. Ali”, 22}, { “Saad”, 21}
{ “Kashif”, 23}, { “Rizwan”, 19.5}}
Structure …
 Lab Assignment
Write a program to initialize a structure
array variable of size 4 with 3
members and then display all the
records

More Related Content

What's hot

Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Smit Shah
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture topu93
 
Structure in c language
Structure in c languageStructure in c language
Structure in c languagesangrampatil81
 
Persentation on c language
Persentation on c languagePersentation on c language
Persentation on c languageSudhanshuVijay3
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppteShikshak
 
Adbms 14 oodbms concepts for managing objects
Adbms 14 oodbms concepts for managing objectsAdbms 14 oodbms concepts for managing objects
Adbms 14 oodbms concepts for managing objectsVaibhav Khanna
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introductionMandeep Singh
 
Data structure Assignment Help
Data structure Assignment HelpData structure Assignment Help
Data structure Assignment HelpJosephErin
 
Str
StrStr
StrAcad
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template libraryRahul Sharma
 
Structures in c programming
Structures in c programmingStructures in c programming
Structures in c programmingKousalya M
 

What's hot (20)

Structure in c
Structure in cStructure in c
Structure in c
 
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
 
Presentation on c programing satcture
Presentation on c programing satcture Presentation on c programing satcture
Presentation on c programing satcture
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
Structure
StructureStructure
Structure
 
Struct
StructStruct
Struct
 
Persentation on c language
Persentation on c languagePersentation on c language
Persentation on c language
 
Unit4 C
Unit4 C Unit4 C
Unit4 C
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Adbms 14 oodbms concepts for managing objects
Adbms 14 oodbms concepts for managing objectsAdbms 14 oodbms concepts for managing objects
Adbms 14 oodbms concepts for managing objects
 
17 structure-and-union
17 structure-and-union17 structure-and-union
17 structure-and-union
 
Jdbc
JdbcJdbc
Jdbc
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
1. Data structures introduction
1. Data structures introduction1. Data structures introduction
1. Data structures introduction
 
Data structure Assignment Help
Data structure Assignment HelpData structure Assignment Help
Data structure Assignment Help
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Str
StrStr
Str
 
Understanding the components of standard template library
Understanding the components of standard template libraryUnderstanding the components of standard template library
Understanding the components of standard template library
 
collections
 collections collections
collections
 
Structures in c programming
Structures in c programmingStructures in c programming
Structures in c programming
 

Similar to oop Lecture 1

Similar to oop Lecture 1 (20)

Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Lk module4 structures
Lk module4 structuresLk module4 structures
Lk module4 structures
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
SPC Unit 5
SPC Unit 5SPC Unit 5
SPC Unit 5
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
Structures in c++
Structures in c++Structures in c++
Structures in c++
 
Data structures
Data structuresData structures
Data structures
 
2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++2 lesson 2 object oriented programming in c++
2 lesson 2 object oriented programming in c++
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
Unit 4 qba
Unit 4 qbaUnit 4 qba
Unit 4 qba
 
Unit-V.pptx
Unit-V.pptxUnit-V.pptx
Unit-V.pptx
 
structures.ppt
structures.pptstructures.ppt
structures.ppt
 
Introduction to structures in c lang.ppt
Introduction to structures in c lang.pptIntroduction to structures in c lang.ppt
Introduction to structures in c lang.ppt
 
Structure.pptx
Structure.pptxStructure.pptx
Structure.pptx
 
CPU : Structures And Unions
CPU : Structures And UnionsCPU : Structures And Unions
CPU : Structures And Unions
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
DS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptxDS-UNIT 1 FINAL (2).pptx
DS-UNIT 1 FINAL (2).pptx
 
Data Structures_Introduction
Data Structures_IntroductionData Structures_Introduction
Data Structures_Introduction
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 

oop Lecture 1

  • 2. Important Features of OOP  There are three major features of Object Oriented Programming 1. Encapsulation: Achieved by dividing a program into classes (similar to structures) 2. Inheritance: Classes are derived from other classes 3. Polymorphism: Achieved by use of virtual functions and pointers
  • 3. Structures …  A collection of related data items is called structure  In array all elements are of same type, unlike array the elements of structure can be of different types  Structure is also known as record (collection of related fields of different or same type)  Structures are used in files processing as a file is the collection of related records (structures)
  • 4. Defining Structure …  Defining names, types and number of data items inside structure is called defining structures  The struct keyword is used for defining a structure struct structurename { type a; type b; type c; };
  • 5. Defining Structures …  Example of structure struct address { char name [20]; char city [15]; float age; };
  • 6. Structure Variable  Variables of structure data type are declared for defined structures called structure variables  Memory is reserved in computer memory after declaration of structure variable  The size of memory reserved is equal to the size of each data member of each variable
  • 7. Structure Variable …  Example of structure variable struct address { char name[20]; char city[15]; float age; }; address var1, var2, abc;
  • 8. Accessing Members of a Structure  The members of a structure are accessed using dot operator (.)  Strucvariable.structelement; struct address { char name[20]; char city[15]; float age; }; main() { address var1; cout<< “enter name, city and age”; cin>>var1.name; cin>>var1.city; cin>>var1.age; } Refer to program struct.cpp
  • 9. Structure … Lab Assignment Write a program to copy one structure variable to another variable and then print it on the screen without using built-in function
  • 10. Initialization of Structure Variables  The values to a structure variable can be assigned during its declaration time as well (same like variable or array initialization)  Actually, data members (usually variables) are initialized that are used inside structure  The order of data members and type must be kept same in initialization with the order and type as used inside structure during definition
  • 11. Initialization of Structure Variables Example of Structure variable initialization struct address { char name [20]; float age; }; address var1 = { “M. Ali”, 22};  The values to a structure variable are assigned in curly braces separated by comma
  • 12. Structure Variables as Arrays  Structure variable can be also declared as of an array type to manage large number of records (each element of the array represents a complete record)Example of array structure variable struct address { char name [20]; float age; }; Address var[4]; //address var1, var2, var3, var4;
  • 13. Initialization of Array of Structure  The data into an array of structure can be initialized at the time of declaration same like two dimensional array is initialized Example of initializing array structure variable struct address { char name [20]; float age; }; Address var[4] = {{ “M. Ali”, 22}, { “Saad”, 21} { “Kashif”, 23}, { “Rizwan”, 19.5}}
  • 14. Structure …  Lab Assignment Write a program to initialize a structure array variable of size 4 with 3 members and then display all the records