SlideShare a Scribd company logo
Writing and reading data back from a file.
Extraction operator VS getline function.
Write a single record on a file.
Read a single record from a file.
Build Company class.
Overload operators for the Company class.
Build template for programs.
Dr. Hussien M. Sharaf 2
What is the problem with reading data from files?
Since we are reading from files in form of streams of
bytes therefore we can not differentiate between
tokens.
Fortunately, the extraction operator in C++ can
tokenize streams.
But some fields could include more than one token.
Dr. Hussien M. Sharaf 3
Hussien M. Sharaf dr.sharaf@from-masr.com811 CS215
Name EmailID Course
Dr. Hussien M. Sharaf 4
ofstream: Stream class to write on files
ifstream: Stream class to read from files
fstream: Stream class to both read and
write from/to files.
Dr. Hussien M. Sharaf 5
Write the previous data into a text file then try
reading using:
1. Method: .get (buf,'n');
2. Method: .getline (buf,'n');
3. Function: getline (ifstream, string_Line,'n');
// Write a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line,token;
char buf[1000];
ofstream myfilePut
("example.txt",ios::trunc);
if (myfilePut.is_open())
{
myfilePut<<"Hussien M.
Sharafn";
}
Dr. Hussien M. Sharaf 7
myfilePut.close();
ifstream myfileGet ("example.txt");
if (myfileGet.is_open())
{ while (! myfileGet.eof())
{
//myfileGet >>token;
myfileGet.get (buf,'n');
line=buf;
myfileGet.seekg(0,ios::beg);
myfileGet.getline (buf,'n');
line=buf;
cout << line<< endl;
}
//clear flags any bad operation
myfileGet.clear();
myfileGet .seekg(0,ios::beg );
getline (myfileGet,line,'n');
cout << line<< endl;
//clear flags any bad operation
myfileGet.clear();
myfileGet .seekg(0,ios::beg );
//use exttaction op to read into buf
while (! myfileGet.eof())
{
myfileGet>>buf;
cout << buf<< endl;
}
Dr. Hussien M. Sharaf 8
//clear flags any bad operation
myfileGet.clear();
myfileGet .seekg(0,ios::beg );
//use exttaction op to read into string
while (! myfileGet.eof())
{
myfileGet>>line;
cout << line<< endl;
}
myfileGet .close();
}
else cout << "Unable to open file";
system("Pause");
return 0;}
Try reading using:
1. Extraction op.
2. Function: getline (ifstream,string_Line,'n');
myfileGet>>line;
getline (myfileGet,line,'n');
Does the extraction op. identify separators other
then space?
Dr. Hussien M. Sharaf 10
It was noticed that the extraction operator “>>”
reads until first token separator [space, “,”, “;”,
TAB, “r” ]
What are your suggestions for reading a collection
of fields?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
string ExtendstringLength(string In, int
requiredSize, string appendchar)
{
while (In.length()<requiredSize )
In=In.append(appendchar);
return In;
}
int main () {
string line,token;
int ID;
string FullName,Course,Email;
char buf[1000];
ID=811;
Dr. Hussien M. Sharaf 11
Course="CS215";
FullName ="Hussien M. Sharaf";
Email="dr.sharaf@from-masr.com";
Course.append("@");
FullName=ExtendstringLength(FullNam
e,20,"@");
Email =
ExtendstringLength(Email,50,"@");
ofstream myfilePut
("example.txt",ios::trunc);
if (myfilePut.is_open())
{
myfilePut<<ID<<Course<<FullName<<
Email ;
}
myfilePut.close();
ifstream myfileGet ("example.txt");
if (myfileGet.is_open())
{
myfileGet>>ID;
cout << ID<< endl;
myfileGet>>Course ;
cout << Course << endl;
//clear flags any bad
operation
myfileGet.clear();
myfileGet .seekg(0,ios::beg
);
myfileGet>>ID;
cout << ID<< endl;
myfileGet.get( buf,7) ;
Course=buf;
Dr. Hussien M. Sharaf 12
Course=Course.substr(0,5);
cout << Course << endl;
myfileGet.get( buf,21) ;
FullName=buf;
FullName
=FullName.erase(FullName.find("@"));
cout << FullName<< endl;
myfileGet.get( buf,51) ;
Email=buf;
Email=Email.erase(Email.find("@"));
cout << Email<< endl;
}
system("Pause");
return 0;
}
Dr. Hussien M. Sharaf 14
What are the required fields? And what are
their types?
1. CompanyName
2. ContactName
3. TitleofBusiness
4. Address
5. City
6. ZipCode
7. Phone
8. Fax
9. Email
10. WebSite
11. CompanyCode
12. CompanyDescription
Each field is qualified by double quotes “.
A screen shot of a file sample
#include <iostream>
using namespace std;
class Company{
string CompanyCode, CompanyDescription ,CompanyName,
ContactName, TitleofBusiness, Address,City, ZipCode, Phone, Fax,
Email, WebSite;
};
1. Write default constructor, copy constructor.
2. Overload “=” operator and “==” [optional]
3. Overload “<<” and “>>” for ostream and istream.
4. Write a driver that uses the above class to read a single line that
contain all fields of a company. Each field is quoted by double
quotes “field_Value” and separated from the next field by a comma ,
Example:
"155","All",“A-z Maintenance",“Malek",“-","902 Bestel Avenue - Garden Grove“,..
Dr. Hussien M. Sharaf 16
Dr. Hussien M. Sharaf 17
User Interface
Classes containing any
processing of data
//Declarations
while (ExitProgram!=true)
{ //take user choice
switch (UserChoice)
{ case 'I':
case 'i':
//handle user Choice
case'E':
case'e':ExitProgram=true; break;
}
}
system("pause");
Dr. Hussien M. Sharaf 18
1. Start by determining Output.
2. List the inputs.
3. Think about processing.
Check Ex 3:
Continue building a class for CompanyInfo:
1. Write default constructor, copy constructor.
2. Overload “=” operator and “==” [optional]
3. Overload “<<” and “>>” for ostream and istream and use
the delimiter method for reading and writing each field.
Each field is required to be enclosed inside two double
quotes i.e “…..”
Write a driver to use this class based on the template
Menu.
Dr. Hussien M. Sharaf 20
Next week is the deadline.
No excuses.
Don’t wait until last day.
I can help you to the highest limit within the next
3 days.
Dr. Hussien M. Sharaf 21
1. Delete the “bin” and “obj” folders.
2. Compress the solution folder using
winrar.
3. Rename the compressed file as follows:
StudentName_ID_A3.rar
4. Email to: n.abdelhameed@fci-cu.edu.eg
with your ID in the subject.
5. With subject: “FO – Assignment#3 -ID”
Dr. Hussien M. Sharaf 22
CS215 - Lec 3  single record operations

