SlideShare a Scribd company logo
1 of 16
Download to read offline
CS215 - Lec 7  managing records collection
Storing collection of records.
Reading collection of records.
Writing collection of records.
Buffering Algorithm.
Dr. Hussien M.
Sharaf
2
Company info class only
represents single record.
A collection of records
needs to be stored into a
dynamic array.
The collection of records
can be encapsulated into a
class that maps to a file.
Dr. Hussien M.
Sharaf
3
Company1
Company2
…..
Company N
Dr. Hussien M.
Sharaf
4
CompanyInfoCollection
Structure
Record 3 Record 4Record 1 Record 2210 250 180 190
1. Store collection of records in a dynamic array
2. Store file full path name.
3. Store and manage the indexing of records.
Dr. Hussien M.
Sharaf
5
CompanyInfoCollection
Functionalities
Record 3 Record 4Record 1 Record 2210 250 180 190
1. Responsible for opening and closing of the file
stream.
2. Calling read or write of companyInfo without
knowing the details of read/write single line.
3. Manage the buffering of records while reading or
writing.
4. Count the number of records in a file.
Dr. Hussien M.
Sharaf
6
Algorithm#1 Writing collection of
records
Record 3 Record 4Record 1 Record 2210 250 180 190
While (len(Buffer) < bufferingSize)
{
companyInfo[i].writeIntoStream( stringStream)
stringStream<<recordDelimiter
i++
}
Stringstream>>Buffer
FileStream.write(Buffer)
Dr. Hussien M.
Sharaf
7
Algorithm#2 Reading collection
of records
Record 3 Record 4Record 1 Record 2210 250 180 190
FileStream.read(Buffer, BufferingSize+1)
Stringstream<<Buffer;
While (! Stringstream.EOF)
{
companyInfo[i].ReadFromStream(Stringstream)
i++
}
1. Read x MB into memory buffer (i.e.
char array).
2. Make sure to stop reading at the end of
a record. How can this be done?
3. Put the buffered data into a string
stream.
Dr. Hussien M.
Sharaf
8
4. Pass the string stream to an instance of
companyInfo which extracts fields.
5. Add the new companyInfo to the array
of records.
6. Manage the index by adding an entry
with the correct offset.
7. Repeat steps 1-6 until EOF
Dr. Hussien M.
Sharaf
9
Dr. Hussien M.
Sharaf
10
Store the byte offset of each record into a list stored in
another file.
Dr. Hussien M.
Sharaf
11
Remember Indexing
Problems:
1. Two files are used: one for the data and another for
CompanyName offset
IBM 0Record1
n
n
Google 211Record2 n
Microsoft 462Record3 n
ITE 643Record4 n
Dr. Hussien M.
Sharaf
12
class CompanyInfoCollection
{
private:
vector<CompanyInfo> Records;
RecordIndex recordIndexes;
public:
//read delimited fields
bool WriteDelimRecords(ostream& ,char);
//read delimited fields
bool readDelimRecords(istream&);
};
Dr. Hussien M.
Sharaf
13
Read/write from
streamBuffer
Single
companyInfo
RecordsCollection
File stream
Read/write from
streamBuffer
Single
companyInfo
Records Indexes
Record 2211 Record 3462
Continue using the CompanyInfo program:
1) Where would you put the following
functionalities:
a. Read the multiple records into a buffer.
b. Split a single record into fields.
c. Append a single record into a collection of
records.
d. Search for a record given a company
name.
Dr. Hussien M.
Sharaf
14
Continue using the CompanyInfo program:
2) Implement Algorithm#1 into the
CompanyInfo program.
3) Implement Algorithm#2 into the
CompanyInfo program.
Dr. Hussien M.
Sharaf
15
CS215 - Lec 7  managing records collection

More Related Content

Viewers also liked

Viewers also liked (20)

CS215 - Lec 10 b trees and hashing
CS215 - Lec 10   b trees and hashingCS215 - Lec 10   b trees and hashing
CS215 - Lec 10 b trees and hashing
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
CS215 - Lec 9 indexing and reclaiming space in files
CS215 - Lec 9  indexing and reclaiming space in filesCS215 - Lec 9  indexing and reclaiming space in files
CS215 - Lec 9 indexing and reclaiming space in files
 
CS215 - Lec 8 searching records
CS215 - Lec 8  searching recordsCS215 - Lec 8  searching records
CS215 - Lec 8 searching records
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
CS215 Lec 1 introduction
 
Compilers Final spring 2013 model answer
 Compilers Final spring 2013 model answer Compilers Final spring 2013 model answer
Compilers Final spring 2013 model answer
 
