C-19

176 views

Published on

Published in: Education, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
176
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

C-19

  1. 1. Lecture 19Lecture 19 Version 1.0Version 1.0 StructureStructure
  2. 2. 2Rushdi Shams, Dept of CSE, KUET, Bangladesh What is StructureWhat is Structure  a ‘book’ is a collection of things such as title,a ‘book’ is a collection of things such as title, author, call number, publisher, number of pages,author, call number, publisher, number of pages, date of publication, etcdate of publication, etc  all this data is dissimilarall this data is dissimilar  author is a string, whereas number of pages is anauthor is a string, whereas number of pages is an integerinteger
  3. 3. 3Rushdi Shams, Dept of CSE, KUET, Bangladesh What is StructureWhat is Structure  For dealing with such collections, C provides aFor dealing with such collections, C provides a data type called ‘structure’data type called ‘structure’  A structure gathers together, different atoms ofA structure gathers together, different atoms of information that comprise a given entityinformation that comprise a given entity  We have seen earlier how ordinary variables canWe have seen earlier how ordinary variables can hold one piece of informationhold one piece of information  how arrays can hold a number of pieces ofhow arrays can hold a number of pieces of information of the same data typeinformation of the same data type
  4. 4. 4Rushdi Shams, Dept of CSE, KUET, Bangladesh What is StructureWhat is Structure  These two data types can handle a great varietyThese two data types can handle a great variety of situationsof situations  But quite often we deal with entities that areBut quite often we deal with entities that are collection of dissimilar data typescollection of dissimilar data types
  5. 5. 5Rushdi Shams, Dept of CSE, KUET, Bangladesh What is structureWhat is structure  to store data about a book. You might want toto store data about a book. You might want to storestore 1.1. its name (a string)its name (a string) 2.2. its price (a float)its price (a float) 3.3. number of pages in it (an int)number of pages in it (an int)
  6. 6. 6Rushdi Shams, Dept of CSE, KUET, Bangladesh What is StructureWhat is Structure  we can follow two approacheswe can follow two approaches 1.1. Construct individual arrays, one for storingConstruct individual arrays, one for storing names, another for storing prices and stillnames, another for storing prices and still another for storing number of pages.another for storing number of pages. 2.2. Use a structure variable.Use a structure variable.
  7. 7. 7Rushdi Shams, Dept of CSE, KUET, Bangladesh What is structureWhat is structure  Let us examine these two approaches one byLet us examine these two approaches one by oneone
  8. 8. Making things withMaking things with ArraysArrays
  9. 9. 9Rushdi Shams, Dept of CSE, KUET, Bangladesh
  10. 10. Making things withMaking things with StructuresStructures
  11. 11. 11Rushdi Shams, Dept of CSE, KUET, Bangladesh
  12. 12. Declaration of StructureDeclaration of Structure and Structure Variablesand Structure Variables
  13. 13. 13Rushdi Shams, Dept of CSE, KUET, Bangladesh
  14. 14. Initializing StructureInitializing Structure VariablesVariables
  15. 15. 15Rushdi Shams, Dept of CSE, KUET, Bangladesh
  16. 16. Accessing StructureAccessing Structure ElementsElements
  17. 17. 17Rushdi Shams, Dept of CSE, KUET, Bangladesh
  18. 18. 18Rushdi Shams, Dept of CSE, KUET, Bangladesh
  19. 19. Array of StructuresArray of Structures
  20. 20. 20Rushdi Shams, Dept of CSE, KUET, Bangladesh

×