SlideShare a Scribd company logo
1 of 14
Data Structures
Software Development
Learning Intentions
By the end of this lesson learners will be able to:
❏ Describe disadvantages of using parallel arrays
❏ Create a user defined record
❏ Use these records to store collections of data
Let’s look at a more efficient way
For our BMI program we were storing 3 values in 3 parallel arrays:
1. Height
2. Weight
3. BMI
We can store these in one record structure where each one will have these 3 pieces of
data
Defining a record in Pseudocode
RECORD BMI:
Height : REAL
Weight: REAL
BMI: REAL
END RECORD
This defines a data structure that has 3 pieces of information.
But we will need to have an array of these as we will be holding details about numerous
people so...
Using a record in Pseudocode
If we need to declare a single BMI variable
❏ DECLARE BMIrecord AS BMI
And then to use the different ‘fields’ we can use the following:
❏ BMIrecord.height = 1.6
❏ BMIrecord.weight = 62.3
❏ BMIrecord.BMI = BMIrecord.weight * (BMIrecord.height ^ 2)
Let’s look at a single record in Python...
class BMI():
def __init__(self):
self.height = 0.0
self.weight = 0.0
self.BMI = 0.0
myBMI = BMI()
myBMI.height = 1.6
myBMI.weight = 62.3
myBMI.BMI = myBMI.weight / myBMI.height **2
print (myBMI.BMI)
Declares a class called BMI ( not officially a
record but is what we will use in Python
Declares a single BMI Record
And then assigns the values in the relevant
fields and then calculates the BMI
Displays the BMI we just calculated
But we will probably need more than one
As we want to store numerous records such as in the table shown below:
We will need to declare an array of records to
store each of the set of fields
Record
Number
Height Weight BMI
0 1.6 62.3 24.3
1 1.7 73.3 25.4
2 1.3 44.0 26.0
3 1.4 58.1 29.6
Declaring an array of records (EXAM)
Python doesn’t require you to declare variables with types explicitly as it is a loosely
typed language so in an exam situation if you were asked to store 40 BMI records you
could use:
DECLARE BMIDetails (39) AS BMI
Variable Name
RECORD BMI:
Height :
REAL
Weight:
REAL
BMI: REAL
END RECORD
Number of Elements
Variable Type
Record Structure
Using an array of records in Pseudocode
DECLARE BMIDetails (39) AS BMI
BMIDetails[0].height = 1.6
BMIDetails[0].weight = 62.3
This stores the following:
Record
Number
Height Weight BMI
0 1.6 62.3
1
Using an array of records in Pseudocode (cont)
BMIDetails[0].BMI = BMIDetails[0].weight / (BMIDetails[0].height ^ 2)
We have used the height and weight fields to calculate the BMI for the first record so are
now storing all of the data shown below:
Record
Number
Height Weight BMI
0 1.6 62.3 24.3
1
Next person(s)...
BMIDetails[1].height = 1.7
BMIDetails[1].weight = 73.3
BMIDetails[1].BMI = BMIDetails[1].weight / (BMIDetails[1].height ^ 2)
Record
Number
Height Weight BMI
0 1.6 62.3 24.3
1 1.7 73.3 25.4
And multiple ones (without a loop)
class BMI():
def __init__(self):
self.height = 0.0
self.weight = 0.0
self.BMI = 0.0
myBMI = [BMI() for x in range (40)]
myBMI[0].height = 1.6
myBMI[0].weight = 62.3
myBMI[0].BMI = myBMI[0].weight / myBMI[0].height **2
print (myBMI[0].BMI)
Declares a class called BMI ( not officially a
record but is what we will use in Python
Declares an array of 40 BMI Records
And then assigns the values to the fields
for the first records in element 0 of the
myBMI Array
Displays the first BMI we just calculated
It would be more efficient to use a loop
DECLARE BMIDetails (39) AS BMI
FOR i = 0 to LENGTH(BMIDetails)
BMIDetails[i].height = GET INPUT FROM USER
BMIDetails[i].weight = GET INPUT FROM USER
BMIDetails[i].BMI = BMIDetails[i].height / (BMIDetails[i].weight ^ 2)
NEXT LOOP
And multiple records in Python (with a loop)
class BMI():
def __init__(self):
self.height = 0.0
self.weight = 0.0
self.BMI = 0.0
myBMI = [BMI() for x in range (40)]
for x in range(len(myBMI)):
myBMI[x].height = float(input("Enter Height: "))
myBMI[x].weight = float(input("Enter Weight: "))
myBMI[x].BMI = roundmyBMI[x].weight / myBMI[x].height **2
print ("BMI = ", myBMI[x].BMI)
Loops through for the length of the array
Uses the loop counter [x] to
place the values at the specified
elements in the array

More Related Content

What's hot

Performance Evaluation for Classifiers tutorial
Performance Evaluation for Classifiers tutorialPerformance Evaluation for Classifiers tutorial
Performance Evaluation for Classifiers tutorial
Bilkent University
 

What's hot (20)

Presentation on Data Structure
Presentation on Data StructurePresentation on Data Structure
Presentation on Data Structure
 
Performance Evaluation for Classifiers tutorial
Performance Evaluation for Classifiers tutorialPerformance Evaluation for Classifiers tutorial
Performance Evaluation for Classifiers tutorial
 
Time complexity.ppt
Time complexity.pptTime complexity.ppt
Time complexity.ppt
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
 
Unit 3 dsa LINKED LIST
Unit 3 dsa LINKED LISTUnit 3 dsa LINKED LIST
Unit 3 dsa LINKED LIST
 
Python: Polymorphism
Python: PolymorphismPython: Polymorphism
Python: Polymorphism
 
Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo Azure Active Directory - External Identities Demo
Azure Active Directory - External Identities Demo
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Data structure tries
Data structure triesData structure tries
Data structure tries
 
Digital Search Tree
Digital Search TreeDigital Search Tree
Digital Search Tree
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Linked list
Linked listLinked list
Linked list
 
Sorting
SortingSorting
Sorting
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Multi ways trees
Multi ways treesMulti ways trees
Multi ways trees
 
Array in c++
Array in c++Array in c++
Array in c++
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Row major and column major in 2 d
Row major and column major in 2 dRow major and column major in 2 d
Row major and column major in 2 d
 
Data preprocessing in Machine learning
Data preprocessing in Machine learning Data preprocessing in Machine learning
Data preprocessing in Machine learning
 

Similar to 4.3 data structures records

Chapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docxChapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docx
tiffanyd4
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
josephineboon366
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
mallik3000
 

Similar to 4.3 data structures records (20)

VB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.pptVB_ERROR CONTROL_FILE HANDLING.ppt
VB_ERROR CONTROL_FILE HANDLING.ppt
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Chapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docxChapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docx
 
Lecture_01.2.pptx
Lecture_01.2.pptxLecture_01.2.pptx
Lecture_01.2.pptx
 
Bt0082 visual basic2
Bt0082 visual basic2Bt0082 visual basic2
Bt0082 visual basic2
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
(E Book) Asp .Net Tips, Tutorials And Code
(E Book) Asp .Net Tips,  Tutorials And Code(E Book) Asp .Net Tips,  Tutorials And Code
(E Book) Asp .Net Tips, Tutorials And Code
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...Managing user Online Training in IBM Netezza DBA Development by www.etraining...
Managing user Online Training in IBM Netezza DBA Development by www.etraining...
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
Algorithms the fundamentals, For computer Science.ppt
Algorithms the fundamentals, For computer Science.pptAlgorithms the fundamentals, For computer Science.ppt
Algorithms the fundamentals, For computer Science.ppt
 
C# Arrays
C# ArraysC# Arrays
C# Arrays
 
Ch5 array nota
Ch5 array notaCh5 array nota
Ch5 array nota
 
How to use a slicer to toggle measures in Power BI
How to use a slicer to toggle measures in Power BIHow to use a slicer to toggle measures in Power BI
How to use a slicer to toggle measures in Power BI
 
I am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdfI am having trouble writing the individual files for part 1, which i.pdf
I am having trouble writing the individual files for part 1, which i.pdf
 
Task 1
Task 1Task 1
Task 1
 
Python for data analysis
Python for data analysisPython for data analysis
Python for data analysis
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Python for Data Analysis.pdf
Python for Data Analysis.pdfPython for Data Analysis.pdf
Python for Data Analysis.pdf
 

More from missstevenson01

Lesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptxLesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptx
missstevenson01
 
Lesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptxLesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptx
missstevenson01
 

More from missstevenson01 (20)

S3 environment
S3 environmentS3 environment
S3 environment
 
The Processor.pptx
The Processor.pptxThe Processor.pptx
The Processor.pptx
 
How Computers Work
How Computers WorkHow Computers Work
How Computers Work
 
Lesson 3 - Coding with Minecraft - Variables.pptx
Lesson 3 -  Coding with Minecraft -  Variables.pptxLesson 3 -  Coding with Minecraft -  Variables.pptx
Lesson 3 - Coding with Minecraft - Variables.pptx
 
Lesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptxLesson 2 - Coding with Minecraft - Events.pptx
Lesson 2 - Coding with Minecraft - Events.pptx
 
Lesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptxLesson 1 - Coding with Minecraft -Introduction.pptx
Lesson 1 - Coding with Minecraft -Introduction.pptx
 
Lesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptxLesson2 - Coding with Minecraft - Events.pptx
Lesson2 - Coding with Minecraft - Events.pptx
 
Ethical hacking trojans, worms and spyware
Ethical hacking    trojans, worms and spywareEthical hacking    trojans, worms and spyware
Ethical hacking trojans, worms and spyware
 
Ethical hacking anti virus
Ethical hacking   anti virusEthical hacking   anti virus
Ethical hacking anti virus
 
Ethical hacking introduction to ethical hacking
Ethical hacking   introduction to ethical hackingEthical hacking   introduction to ethical hacking
Ethical hacking introduction to ethical hacking
 
S1 internet safety-chattingonline
S1 internet safety-chattingonlineS1 internet safety-chattingonline
S1 internet safety-chattingonline
 
S3 wireframe diagrams
S3 wireframe diagramsS3 wireframe diagrams
S3 wireframe diagrams
 
Sql
SqlSql
Sql
 
Alien database
Alien databaseAlien database
Alien database
 
Video Games and Copyright laws
Video Games and Copyright lawsVideo Games and Copyright laws
Video Games and Copyright laws
 
Games Design Document
Games Design DocumentGames Design Document
Games Design Document
 
Video game proposal
Video game proposalVideo game proposal
Video game proposal
 
Evaluation
EvaluationEvaluation
Evaluation
 
H evaluation
H evaluationH evaluation
H evaluation
 
H testing and debugging
H testing and debuggingH testing and debugging
H testing and debugging
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
demyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptxdemyelinated disorder: multiple sclerosis.pptx
demyelinated disorder: multiple sclerosis.pptx
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 

4.3 data structures records

  • 2. Learning Intentions By the end of this lesson learners will be able to: ❏ Describe disadvantages of using parallel arrays ❏ Create a user defined record ❏ Use these records to store collections of data
  • 3. Let’s look at a more efficient way For our BMI program we were storing 3 values in 3 parallel arrays: 1. Height 2. Weight 3. BMI We can store these in one record structure where each one will have these 3 pieces of data
  • 4. Defining a record in Pseudocode RECORD BMI: Height : REAL Weight: REAL BMI: REAL END RECORD This defines a data structure that has 3 pieces of information. But we will need to have an array of these as we will be holding details about numerous people so...
  • 5. Using a record in Pseudocode If we need to declare a single BMI variable ❏ DECLARE BMIrecord AS BMI And then to use the different ‘fields’ we can use the following: ❏ BMIrecord.height = 1.6 ❏ BMIrecord.weight = 62.3 ❏ BMIrecord.BMI = BMIrecord.weight * (BMIrecord.height ^ 2)
  • 6. Let’s look at a single record in Python... class BMI(): def __init__(self): self.height = 0.0 self.weight = 0.0 self.BMI = 0.0 myBMI = BMI() myBMI.height = 1.6 myBMI.weight = 62.3 myBMI.BMI = myBMI.weight / myBMI.height **2 print (myBMI.BMI) Declares a class called BMI ( not officially a record but is what we will use in Python Declares a single BMI Record And then assigns the values in the relevant fields and then calculates the BMI Displays the BMI we just calculated
  • 7. But we will probably need more than one As we want to store numerous records such as in the table shown below: We will need to declare an array of records to store each of the set of fields Record Number Height Weight BMI 0 1.6 62.3 24.3 1 1.7 73.3 25.4 2 1.3 44.0 26.0 3 1.4 58.1 29.6
  • 8. Declaring an array of records (EXAM) Python doesn’t require you to declare variables with types explicitly as it is a loosely typed language so in an exam situation if you were asked to store 40 BMI records you could use: DECLARE BMIDetails (39) AS BMI Variable Name RECORD BMI: Height : REAL Weight: REAL BMI: REAL END RECORD Number of Elements Variable Type Record Structure
  • 9. Using an array of records in Pseudocode DECLARE BMIDetails (39) AS BMI BMIDetails[0].height = 1.6 BMIDetails[0].weight = 62.3 This stores the following: Record Number Height Weight BMI 0 1.6 62.3 1
  • 10. Using an array of records in Pseudocode (cont) BMIDetails[0].BMI = BMIDetails[0].weight / (BMIDetails[0].height ^ 2) We have used the height and weight fields to calculate the BMI for the first record so are now storing all of the data shown below: Record Number Height Weight BMI 0 1.6 62.3 24.3 1
  • 11. Next person(s)... BMIDetails[1].height = 1.7 BMIDetails[1].weight = 73.3 BMIDetails[1].BMI = BMIDetails[1].weight / (BMIDetails[1].height ^ 2) Record Number Height Weight BMI 0 1.6 62.3 24.3 1 1.7 73.3 25.4
  • 12. And multiple ones (without a loop) class BMI(): def __init__(self): self.height = 0.0 self.weight = 0.0 self.BMI = 0.0 myBMI = [BMI() for x in range (40)] myBMI[0].height = 1.6 myBMI[0].weight = 62.3 myBMI[0].BMI = myBMI[0].weight / myBMI[0].height **2 print (myBMI[0].BMI) Declares a class called BMI ( not officially a record but is what we will use in Python Declares an array of 40 BMI Records And then assigns the values to the fields for the first records in element 0 of the myBMI Array Displays the first BMI we just calculated
  • 13. It would be more efficient to use a loop DECLARE BMIDetails (39) AS BMI FOR i = 0 to LENGTH(BMIDetails) BMIDetails[i].height = GET INPUT FROM USER BMIDetails[i].weight = GET INPUT FROM USER BMIDetails[i].BMI = BMIDetails[i].height / (BMIDetails[i].weight ^ 2) NEXT LOOP
  • 14. And multiple records in Python (with a loop) class BMI(): def __init__(self): self.height = 0.0 self.weight = 0.0 self.BMI = 0.0 myBMI = [BMI() for x in range (40)] for x in range(len(myBMI)): myBMI[x].height = float(input("Enter Height: ")) myBMI[x].weight = float(input("Enter Weight: ")) myBMI[x].BMI = roundmyBMI[x].weight / myBMI[x].height **2 print ("BMI = ", myBMI[x].BMI) Loops through for the length of the array Uses the loop counter [x] to place the values at the specified elements in the array