SlideShare a Scribd company logo
0
 Outline:
◦ Definition of Structures
◦ Array of structures
◦ Structure and functions
◦ Enumerated data type
 A structure in C++ are a group of data elements grouped together under
one name. these data elements known as a member of a structure.
 A structure type in C++ is called struct.
 A struct is heterogeneous in that it can be composed of data of different
types.
 In contrast, array is homogeneous since it can contain only data of the same
type.
1
 Unlike an array, a structure can contain many different data types (int,
string, bool, etc.).
 Structures hold data that belong together.
 Examples:
◦ Student record: student id, name, major, gender, start year, …
◦ Bank account: account number, name, currency, balance, …
◦ Address book: name, address, telephone number, …
 In database applications, structures are called records.
 Individual components of a struct type are called members (or fields).
2
 Members can be of different types (simple, array or
struct).
 A struct is named as a whole while individual members
are named using field identifiers.
 Complex data structures can be formed by defining
arrays of structs.
3
 The keyword ‘struct ‘ is used for creating a structure.
 The structure declaration appears at the top of the source code file
before any variables and structures are defined.
 Then inside the curly braces, you can declare one or more members
(declare variables inside curly braces) of that structure. For
example:
 Definition of a structure:
struct structure_name
{
data-type member-1;
data-type member-2;
data-type member-3;
data-type member-4;
} ;
4
 Example:
struct Date {
int day;
int month;
int year;
} ;
The “Date” structure
has 3 members,
day, month & year.
Notice the
required ;
5
 Example:
struct StudentInfo{
int Id;
int age;
char Gender;
double CGPA;
};
 Example:
struct StudentGrade{
char Name[15];
char Course[9];
int Lab[5];
int Homework[3];
int Exam[2];
};
The “StudentInfo”
structure has 4 members
of different types.
The “StudentGrade”
structure has 5
members of
different array types.
 struct names commonly begin with an uppercase
letter
 Multiple fields of same type can be in a comma-
separated list.
string name,address;
6
The “Person”
structure has 3 members
of different types.
7
 Struct declaration does not allocate memory or create
variables.
 To allocate memory spaces for structure members, we must
create an object which is called structure variable.
Let’s create a structure having 3 variable a, b, c.
Method 1:
struct structure_name
{
member definition;
member definition;
...
member definition;
} ;
struct structure_name a,b,c;
8
Method 2:
struct structure_name
{
member definition;
member definition;
...
member definition;
} ;
structure_name a,b,c;
Method 3
struct structure_name
{
member definition;
member definition;
...
member definition;
}a,b,c ;
 To access any member of a structure, we use the member access operator
(.). The member access operator is coded as a period between the structure
variable name and the structure member that we wish to access.
◦ structure variable name. structure member
9
p.name; is char array element of
structure p.
p.age; is the integer element of
structure p.
p.salary; is a float element of
structure p.
The “Person”
structure has 3 members
of different types.
name
age
salary
Person
name
age
salary
p
 To display the contents of a struct variable, you must display each field
separately, using the dot operator
struct Student
{
int studentID;
string name;
short year;
double gpa;
};
Student s1;
cout << s1; // won’t work!
cout << s1.studentID << endl;
cout << s1.name << endl;
cout << s1.year << endl;
cout << s1.gpa;
10
Wrong:
Correct
11
 Cannot initialize members in the structure declaration,
because no memory has been allocated yet.
struct Student // Illegal
{ //initialization
int studentID = 1145;
string name = "Alex";
short year = 1;
float gpa = 2.95;
};
12
 Structure members are initialized at the time a structure
variable is created.
 Can initialize a structure variable’s members with
either
◦ an initialization list
◦ a constructor
 An initialization list is an ordered set of values,
separated by commas and contained in { }, that
provides initial values for a set of data members.
{12, 6, 3} // initialization list
// with 3 values
13
 Order of list elements matters: The first value