More Related Content

What's hot

File handling in c++
File handling in c++File handling in c++
File handling in c++
Daniel Nyagechi
 
File Pointers
File PointersFile Pointers
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
pinkpreet_kaur
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
snchnchl
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
HalaiHansaika
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
บทที่5
บทที่5บทที่5
บทที่5
Palm Unnop
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
Abdullah khawar
 
OOP Language Powerpoint
OOP Language PowerpointOOP Language Powerpoint
OOP Language Powerpoint
Angelia Nicole Dela Cruz
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
Mahendra Yadav
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
ProfSonaliGholveDoif
 
Data file handling
Data file handlingData file handling
Data file handling
TAlha MAlik
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 
File handling
File handlingFile handling
File handling
Nilesh Dalvi
 

What's hot (15)

File handling in c++
File handling in c++File handling in c++
File handling in c++
 
File Pointers
File PointersFile Pointers
File Pointers
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
 
Filesin c++
Filesin c++Filesin c++
Filesin c++
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
บทที่5
บทที่5บทที่5
บทที่5
 
Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)Pf cs102 programming-8 [file handling] (1)
Pf cs102 programming-8 [file handling] (1)
 
OOP Language Powerpoint
OOP Language PowerpointOOP Language Powerpoint
OOP Language Powerpoint
 
