SlideShare uma empresa Scribd logo
1 de 14
Array within a Class
AS WE HAVE ARRAYS WITHIN A STRUCTURE. IN THE SAME WE CAN HAVE
ARRAYS AS A DATA MEMBER WITHIN A CLASS ALSO. THEY CAN BE
DECLARED EITHER IN PRIVATE OR PROTECTED OR PUBLIC SECTION.
Example:- Array as data member of Class
 Class student
 {
 Int rollno;
 Char name[50];
 Int marks[5]; // arrary of 5 intgers variables to store marks in
5 subjects.
 Int total;
 Float average;
 Public:
 Void getstuddetails();
 Void printstuddetails();
};
Void student:: getstuddetails()
{
cout<<“Enter rollno”;
cin>>rollno;
cout<<“Enter Name”;
gets(name);
total=0;
cout<<“Enter marks in 5 sujects”;
for(int i=0;i<5;i++)
{
cout<<“Subjet “<< i+1<<“t”;
cin>>marks[i];
total=total+marks[i];
}
}
 Void student :: printstuddetails()
 {
 Cout<<“Rollno t:t”<<rollno;
 Cout<<“Name t:t”<<namel
 Cout<<“Marks Details”;
 For(int i=0;i<5;i++)
 {
 Cout<<“Subject “<<i+1<<“t:t”<<marks[i];
 }
 Cout<<“total t:t “<<total;
 Cout<<“Average t :t “<<average;
 }
Array of Objects
 As we can declare array of integer, float, characters and array of
structure variables in the same way C++ also supports Array of objects
also.
 An array of objects is declared in the same way as we had declared
array of structure variables.
Example:- In continuation with the previous
example of array within a class
 Void main()
 {
 Student xa[10];
 Cout<<“Enter detail of 10 students of x a class”;
 for(int i=;i<10;i++)
 {
 Xa[i].getstuddetails();
 }
 Cout<<“Details entered by you are shown below”;
 For(i=0;i<10;i++)
 {
 Xa[i].printstuddetails();
 }
 }
Nested Class
As of nested condition (conditions within conditions) and nested loops (loops
within loop). We can also declare Nested class.
 A class declared within another class is called a nested class.
 The outer class is known as enclosing class.
 The inner class is known as nested class.
 We can declare the inner class (nested class) in any section of the outer
class (enclosing class) i.e. private , public or protected.
 If we declare inner class in private section then we will be able to declare
the objects of inner class within outer class only or you can’t declare object
of inner class (declared in private section) Outside the outer class(its
enclosing class).
 If the nested class definition in under public section the object of
inner class can be declared outside the outer class but by specifying
full qualified names. Only.
Example:
Outerclassname :: innerclassname objname;
Example 1:- Nested class declared in private
section
Functions in a Class
Different type of functions can be declared within a Class.
 Inline function
 Constant functions
 Nested functions
Inline functions
 It is an enhancement of C++ to speed up the execution of a program.
 Coding of inline function is same as normal function but the definition
of inline function starts / precedes with the keyword inline.
 Difference between normal and inline function is the different
compilation process of them.
Execution process of a normal function
 1001 int a=4, b=7; Memory loaded code scenario
 1002 int c= a+b, d; with memory addresses of
 1003 d=square ( c); instruction to be executed.
 1004 cout<<d;
 2011int square(int i)
 {
 Return i*I;
 }
Whenever in the execution of a program a function call takes place a
lot of function calling overheads involved.
 The address of the next instruction ( nest to the function calling
instruction) is saved in the memory.
i.e. 1004 address will be saved in the memory
 The argument passed to function will be copied into system stack
(local variable storage area) i.e. value of c (11) will be loaded into
stack.
 Jump to the memory address of called function i.e. jump to 2011
address
 Execute the function i.e. calculate 11 X 11 and return the result
 Store the return value into d.
 Fetch the address saved in step 1 and jump to that address (1004)
start further execution.
Array within a class

Mais conteúdo relacionado

Mais procurados

class and objects
class and objectsclass and objects
class and objects
Payel Guria
 

Mais procurados (20)

Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
class and objects
class and objectsclass and objects
class and objects
 
array of object pointer in c++
array of object pointer in c++array of object pointer in c++
array of object pointer in c++
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
C functions
C functionsC functions
C functions
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Function overloading and overriding
Function overloading and overridingFunction overloading and overriding
Function overloading and overriding
 