initializes the first data member, the second value
initializes the second data member, etc.
 Elements of an initialization list can be constants,
variables, or expressions.
{12, W, L/W + 1} // initialization
//List with 3 items
14
Initialization list example:
struct Dimensions
{
int length,
int width,
int height;
};
Dimensions box = {12,6,3};
box
length 12
width 6
height 3
 Can initialize just some members, but cannot skip over
members.
Dimensions box1 = {12,6}; //OK
Dimensions box2 = {12,,3}; //illegal
 Can’t omit a value for a member without omitting values for all following members.
15
C++ Program to assign data to members of a structure variable and
display it.
Output
Enter Full name: abebe
kebede
Enter age: 27
Enter salary: 1024.4
Displaying Information.
Name: abebe kebede
Age: 27
Salary: 1024.4
 We can create an array of structures. thus we can use
the same structure for more than one variable which
adds more flexibility to your program.
 In another word array of structure means making the
structure variable an array.
 suppose we need to store the data of 100 students.
Declaring 100 separate variables of the structure is
definitely not a good option. For that, we need to create
an array of structures.
16
17
Example:
 We can also create an object of a structure in another
structure as members of a structure.
 If you have data like student information (name, id, age,
section), and the address of a person (kebele, kefle-Ketama,
and road name). what are you going to do? You must be
able to incorporate this type of data in other structs. The
following program declares two structs one for address and
the other for students.
18
19
 Structure variables can be passed to a function and returned in a similar way as
normal arguments.
 There are two methods by which we can pass structures to functions.
• Passing by Value
• Passing by Reference
 The call/pass-by value method of passing arguments to a function, copies the actual
value of an argument into the formal parameter of the function.
 In this case changes made to the parameter inside the function have no effect on the
argument.
 By default, C++ uses call-by-value to pass arguments. In general, this means that
code within a function cannot alter the arguments used to call the function.
20
 The call/pass by reference method of passing arguments to
a function, copies the reference of an argument into the
formal parameter.
 Inside the function, the reference is used to access the actual
argument used in the call. this means that changes made to
the parameter affect the passed arguments.
 To pass the value by reference, argument reference is
passed to the functions just like any other value.
21
22
23
24
25
 An enumeration is a user-defined data type that consists
of integral constants.
 Enums or enumerations are generally used when you
expect the variable to select one value from the
possible set of values.
 To define an enumeration, the keyword enum is used.
26
27
By default, spring is 0, summer is 1 and so on. You can change the default value of an
enum element during declaration (if necessary).
28
Method 1 Method 2
29
30
Thank you!!!

More Related Content

Similar to Chapter4.pptx

lec14.pdf
lec14.pdflec14.pdf
lec14.pdf
HEMAHEMS5
 
Structure & union
Structure & unionStructure & union
Structure & union
lalithambiga kamaraj
 
Unit 1_ADC.pptx
Unit 1_ADC.pptxUnit 1_ADC.pptx
Unit 1_ADC.pptx
Itsbrokenstatus
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
1. structure
1. structure1. structure
1. structure
hasan Mohammad
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
ashu awais
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
kavitham66441
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
Gem WeBlog
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
Abhishekkumarsingh630054
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
Tanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
tanmaymodi4
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
Chandrakant Divate
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
ansariparveen06
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
ParinayWadhwa
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
Ram Sagar Mourya
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
Prasanna Kumar SM
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
sangrampatil81
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
YOGESH SINGH
 
structures and unions in 'C'
structures and unions in 'C'structures and unions in 'C'
structures and unions in 'C'
illpa
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
psaravanan1985
 

Similar to Chapter4.pptx (20)

lec14.pdf
lec14.pdflec14.pdf
lec14.pdf
 
Structure & union
Structure & unionStructure & union
Structure & union
 
Unit 1_ADC.pptx
Unit 1_ADC.pptxUnit 1_ADC.pptx
Unit 1_ADC.pptx
 