File Handling and Command Line Arguments in C
File Handling and Command Line Arguments in CFile Handling and Command Line Arguments in C
File Handling and Command Line Arguments in C
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Data file handling
Data file handlingData file handling
Data file handling
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
File handling
File handlingFile handling
File handling
 

Viewers also liked

Test video
Test videoTest video
Test video
DLML
 
Introducing Applied Ludology: Hands-on Methods for Game Design Research
Introducing Applied Ludology: Hands-on Methods for Game Design ResearchIntroducing Applied Ludology: Hands-on Methods for Game Design Research
Introducing Applied Ludology: Hands-on Methods for Game Design Research
Aki Järvinen
 
Introducing the LIS Research Coalition
Introducing the LIS Research CoalitionIntroducing the LIS Research Coalition
Introducing the LIS Research Coalition
Library and Information Science Research Coalition
 
Keep Calm and Make It Real
Keep Calm and Make It RealKeep Calm and Make It Real
Keep Calm and Make It Real
WiLS
 
Classified catalogue (Tony Vimal)
Classified  catalogue (Tony Vimal)Classified  catalogue (Tony Vimal)
Classified catalogue (Tony Vimal)
tonyviamll89
 
Catalogue Entry Format
Catalogue Entry FormatCatalogue Entry Format
Catalogue Entry Format
Sarika Sawant
 

Viewers also liked (6)

Test video
Test videoTest video
Test video
 
Introducing Applied Ludology: Hands-on Methods for Game Design Research
Introducing Applied Ludology: Hands-on Methods for Game Design ResearchIntroducing Applied Ludology: Hands-on Methods for Game Design Research
Introducing Applied Ludology: Hands-on Methods for Game Design Research
 
Introducing the LIS Research Coalition
Introducing the LIS Research CoalitionIntroducing the LIS Research Coalition
Introducing the LIS Research Coalition
 
Keep Calm and Make It Real
Keep Calm and Make It RealKeep Calm and Make It Real
Keep Calm and Make It Real
 
Classified catalogue (Tony Vimal)
Classified  catalogue (Tony Vimal)Classified  catalogue (Tony Vimal)
Classified catalogue (Tony Vimal)
 
Catalogue Entry Format
Catalogue Entry FormatCatalogue Entry Format
Catalogue Entry Format
 

Similar to CS215 - Lec 3 single record operations

C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
ANUSUYA S
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptxObject Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptxObject Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
RashidFaridChishti
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
C++ course start
C++ course startC++ course start
C++ course start
Net3lem
 
streams and files
 streams and files streams and files
streams and files
Mariam Butt
 
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
Arab Open University and Cairo University
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
Arab Open University and Cairo University
 
C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.
Mohamed Fawzy
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
File io
File ioFile io
cpp-file-handling
cpp-file-handlingcpp-file-handling
cpp-file-handling
zohaib ali ali
 
Cpp file-handling
Cpp file-handlingCpp file-handling
Cpp file-handling
JiaahRajpout123
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
Gaurav Singh
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
Arab Open University and Cairo University
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
sekar c
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
wkyra78
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
pavimalpani
 
File management in C++
File management in C++File management in C++
File management in C++
apoorvaverma33
 

Similar to CS215 - Lec 3 single record operations (20)

C++ - UNIT_-_V.pptx which contains details about File Concepts
C++  - UNIT_-_V.pptx which contains details about File ConceptsC++  - UNIT_-_V.pptx which contains details about File Concepts
C++ - UNIT_-_V.pptx which contains details about File Concepts
 
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptxObject Oriented Programming using C++: Ch12 Streams and Files.pptx
Object Oriented Programming using C++: Ch12 Streams and Files.pptx
 
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptxObject Oriented Programming Using C++: Ch12 Streams and Files.pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
 
