Professional Documents
Culture Documents
Lesson 4
Lesson 4
Lesson 4
4.1. Introduction
A structure is a data structure used to package several related variables into one unit.
The size of the structure is equal to the total size of all members.
4.2. Lesson objectives
By the end of this lesson the learner will be able to
• Define and explain applications of structure data type
• Explain advantages and disadvantages of structure
• Declare and use structure data type
4.3. Lesson outline
This lesson is structured as follows:
4.1. Introduction
4.2. Lesson objectives
4.3. Lesson outline
4.4. Declaration of structure
4.5. Access structure members
4.6. Using structure members
4.7. Revision questions
4.8. Summary
4.9. Suggested reading
Example: mary.age;
Advantages:
• They are easy to program
• They are easy to access at the same time
• Different variables can be declared under one name.
Disadvantages:
• Wastage of memory space
• All members are public by default
4.7. Revision questions
a)Explain two advantages and two disadvantages of structures.
b) Write a c++ program that uses structure as follows; create structure employee
whose members are age, height, weight and gender. Create objects
Henry,Charles for the structure.
4.8. Summary
In this lesson we have learnt about structure data structure. We have observed that the
structure allows several types of variables to use the same identifier. This strategy
ensures the variables are easy to access. However, we did observe that this structure
leads to wastage of memory space and that the members can be accessed publicly.
4.9. Suggested reading
[1]. Data structures using C and C++, 2nd Edition by Yedidyah Langsam, Aaron
J.Augenstein and Aaron M.Tenebaum: Pubslisher: Pearson.
[2]. Data structures and algorithms in c++ by Michael T.Goodrich,Robertio
Tamassia and David Mount: Publisher: Wiley
[3]. Fundamentals of data structures in c++ by Ellis Horowitz,Sartaj Sahni and
Dinesh Mehta.
Publisher:Galgotia
[4]. Introduction to data structures and algorithms with c++ by Glenn W.Rowe .
Publisher: Prentice Hall.