Structure in C
Structure in CStructure in C
Structure in C
 
1. structure
1. structure1. structure
1. structure
 
Structure prespentation
Structure prespentation Structure prespentation
Structure prespentation
 
data structure and c programing concepts
data structure and c programing conceptsdata structure and c programing concepts
data structure and c programing concepts
 
Pointers and Structures
Pointers and StructuresPointers and Structures
Pointers and Structures
 
Chapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptxChapter 8 Structure Part 2 (1).pptx
Chapter 8 Structure Part 2 (1).pptx
 
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
 
Fundamentals of Structure in C Programming
Fundamentals of Structure in C ProgrammingFundamentals of Structure in C Programming
Fundamentals of Structure in C Programming
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
structures_v1.ppt
structures_v1.pptstructures_v1.ppt
structures_v1.ppt
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
Structure and Enum in c#
Structure and Enum in c#Structure and Enum in c#
Structure and Enum in c#
 
Structure in c language
Structure in c languageStructure in c language
Structure in c language
 
VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4VIT351 Software Development VI Unit4
VIT351 Software Development VI Unit4
 
structures and unions in 'C'
structures and unions in 'C'structures and unions in 'C'
structures and unions in 'C'
 
Unit 5 (1)
Unit 5 (1)Unit 5 (1)
Unit 5 (1)
 

Recently uploaded

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
JamalHussainArman
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 

Recently uploaded (20)

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptxML Based Model for NIDS MSc Updated Presentation.v2.pptx
ML Based Model for NIDS MSc Updated Presentation.v2.pptx
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 