CS215 Lec 1 introduction
CS215 Lec 1   introductionCS215 Lec 1   introduction
CS215 Lec 1 introduction
 
C++ course start
C++ course startC++ course start
C++ course start
 
streams and files
 streams and files streams and files
streams and files
 
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
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
CS215 - Lec 4 single record organization
CS215 - Lec 4  single record organizationCS215 - Lec 4  single record organization
CS215 - Lec 4 single record organization
 
C programming day#3.
C programming day#3.C programming day#3.
C programming day#3.
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
File io
File ioFile io
File io
 
cpp-file-handling
cpp-file-handlingcpp-file-handling
cpp-file-handling
 
Cpp file-handling
Cpp file-handlingCpp file-handling
Cpp file-handling
 
Srgoc dotnet
Srgoc dotnetSrgoc dotnet
Srgoc dotnet
 
CS215 - Lec 2 file organization
CS215 - Lec 2   file organizationCS215 - Lec 2   file organization
CS215 - Lec 2 file organization
 
Php interview questions
Php interview questionsPhp interview questions
Php interview questions
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
 
File management in C++
File management in C++File management in C++
File management in C++
 

More from Arab Open University and Cairo University

Infos2014
Infos2014Infos2014
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
Arab Open University and Cairo University
 
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
Arab Open University and Cairo University
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
Arab Open University and Cairo University
 
Lec4
Lec4Lec4
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
Arab Open University and Cairo University
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
Arab Open University and Cairo University
 
Theory of computation Lec1
Theory of computation Lec1Theory of computation Lec1
Theory of computation Lec1
Arab Open University and Cairo University
 
Theory of computation Lec7 pda
Theory of computation Lec7 pdaTheory of computation Lec7 pda
Theory of computation Lec7 pda
Arab Open University and Cairo University
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Cs419 lec8 top-down parsing
Cs419 lec8    top-down parsingCs419 lec8    top-down parsing
Cs419 lec8 top-down parsing
Arab Open University and Cairo University
 
Cs419 lec11 bottom-up parsing
Cs419 lec11   bottom-up parsingCs419 lec11   bottom-up parsing
Cs419 lec11 bottom-up parsing
Arab Open University and Cairo University
 
Cs419 lec12 semantic analyzer
Cs419 lec12  semantic analyzerCs419 lec12  semantic analyzer
Cs419 lec12 semantic analyzer
Arab Open University and Cairo University
 
Cs419 lec9 constructing parsing table ll1
Cs419 lec9   constructing parsing table ll1Cs419 lec9   constructing parsing table ll1
Cs419 lec9 constructing parsing table ll1
Arab Open University and Cairo University
 
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
Arab Open University and Cairo University
 
Cs419 lec7 cfg
Cs419 lec7   cfgCs419 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
Arab Open University and Cairo University
 
Cs419 lec5 lexical analysis using dfa
Cs419 lec5   lexical analysis using dfaCs419 lec5   lexical analysis using dfa
Cs419 lec5 lexical analysis using dfa
Arab Open University and Cairo University
 
Cs419 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
Arab Open University and Cairo University
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
Arab Open University and Cairo University
 

More from Arab Open University and Cairo University (20)

Infos2014
Infos2014Infos2014
Infos2014
 
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
 
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
 
Theory of computation Lec6
Theory of computation Lec6Theory of computation Lec6
Theory of computation Lec6
 
Lec4
Lec4Lec4
Lec4
 
Theory of computation Lec3 dfa
Theory of computation Lec3 dfaTheory of computation Lec3 dfa
Theory of computation Lec3 dfa
 
Theory of computation Lec2
Theory of computation Lec2Theory of computation Lec2
Theory of computation Lec2
 
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
 
Setup python with eclipse
Setup python with eclipseSetup python with eclipse
Setup python with eclipse
 
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 lec4 lexical analysis using re
Cs419 lec4   lexical analysis using reCs419 lec4   lexical analysis using re
Cs419 lec4 lexical analysis using re
 
