• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
C-19
 

C-19

on

  • 119 views

 

Statistics

Views

Total Views
119
Views on SlideShare
119
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    C-19 C-19 Presentation Transcript

    • Lecture 19Lecture 19 Version 1.0Version 1.0 StructureStructure
    • 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
    • 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
    • 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
    • 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)
    • 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.
    • 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
    • Making things withMaking things with ArraysArrays
    • 9Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • Making things withMaking things with StructuresStructures
    • 11Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • Declaration of StructureDeclaration of Structure and Structure Variablesand Structure Variables
    • 13Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • Initializing StructureInitializing Structure VariablesVariables
    • 15Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • Accessing StructureAccessing Structure ElementsElements
    • 17Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • 18Rushdi Shams, Dept of CSE, KUET, Bangladesh
    • Array of StructuresArray of Structures
    • 20Rushdi Shams, Dept of CSE, KUET, Bangladesh