Model answer of compilers june spring 2013
Model answer of compilers june spring 2013Model answer of compilers june spring 2013
Model answer of compilers june spring 2013
 
File Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswerFile Organization & processing Mid term summer 2014 - modelanswer
File Organization & processing Mid term summer 2014 - modelanswer
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 
CS215 - Lec 3 single record operations
CS215 - Lec 3  single record operationsCS215 - Lec 3  single record operations
CS215 - Lec 3 single record operations
 
Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013Model answer of exam TC_spring 2013
Model answer of exam TC_spring 2013
 
Compilers midterm spring 2013 model answer
Compilers midterm spring 2013   model answerCompilers midterm spring 2013   model answer
Compilers midterm spring 2013 model answer
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
Lec4
Lec4Lec4
Lec4
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Infos2014
Infos2014Infos2014
Infos2014
 

Similar to CS215 - Lec 7 managing records collection

Good (enough) research data management practices
Good (enough) research data management practicesGood (enough) research data management practices
Good (enough) research data management practicesLeon Osinski
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingZainab Almugbel
 
MARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMaruthiRock
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in ElasticsearchImpetus Technologies
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systemsdonny101
 
File organization in database
File organization in databaseFile organization in database
File organization in databaseAfrasiyab Haider
 
File organization in database
File organization in databaseFile organization in database
File organization in databaseAfrasiyab Haider
 
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...Leons Petražickis
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
Application portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxApplication portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxAmanJain384694
 
File handling in qbasic
File handling in qbasicFile handling in qbasic
File handling in qbasicSmritiGurung4
 
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxСРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxssuser8719a6
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'eShikshak
 
Unit 4 data storage and querying
Unit 4   data storage and queryingUnit 4   data storage and querying
Unit 4 data storage and queryingRavindran Kannan
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data StructureProf Ansari
 
Report blocking ,management of files in secondry memory , static vs dynamic a...
Report blocking ,management of files in secondry memory , static vs dynamic a...Report blocking ,management of files in secondry memory , static vs dynamic a...
Report blocking ,management of files in secondry memory , static vs dynamic a...NoorMustafaSoomro
 

Similar to CS215 - Lec 7 managing records collection (20)

CS215 - Lec 6 record index
CS215 - Lec 6  record indexCS215 - Lec 6  record index
CS215 - Lec 6 record index
 
CS215 - Lec 5 record organization
CS215 - Lec 5  record organizationCS215 - Lec 5  record organization
CS215 - Lec 5 record organization
 
Good (enough) research data management practices
Good (enough) research data management practicesGood (enough) research data management practices
Good (enough) research data management practices
 
Ch 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashingCh 17 disk storage, basic files structure, and hashing
Ch 17 disk storage, basic files structure, and hashing
 
MARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptxMARUTHI_INVERTED_SEARCH_presentation.pptx
MARUTHI_INVERTED_SEARCH_presentation.pptx
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in Elasticsearch
 
File structures
File structuresFile structures
File structures
 
File structures
File structuresFile structures
File structures
 
Unit ivos - file systems
Unit ivos - file systemsUnit ivos - file systems
Unit ivos - file systems
 
File organization in database
File organization in databaseFile organization in database
File organization in database
 
File organization in database
File organization in databaseFile organization in database
File organization in database
 
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
IOD 2013 - Crunch Big Data in the Cloud with IBM BigInsights and Hadoop lab s...
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Application portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptxApplication portfolio development.advadisadvan.pptx
Application portfolio development.advadisadvan.pptx
 
File handling in qbasic
File handling in qbasicFile handling in qbasic
File handling in qbasic
 
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptxСРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
СРС АКТ Малошов Нұралы ВМ-МҚБ-11-23.pptx
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Unit 4 data storage and querying
Unit 4   data storage and queryingUnit 4   data storage and querying
Unit 4 data storage and querying
 
File Types in Data Structure
File Types in Data StructureFile Types in Data Structure
File Types in Data Structure
 
Report blocking ,management of files in secondry memory , static vs dynamic a...
Report blocking ,management of files in secondry memory , static vs dynamic a...Report blocking ,management of files in secondry memory , static vs dynamic a...
Report blocking ,management of files in secondry memory , static vs dynamic a...
 

More from Arab Open University and Cairo University (12)

Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 lec7   cfg
Cs419 lec7 cfg
 
Cs419 lec6 lexical analysis using nfa
Cs419 lec6   lexical analysis using nfaCs419 lec6   lexical analysis using nfa
Cs419 lec6 lexical analysis using nfa
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 
Cs419 Compiler lec1&2 introduction
Cs419 Compiler lec1&2  introductionCs419 Compiler lec1&2  introduction
Cs419 Compiler lec1&2 introduction
 