Cs419 lec3 lexical analysis using re
Cs419 lec3   lexical analysis using reCs419 lec3   lexical analysis using re
Cs419 lec3 lexical analysis using re
 

Recently uploaded

Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
ScyllaDB
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
Ivo Velitchkov
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
Safe Software
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
LizaNolte
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Pitangent Analytics & Technology Solutions Pvt. Ltd
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-EfficiencyFreshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
Freshworks Rethinks NoSQL for Rapid Scaling & Cost-Efficiency
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Apps Break Data
Apps Break DataApps Break Data
Apps Break Data
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Essentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation ParametersEssentials of Automations: Exploring Attributes & Automation Parameters
Essentials of Automations: Exploring Attributes & Automation Parameters
 
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham HillinQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
inQuba Webinar Mastering Customer Journey Management with Dr Graham Hill
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
Crafting Excellence: A Comprehensive Guide to iOS Mobile App Development Serv...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

CS215 - Lec 3 single record operations

  • 1.
  • 2. Writing and reading data back from a file. Extraction operator VS getline function. Write a single record on a file. Read a single record from a file. Build Company class. Overload operators for the Company class. Build template for programs. Dr. Hussien M. Sharaf 2
  • 3. What is the problem with reading data from files? Since we are reading from files in form of streams of bytes therefore we can not differentiate between tokens. Fortunately, the extraction operator in C++ can tokenize streams. But some fields could include more than one token. Dr. Hussien M. Sharaf 3 Hussien M. Sharaf dr.sharaf@from-masr.com811 CS215 Name EmailID Course
  • 4. Dr. Hussien M. Sharaf 4
  • 5. ofstream: Stream class to write on files ifstream: Stream class to read from files fstream: Stream class to both read and write from/to files. Dr. Hussien M. Sharaf 5
  • 6. Write the previous data into a text file then try reading using: 1. Method: .get (buf,'n'); 2. Method: .getline (buf,'n'); 3. Function: getline (ifstream, string_Line,'n');
  • 7. // Write a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line,token; char buf[1000]; ofstream myfilePut ("example.txt",ios::trunc); if (myfilePut.is_open()) { myfilePut<<"Hussien M. Sharafn"; } Dr. Hussien M. Sharaf 7 myfilePut.close(); ifstream myfileGet ("example.txt"); if (myfileGet.is_open()) { while (! myfileGet.eof()) { //myfileGet >>token; myfileGet.get (buf,'n'); line=buf; myfileGet.seekg(0,ios::beg); myfileGet.getline (buf,'n'); line=buf; cout << line<< endl; }
  • 8. //clear flags any bad operation myfileGet.clear(); myfileGet .seekg(0,ios::beg ); getline (myfileGet,line,'n'); cout << line<< endl; //clear flags any bad operation myfileGet.clear(); myfileGet .seekg(0,ios::beg ); //use exttaction op to read into buf while (! myfileGet.eof()) { myfileGet>>buf; cout << buf<< endl; } Dr. Hussien M. Sharaf 8 //clear flags any bad operation myfileGet.clear(); myfileGet .seekg(0,ios::beg ); //use exttaction op to read into string while (! myfileGet.eof()) { myfileGet>>line; cout << line<< endl; } myfileGet .close(); } else cout << "Unable to open file"; system("Pause"); return 0;}
  • 9. Try reading using: 1. Extraction op. 2. Function: getline (ifstream,string_Line,'n'); myfileGet>>line; getline (myfileGet,line,'n'); Does the extraction op. identify separators other then space?
  • 10. Dr. Hussien M. Sharaf 10 It was noticed that the extraction operator “>>” reads until first token separator [space, “,”, “;”, TAB, “r” ] What are your suggestions for reading a collection of fields?
  • 11. #include <iostream> #include <fstream> #include <string> using namespace std; string ExtendstringLength(string In, int requiredSize, string appendchar) { while (In.length()<requiredSize ) In=In.append(appendchar); return In; } int main () { string line,token; int ID; string FullName,Course,Email; char buf[1000]; ID=811; Dr. Hussien M. Sharaf 11 Course="CS215"; FullName ="Hussien M. Sharaf"; Email="dr.sharaf@from-masr.com"; Course.append("@"); FullName=ExtendstringLength(FullNam e,20,"@"); Email = ExtendstringLength(Email,50,"@"); ofstream myfilePut ("example.txt",ios::trunc); if (myfilePut.is_open()) { myfilePut<<ID<<Course<<FullName<< Email ; } myfilePut.close();
  • 12. ifstream myfileGet ("example.txt"); if (myfileGet.is_open()) { myfileGet>>ID; cout << ID<< endl; myfileGet>>Course ; cout << Course << endl; //clear flags any bad operation myfileGet.clear(); myfileGet .seekg(0,ios::beg ); myfileGet>>ID; cout << ID<< endl; myfileGet.get( buf,7) ; Course=buf; Dr. Hussien M. Sharaf 12 Course=Course.substr(0,5); cout << Course << endl; myfileGet.get( buf,21) ; FullName=buf; FullName =FullName.erase(FullName.find("@")); cout << FullName<< endl; myfileGet.get( buf,51) ; Email=buf; Email=Email.erase(Email.find("@")); cout << Email<< endl; } system("Pause"); return 0; }
  • 13.
  • 14. Dr. Hussien M. Sharaf 14 What are the required fields? And what are their types? 1. CompanyName 2. ContactName 3. TitleofBusiness 4. Address 5. City 6. ZipCode 7. Phone 8. Fax 9. Email 10. WebSite 11. CompanyCode 12. CompanyDescription
  • 15. Each field is qualified by double quotes “. A screen shot of a file sample
  • 16. #include <iostream> using namespace std; class Company{ string CompanyCode, CompanyDescription ,CompanyName, ContactName, TitleofBusiness, Address,City, ZipCode, Phone, Fax, Email, WebSite; }; 1. Write default constructor, copy constructor. 2. Overload “=” operator and “==” [optional] 3. Overload “<<” and “>>” for ostream and istream. 4. Write a driver that uses the above class to read a single line that contain all fields of a company. Each field is quoted by double quotes “field_Value” and separated from the next field by a comma , Example: "155","All",“A-z Maintenance",“Malek",“-","902 Bestel Avenue - Garden Grove“,.. Dr. Hussien M. Sharaf 16
  • 17. Dr. Hussien M. Sharaf 17 User Interface Classes containing any processing of data
  • 18. //Declarations while (ExitProgram!=true) { //take user choice switch (UserChoice) { case 'I': case 'i': //handle user Choice case'E': case'e':ExitProgram=true; break; } } system("pause"); Dr. Hussien M. Sharaf 18
  • 19. 1. Start by determining Output. 2. List the inputs. 3. Think about processing.
  • 20. Check Ex 3: Continue building a class for CompanyInfo: 1. Write default constructor, copy constructor. 2. Overload “=” operator and “==” [optional] 3. Overload “<<” and “>>” for ostream and istream and use the delimiter method for reading and writing each field. Each field is required to be enclosed inside two double quotes i.e “…..” Write a driver to use this class based on the template Menu. Dr. Hussien M. Sharaf 20
  • 21. Next week is the deadline. No excuses. Don’t wait until last day. I can help you to the highest limit within the next 3 days. Dr. Hussien M. Sharaf 21
  • 22. 1. Delete the “bin” and “obj” folders. 2. Compress the solution folder using winrar. 3. Rename the compressed file as follows: StudentName_ID_A3.rar 4. Email to: n.abdelhameed@fci-cu.edu.eg with your ID in the subject. 5. With subject: “FO – Assignment#3 -ID” Dr. Hussien M. Sharaf 22