Storage classes in C
Storage classes in CStorage classes in C
Storage classes in C
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Strings
StringsStrings
Strings
 
File in C language
File in C languageFile in C language
File in C language
 
Functions in C
Functions in CFunctions in C
Functions in C
 

Destaque

Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Array in c language
Array in c languageArray in c language
Array in c language
home
 
structure and union
structure and unionstructure and union
structure and union
student
 

Destaque (20)

Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Array in C
Array in CArray in C
Array in C
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays
ArraysArrays
Arrays
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Type Casting in C++
Type Casting in C++Type Casting in C++
Type Casting in C++
 
Ms word Part 2
Ms  word Part 2Ms  word Part 2
Ms word Part 2
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Structure in c
Structure in cStructure in c
Structure in c
 
Structure in c
Structure in cStructure in c
Structure in c
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Structure in C
Structure in CStructure in C
Structure in C
 
structure and union
structure and unionstructure and union
structure and union
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
0. Course Introduction
0. Course Introduction0. Course Introduction
0. Course Introduction
 

Semelhante a Array within a class

Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
SURBHI SAROHA
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
DeepasCSE
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
Kumar
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
Saurav Kumar
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
trixiacruz
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
Rahul04August
 

Semelhante a Array within a class (20)

Bc0037
Bc0037Bc0037
Bc0037
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)Object Oriented Programming using C++(UNIT 1)
Object Oriented Programming using C++(UNIT 1)
 
Core java oop
Core java oopCore java oop
Core java oop
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
OOC MODULE1.pptx
OOC MODULE1.pptxOOC MODULE1.pptx
OOC MODULE1.pptx
 
Object oriented programming 2
Object oriented programming 2Object oriented programming 2
Object oriented programming 2
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptxINTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
INTRODUCTION TO OBJECT ORIENTED PROGRAMMING.pptx
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
 
Function class in c++
Function class in c++Function class in c++
Function class in c++
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)Lecture 4.2 c++(comlete reference book)
Lecture 4.2 c++(comlete reference book)
 
3 functions and class
3   functions and class3   functions and class
3 functions and class
 
The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210The Ring programming language version 1.9 book - Part 39 of 210
The Ring programming language version 1.9 book - Part 39 of 210
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
Functions and Modules.pptx
Functions and Modules.pptxFunctions and Modules.pptx
Functions and Modules.pptx
 
The purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdfThe purpose of this C++ programming project is to allow the student .pdf
The purpose of this C++ programming project is to allow the student .pdf
 
CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++CLASSES, STRUCTURE,UNION in C++
CLASSES, STRUCTURE,UNION in C++
 

Mais de AAKASH KUMAR

2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
AAKASH KUMAR
 

Mais de AAKASH KUMAR (20)

NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
NETWORKING AND COMMUNICATION || SLIDE 1 || TOPOLOGY AND PLACEMENT OF DEVICES|...
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Inheritance question
Inheritance questionInheritance question
Inheritance question
 
Header file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12THHeader file BASED QUESTION- CBSE CS CLASS 12TH
Header file BASED QUESTION- CBSE CS CLASS 12TH
 
Constructor & destructor based question- cbse cs class 12th
Constructor & destructor based question-  cbse cs class 12thConstructor & destructor based question-  cbse cs class 12th
Constructor & destructor based question- cbse cs class 12th
 
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAMCHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
CHOOSE THE CORRECT IDENTIFIER - Q.1 CBSE CS EXAM
 
Practical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12thPractical exam special- CBSE CS CLASS 12th
Practical exam special- CBSE CS CLASS 12th
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
STACK || FUNCTION WRITING BASED ON STACK || DATA STRUCTURE || LINKED LIST || ...
 
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
 
Inheritance question class 12th
Inheritance question class 12thInheritance question class 12th
Inheritance question class 12th
 
Ms word Part 1
Ms  word Part 1Ms  word Part 1
Ms word Part 1
 
Power point2007instruction
Power point2007instructionPower point2007instruction
Power point2007instruction
 
Html introduction Part-2
Html introduction Part-2Html introduction Part-2
Html introduction Part-2
 
Html Slide Part-1
Html Slide Part-1Html Slide Part-1
Html Slide Part-1
 
Evolution / history of Computer
Evolution / history of ComputerEvolution / history of Computer
Evolution / history of Computer
 