Chapter4.pptx

  • 1. 0  Outline: ◦ Definition of Structures ◦ Array of structures ◦ Structure and functions ◦ Enumerated data type
  • 2.  A structure in C++ are a group of data elements grouped together under one name. these data elements known as a member of a structure.  A structure type in C++ is called struct.  A struct is heterogeneous in that it can be composed of data of different types.  In contrast, array is homogeneous since it can contain only data of the same type. 1
  • 3.  Unlike an array, a structure can contain many different data types (int, string, bool, etc.).  Structures hold data that belong together.  Examples: ◦ Student record: student id, name, major, gender, start year, … ◦ Bank account: account number, name, currency, balance, … ◦ Address book: name, address, telephone number, …  In database applications, structures are called records.  Individual components of a struct type are called members (or fields). 2
  • 4.  Members can be of different types (simple, array or struct).  A struct is named as a whole while individual members are named using field identifiers.  Complex data structures can be formed by defining arrays of structs. 3
  • 5.  The keyword ‘struct ‘ is used for creating a structure.  The structure declaration appears at the top of the source code file before any variables and structures are defined.  Then inside the curly braces, you can declare one or more members (declare variables inside curly braces) of that structure. For example:  Definition of a structure: struct structure_name { data-type member-1; data-type member-2; data-type member-3; data-type member-4; } ; 4  Example: struct Date { int day; int month; int year; } ; The “Date” structure has 3 members, day, month & year. Notice the required ;
  • 6. 5  Example: struct StudentInfo{ int Id; int age; char Gender; double CGPA; };  Example: struct StudentGrade{ char Name[15]; char Course[9]; int Lab[5]; int Homework[3]; int Exam[2]; }; The “StudentInfo” structure has 4 members of different types. The “StudentGrade” structure has 5 members of different array types.
  • 7.  struct names commonly begin with an uppercase letter  Multiple fields of same type can be in a comma- separated list. string name,address; 6 The “Person” structure has 3 members of different types.
  • 8. 7  Struct declaration does not allocate memory or create variables.  To allocate memory spaces for structure members, we must create an object which is called structure variable. Let’s create a structure having 3 variable a, b, c. Method 1: struct structure_name { member definition; member definition; ... member definition; } ; struct structure_name a,b,c;
  • 9. 8 Method 2: struct structure_name { member definition; member definition; ... member definition; } ; structure_name a,b,c; Method 3 struct structure_name { member definition; member definition; ... member definition; }a,b,c ;
  • 10.  To access any member of a structure, we use the member access operator (.). The member access operator is coded as a period between the structure variable name and the structure member that we wish to access. ◦ structure variable name. structure member 9 p.name; is char array element of structure p. p.age; is the integer element of structure p. p.salary; is a float element of structure p. The “Person” structure has 3 members of different types. name age salary Person name age salary p
  • 11.  To display the contents of a struct variable, you must display each field separately, using the dot operator struct Student { int studentID; string name; short year; double gpa; }; Student s1; cout << s1; // won’t work! cout << s1.studentID << endl; cout << s1.name << endl; cout << s1.year << endl; cout << s1.gpa; 10 Wrong: Correct
  • 12. 11  Cannot initialize members in the structure declaration, because no memory has been allocated yet. struct Student // Illegal { //initialization int studentID = 1145; string name = "Alex"; short year = 1; float gpa = 2.95; };
  • 13. 12  Structure members are initialized at the time a structure variable is created.  Can initialize a structure variable’s members with either ◦ an initialization list ◦ a constructor  An initialization list is an ordered set of values, separated by commas and contained in { }, that provides initial values for a set of data members. {12, 6, 3} // initialization list // with 3 values
  • 14. 13  Order of list elements matters: The first value initializes the first data member, the second value initializes the second data member, etc.  Elements of an initialization list can be constants, variables, or expressions. {12, W, L/W + 1} // initialization //List with 3 items
  • 15. 14 Initialization list example: struct Dimensions { int length, int width, int height; }; Dimensions box = {12,6,3}; box length 12 width 6 height 3  Can initialize just some members, but cannot skip over members. Dimensions box1 = {12,6}; //OK Dimensions box2 = {12,,3}; //illegal  Can’t omit a value for a member without omitting values for all following members.
  • 16. 15 C++ Program to assign data to members of a structure variable and display it. Output Enter Full name: abebe kebede Enter age: 27 Enter salary: 1024.4 Displaying Information. Name: abebe kebede Age: 27 Salary: 1024.4
  • 17.  We can create an array of structures. thus we can use the same structure for more than one variable which adds more flexibility to your program.  In another word array of structure means making the structure variable an array.  suppose we need to store the data of 100 students. Declaring 100 separate variables of the structure is definitely not a good option. For that, we need to create an array of structures. 16
  • 19.  We can also create an object of a structure in another structure as members of a structure.  If you have data like student information (name, id, age, section), and the address of a person (kebele, kefle-Ketama, and road name). what are you going to do? You must be able to incorporate this type of data in other structs. The following program declares two structs one for address and the other for students. 18
  • 20. 19
  • 21.  Structure variables can be passed to a function and returned in a similar way as normal arguments.  There are two methods by which we can pass structures to functions. • Passing by Value • Passing by Reference  The call/pass-by value method of passing arguments to a function, copies the actual value of an argument into the formal parameter of the function.  In this case changes made to the parameter inside the function have no effect on the argument.  By default, C++ uses call-by-value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function. 20
  • 22.  The call/pass by reference method of passing arguments to a function, copies the reference of an argument into the formal parameter.  Inside the function, the reference is used to access the actual argument used in the call. this means that changes made to the parameter affect the passed arguments.  To pass the value by reference, argument reference is passed to the functions just like any other value. 21
  • 23. 22
  • 24. 23
  • 25. 24
  • 26. 25
  • 27.  An enumeration is a user-defined data type that consists of integral constants.  Enums or enumerations are generally used when you expect the variable to select one value from the possible set of values.  To define an enumeration, the keyword enum is used. 26
  • 28. 27 By default, spring is 0, summer is 1 and so on. You can change the default value of an enum element during declaration (if necessary).
  • 30. 29