Final Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answersFinal Exam OS fall 2012-2013 with answers
Final Exam OS fall 2012-2013 with answers
 

Recently uploaded

How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesMohammad Hassany
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxKatherine Villaluna
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxEduSkills OECD
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRATanmoy Mishra
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsEugene Lysak
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 

Recently uploaded (20)

How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Human-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming ClassesHuman-AI Co-Creation of Worked Examples for Programming Classes
Human-AI Co-Creation of Worked Examples for Programming Classes
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
Practical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptxPractical Research 1 Lesson 9 Scope and delimitation.pptx
Practical Research 1 Lesson 9 Scope and delimitation.pptx
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptxPISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
PISA-VET launch_El Iza Mohamedou_19 March 2024.pptx
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRADUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
DUST OF SNOW_BY ROBERT FROST_EDITED BY_ TANMOY MISHRA
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
The Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George WellsThe Stolen Bacillus by Herbert George Wells
The Stolen Bacillus by Herbert George Wells
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 

CS215 - Lec 7 managing records collection

  • 2. Storing collection of records. Reading collection of records. Writing collection of records. Buffering Algorithm. Dr. Hussien M. Sharaf 2
  • 3. Company info class only represents single record. A collection of records needs to be stored into a dynamic array. The collection of records can be encapsulated into a class that maps to a file. Dr. Hussien M. Sharaf 3 Company1 Company2 ….. Company N
  • 4. Dr. Hussien M. Sharaf 4 CompanyInfoCollection Structure Record 3 Record 4Record 1 Record 2210 250 180 190 1. Store collection of records in a dynamic array 2. Store file full path name. 3. Store and manage the indexing of records.
  • 5. Dr. Hussien M. Sharaf 5 CompanyInfoCollection Functionalities Record 3 Record 4Record 1 Record 2210 250 180 190 1. Responsible for opening and closing of the file stream. 2. Calling read or write of companyInfo without knowing the details of read/write single line. 3. Manage the buffering of records while reading or writing. 4. Count the number of records in a file.
  • 6. Dr. Hussien M. Sharaf 6 Algorithm#1 Writing collection of records Record 3 Record 4Record 1 Record 2210 250 180 190 While (len(Buffer) < bufferingSize) { companyInfo[i].writeIntoStream( stringStream) stringStream<<recordDelimiter i++ } Stringstream>>Buffer FileStream.write(Buffer)
  • 7. Dr. Hussien M. Sharaf 7 Algorithm#2 Reading collection of records Record 3 Record 4Record 1 Record 2210 250 180 190 FileStream.read(Buffer, BufferingSize+1) Stringstream<<Buffer; While (! Stringstream.EOF) { companyInfo[i].ReadFromStream(Stringstream) i++ }
  • 8. 1. Read x MB into memory buffer (i.e. char array). 2. Make sure to stop reading at the end of a record. How can this be done? 3. Put the buffered data into a string stream. Dr. Hussien M. Sharaf 8
  • 9. 4. Pass the string stream to an instance of companyInfo which extracts fields. 5. Add the new companyInfo to the array of records. 6. Manage the index by adding an entry with the correct offset. 7. Repeat steps 1-6 until EOF Dr. Hussien M. Sharaf 9
  • 11. Store the byte offset of each record into a list stored in another file. Dr. Hussien M. Sharaf 11 Remember Indexing Problems: 1. Two files are used: one for the data and another for CompanyName offset IBM 0Record1 n n Google 211Record2 n Microsoft 462Record3 n ITE 643Record4 n
  • 12. Dr. Hussien M. Sharaf 12 class CompanyInfoCollection { private: vector<CompanyInfo> Records; RecordIndex recordIndexes; public: //read delimited fields bool WriteDelimRecords(ostream& ,char); //read delimited fields bool readDelimRecords(istream&); };
  • 13. Dr. Hussien M. Sharaf 13 Read/write from streamBuffer Single companyInfo RecordsCollection File stream Read/write from streamBuffer Single companyInfo Records Indexes Record 2211 Record 3462
  • 14. Continue using the CompanyInfo program: 1) Where would you put the following functionalities: a. Read the multiple records into a buffer. b. Split a single record into fields. c. Append a single record into a collection of records. d. Search for a record given a company name. Dr. Hussien M. Sharaf 14
  • 15. Continue using the CompanyInfo program: 2) Implement Algorithm#1 into the CompanyInfo program. 3) Implement Algorithm#2 into the CompanyInfo program. Dr. Hussien M. Sharaf 15