computer system
computer system computer system
computer system
 
Input Output Devices and Memory Unit
Input Output Devices and Memory UnitInput Output Devices and Memory Unit
Input Output Devices and Memory Unit
 
C++ programming Unit 5 flow of control
C++ programming Unit 5 flow of controlC++ programming Unit 5 flow of control
C++ programming Unit 5 flow of control
 
c++ programming Unit 4 operators
c++ programming Unit 4 operatorsc++ programming Unit 4 operators
c++ programming Unit 4 operators
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Último (20)

Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Array within a class

  • 1. Array within a Class AS WE HAVE ARRAYS WITHIN A STRUCTURE. IN THE SAME WE CAN HAVE ARRAYS AS A DATA MEMBER WITHIN A CLASS ALSO. THEY CAN BE DECLARED EITHER IN PRIVATE OR PROTECTED OR PUBLIC SECTION.
  • 2. Example:- Array as data member of Class  Class student  {  Int rollno;  Char name[50];  Int marks[5]; // arrary of 5 intgers variables to store marks in 5 subjects.  Int total;  Float average;  Public:  Void getstuddetails();  Void printstuddetails(); }; Void student:: getstuddetails() { cout<<“Enter rollno”; cin>>rollno; cout<<“Enter Name”; gets(name); total=0; cout<<“Enter marks in 5 sujects”; for(int i=0;i<5;i++) { cout<<“Subjet “<< i+1<<“t”; cin>>marks[i]; total=total+marks[i]; } }
  • 3.  Void student :: printstuddetails()  {  Cout<<“Rollno t:t”<<rollno;  Cout<<“Name t:t”<<namel  Cout<<“Marks Details”;  For(int i=0;i<5;i++)  {  Cout<<“Subject “<<i+1<<“t:t”<<marks[i];  }  Cout<<“total t:t “<<total;  Cout<<“Average t :t “<<average;  }
  • 4. Array of Objects  As we can declare array of integer, float, characters and array of structure variables in the same way C++ also supports Array of objects also.  An array of objects is declared in the same way as we had declared array of structure variables.
  • 5. Example:- In continuation with the previous example of array within a class  Void main()  {  Student xa[10];  Cout<<“Enter detail of 10 students of x a class”;  for(int i=;i<10;i++)  {  Xa[i].getstuddetails();  }  Cout<<“Details entered by you are shown below”;  For(i=0;i<10;i++)  {  Xa[i].printstuddetails();  }  }
  • 6. Nested Class As of nested condition (conditions within conditions) and nested loops (loops within loop). We can also declare Nested class.  A class declared within another class is called a nested class.  The outer class is known as enclosing class.  The inner class is known as nested class.  We can declare the inner class (nested class) in any section of the outer class (enclosing class) i.e. private , public or protected.  If we declare inner class in private section then we will be able to declare the objects of inner class within outer class only or you can’t declare object of inner class (declared in private section) Outside the outer class(its enclosing class).
  • 7.  If the nested class definition in under public section the object of inner class can be declared outside the outer class but by specifying full qualified names. Only. Example: Outerclassname :: innerclassname objname;
  • 8. Example 1:- Nested class declared in private section
  • 9. Functions in a Class Different type of functions can be declared within a Class.  Inline function  Constant functions  Nested functions
  • 10. Inline functions  It is an enhancement of C++ to speed up the execution of a program.  Coding of inline function is same as normal function but the definition of inline function starts / precedes with the keyword inline.  Difference between normal and inline function is the different compilation process of them.
  • 11. Execution process of a normal function  1001 int a=4, b=7; Memory loaded code scenario  1002 int c= a+b, d; with memory addresses of  1003 d=square ( c); instruction to be executed.  1004 cout<<d;  2011int square(int i)  {  Return i*I;  }
  • 12. Whenever in the execution of a program a function call takes place a lot of function calling overheads involved.  The address of the next instruction ( nest to the function calling instruction) is saved in the memory. i.e. 1004 address will be saved in the memory  The argument passed to function will be copied into system stack (local variable storage area) i.e. value of c (11) will be loaded into stack.  Jump to the memory address of called function i.e. jump to 2011 address
  • 13.  Execute the function i.e. calculate 11 X 11 and return the result  Store the return value into d.  Fetch the address saved in step 1 and jump to that address (1004) start further execution.