SlideShare a Scribd company logo
OOP
       Object Oriented Programming


            Lab - 13
IDE
   Microsoft Visual C++ 6.0


                           Sajid Ali Gillal
File
Files
• A file is a collection of data in mass storage.
• A data file is not a part of a program’s source
  code.
• The same file can be read or modified by
  different programs.
• The program must be aware of the format of
  the data in the file.
Files (cont’d)
• The file system is maintained by the
  operating system.
• The system provides commands and/or GUI
  utilities for viewing file directories and for
  copying, moving, renaming, and deleting
  files.
• The system also provides “core” functions,
  callable from programs, for reading and
  writing directories and files.
File
 Random Access File
          &
Sequential Access File
Sequential Files
Sequential file techniques provide a straightforward way to read and write
files. Basic's sequential file commands manipulate text files: files of ASCII
characters with carriage-return/linefeed pairs separating records.

In computer science, sequential access means that a group of elements (e.g.
data in a memory array or a disk file or on a tape) is accessed in a
predetermined, ordered sequence. Sequential access is sometimes the only
way of accessing the data, for example if it is on a tape. It may also be the
access method of choice, for example if we simply want to process a
sequence of data elements in order.
Random Access Files
Random access files consist of records that can be accessed in any sequence.
This means the data is stored exactly as it appears in memory, thus saving
processing time (because no translation is necessary) both in when the file is
written and in when it is read.


In computer science, random access (sometimes called direct access) is the
ability to access an arbitrary element of a sequence in equal time.
Random-Access Files
• A program can start reading or writing a
  random-access file at any place and read or
  write any number of bytes at a time.
• “Random-access file” is an abstraction: any
  file can be treated as a random-access file.
• You can open a random-access file both for
  reading and writing at the same time.
Random-Access Files (cont’d)

• A binary file containing fixed-length data
  records is suitable for random-access
  treatment.
• A random-access file may be accompanied
  by an “index” (either in the same or a
  different file), which tells the address of each
  record.
File Types


            Text
File                  Binary




           Stream
                   Random-Access


                                 common use
                                 possible, but
                               not as common
What You Will Learn




        Create files
                       Write files

Read files




  Update files
Random Access Files
 A RandomAccessFile employs an internal pointer that points to the next
  byte to read.
 This pointer is zero-based and the first byte is indicated by index 0.
 When first created, a RandomAccessFile points to the first byte.
 You can change the pointer's position by invoking the different methods.
 The skipBytes method moves the pointer by the specified number of
  bytes.
 If offset number of bytes would pass the end of file, the internal pointer
  will only move to as much as the end of file.
How do I read an int
from a file?
"r".    Open for reading only.

"rw“.   Open for reading and writing.
          If the file does not already exist, Random Access
          File creates the file.

"rws". Open for reading and writing and require that every
       update to the file's content and metadata be written
       synchronously.

"rwd". Open for reading and writing and require that every
       update to the file's content (but not metadata) be
       written synchronously.
(“C:Documents and Settings01-113082-009DesktopABCRose.txt”);
Create File                                P1.cpp



     #include <fstream>
     #include <iostream>
     using namespace std;

     void main( )
     {
       ofstream Savefile("D:Rose.txt");


     }
(“C:Documents and Settings01-113082-009DesktopABCRose.txt”);
Create File                                      Q1.cpp



       #include <fstream>
       #include <iostream>
       using namespace std;

       void main( )
       {
         ofstream Savefile("D:Rose.txt");

           Savefile<< "Sajid Ali Gillal";

       }



 May 21, 2010                 Sajid Ali Gillal      20
File output with strings or lines of output              P4.cpp


#include <fstream.h>

void main( )
{
      ofstream outfile("E:Rose.txt");

          outfile << "This is first line of Gillal Programn";
          outfile << "This is second line of Gillal Programn";
          outfile << "This is third line of Gillal Programn";

}




 May 21, 2010                 Sajid Ali Gillal              21
File input with characters                      P2.cpp


     #include <fstream>
     #include <iostream>

     using namespace std;

     void main( )
     {
           char ch;
           ifstream Readfile("D:Rose.txt");
           while(Readfile)
           {
                  Readfile.get(ch);
                  cout << ch;
           }
           cout << endl;

     }
 May 21, 2010                Sajid Ali Gillal     22
file output with characters                                      P5.cpp

#include <fstream>
#include <iostream>
#include <string>
using namespace std;

void main( )
{
      string str = "If you start judging the people then
                                   you will have no time to love them!";
            ofstream Savefile("E:Rose.txt");

            Savefile<<str;
            cout << "File writtenn";

}
    May 21, 2010               Sajid Ali Gillal                     23
Reads person (full object) from disk                                        P6.cpp
#include <fstream.h>                        void main( )
#include <iostream.h>                       {
#include <stdio.h>
#include <conio.h>                          person pers;     //create person variable
                                                    FILE *ptr;
class person                                        ptr = fopen("E:data2.txt","w");
{                                                   fread(&pers,sizeof(pers),1,ptr);
protected:                                          pers.showData();
char name[80]; //person's name                      getch();
short age;     //person's age
                                            }
public:
void showData( ) //display person's data
{
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
        }
};
   May 21, 2010                      Sajid Ali Gillal                           24
Save person (full object) to disk                                          P7.cpp
#include <fstream.h>                       void main( )
#include <iostream.h>                      {
#include <stdio.h>                         person pers; //create a person
                                           pers.getData(); //get data for person
class person
{                                          FILE *ptr;
protected:                                 ptr = fopen("E:Rose.dat","wb");
char name[80];      //person's name        fwrite(&pers,sizeof(pers),1,ptr);
short age;          //person's age         fclose(ptr);
public:                                    }
void getData()    //get person's data
        {
cout << "Enter name: ";
cin >> name;
cout << "Enter age: ";
cin >> age;
        }
};
   May 21, 2010                     Sajid Ali Gillal                           25
OOP


      Object Oriented Programming




                                    Sajid Ali Gillal

May 21, 2010     Sajid Ali Gillal                      26

More Related Content

What's hot

Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
ESUG
 
Redis/Lessons learned
Redis/Lessons learnedRedis/Lessons learned
Redis/Lessons learned
Tit Petric
 
File system
File systemFile system
File system
Gayane Aslanyan
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
Prakash Pimpale
 
Large scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azureLarge scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azure
cloudbeatsch
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
Quỳnh Phan
 
Swift 4 : Codable
Swift 4 : CodableSwift 4 : Codable
Swift 4 : Codable
SeongGyu Jo
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2
Itamar Haber
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
Eric Bottard
 
Tutorial on Node File System
Tutorial on Node File SystemTutorial on Node File System
Tutorial on Node File System
iFour Technolab Pvt. Ltd.
 
Full Text search in Django with Postgres
Full Text search in Django with PostgresFull Text search in Django with Postgres
Full Text search in Django with Postgres
syerram
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)
Itamar Haber
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
Mudasir Syed
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
Prof. Wim Van Criekinge
 
Introducing FSter
Introducing FSterIntroducing FSter
Introducing FSter
itsmesrl
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with Gluster
Gluster.org
 
Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501
Jinho Kim
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
Charles Anderson
 

What's hot (20)

Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
Redis/Lessons learned
Redis/Lessons learnedRedis/Lessons learned
Redis/Lessons learned
 
File system
File systemFile system
File system
 
Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics Natural Language Toolkit (NLTK), Basics
Natural Language Toolkit (NLTK), Basics
 
Large scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azureLarge scale nlp using python's nltk on azure
Large scale nlp using python's nltk on azure
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoop
 
Hawk presentation
Hawk presentationHawk presentation
Hawk presentation
 
Cscope and ctags
Cscope and ctagsCscope and ctags
Cscope and ctags
 
Swift 4 : Codable
Swift 4 : CodableSwift 4 : Codable
Swift 4 : Codable
 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring Data
 
Tutorial on Node File System
Tutorial on Node File SystemTutorial on Node File System
Tutorial on Node File System
 
Full Text search in Django with Postgres
Full Text search in Django with PostgresFull Text search in Django with Postgres
Full Text search in Django with Postgres
 
Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)Redis Indices (#RedisTLV)
Redis Indices (#RedisTLV)
 
Filing system in PHP
Filing system in PHPFiling system in PHP
Filing system in PHP
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge
 
Introducing FSter
Introducing FSterIntroducing FSter
Introducing FSter
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with Gluster
 
Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to Redis
 

Viewers also liked

Part 5 create sequence increment value using negative value
Part 5 create sequence increment value using negative valuePart 5 create sequence increment value using negative value
Part 5 create sequence increment value using negative value
Girija Muscut
 
Cognitive information science
Cognitive information scienceCognitive information science
Cognitive information science
S. Kate Devitt
 
Debugging in visual studio (basic level)
Debugging in visual studio (basic level)Debugging in visual studio (basic level)
Debugging in visual studio (basic level)
Larry Nung
 
Prolog -Cpt114 - Week3
Prolog -Cpt114 - Week3Prolog -Cpt114 - Week3
Prolog -Cpt114 - Week3a_akhavan
 
Part2 database connection service based using vb.net
Part2 database connection service based using vb.netPart2 database connection service based using vb.net
Part2 database connection service based using vb.net
Girija Muscut
 
Part 1 picturebox using vb.net
Part 1 picturebox using vb.netPart 1 picturebox using vb.net
Part 1 picturebox using vb.net
Girija Muscut
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.net
Girija Muscut
 
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uPython Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uNikola Plejic
 
Making Information Usable: The Art & Science of Information Design
Making Information Usable: The Art & Science of Information DesignMaking Information Usable: The Art & Science of Information Design
Making Information Usable: The Art & Science of Information Design
Hubbard One
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15Niit Care
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++
Microsoft
 
Pioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
Pioneers of Information Science in Europe: The Oeuvre of Norbert HenrichsPioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
Pioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
Wolfgang Stock
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
shannonsdavis
 
Information Overload and Information Science / Mieczysław Muraszkiewicz
Information Overload and Information Science / Mieczysław MuraszkiewiczInformation Overload and Information Science / Mieczysław Muraszkiewicz
Information Overload and Information Science / Mieczysław Muraszkiewicz
Zakład Systemów Informacyjnych, Instytut Informacji Naukowej i Studiów Bibliologicznych (UW)
 
How Not To Be Seen
How Not To Be SeenHow Not To Be Seen
How Not To Be Seen
Mark Pesce
 
Logical Programming With ruby-prolog
Logical Programming With ruby-prologLogical Programming With ruby-prolog
Logical Programming With ruby-prolog
Preston Lee
 
Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.net
Girija Muscut
 
Transforming the world with Information technology
Transforming the world with Information technologyTransforming the world with Information technology
Transforming the world with Information technology
Glenn Klith Andersen
 
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
RuleML
 

Viewers also liked (20)

Presentation1
Presentation1Presentation1
Presentation1
 
Part 5 create sequence increment value using negative value
Part 5 create sequence increment value using negative valuePart 5 create sequence increment value using negative value
Part 5 create sequence increment value using negative value
 
Cognitive information science
Cognitive information scienceCognitive information science
Cognitive information science
 
Debugging in visual studio (basic level)
Debugging in visual studio (basic level)Debugging in visual studio (basic level)
Debugging in visual studio (basic level)
 
Prolog -Cpt114 - Week3
Prolog -Cpt114 - Week3Prolog -Cpt114 - Week3
Prolog -Cpt114 - Week3
 
Part2 database connection service based using vb.net
Part2 database connection service based using vb.netPart2 database connection service based using vb.net
Part2 database connection service based using vb.net
 
Part 1 picturebox using vb.net
Part 1 picturebox using vb.netPart 1 picturebox using vb.net
Part 1 picturebox using vb.net
 
Part 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.netPart 8 add,update,delete records using records operation buttons in vb.net
Part 8 add,update,delete records using records operation buttons in vb.net
 
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-uPython Tools for Visual Studio: Python na Microsoftovom .NET-u
Python Tools for Visual Studio: Python na Microsoftovom .NET-u
 
Making Information Usable: The Art & Science of Information Design
Making Information Usable: The Art & Science of Information DesignMaking Information Usable: The Art & Science of Information Design
Making Information Usable: The Art & Science of Information Design
 
Vb.net session 15
Vb.net session 15Vb.net session 15
Vb.net session 15
 
What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++What&rsquo;s new in Visual C++
What&rsquo;s new in Visual C++
 
Pioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
Pioneers of Information Science in Europe: The Oeuvre of Norbert HenrichsPioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
Pioneers of Information Science in Europe: The Oeuvre of Norbert Henrichs
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Information Overload and Information Science / Mieczysław Muraszkiewicz
Information Overload and Information Science / Mieczysław MuraszkiewiczInformation Overload and Information Science / Mieczysław Muraszkiewicz
Information Overload and Information Science / Mieczysław Muraszkiewicz
 
How Not To Be Seen
How Not To Be SeenHow Not To Be Seen
How Not To Be Seen
 
Logical Programming With ruby-prolog
Logical Programming With ruby-prologLogical Programming With ruby-prolog
Logical Programming With ruby-prolog
 
Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.net
 
Transforming the world with Information technology
Transforming the world with Information technologyTransforming the world with Information technology
Transforming the world with Information technology
 
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
RuleML2015: Explanation of proofs of regulatory (non-)complianceusing semanti...
 

Similar to Cpp lab 13_pres

File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
Dr .Ahmed Tawwab
 
working with files
working with filesworking with files
working with files
SangeethaSasi1
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
Rex Joe
 
Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handlingpinkpreet_kaur
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handlingpinkpreet_kaur
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
File management
File managementFile management
File management
Mohammed Sikander
 
File Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.pptFile Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.ppt
muhazamali0
 
Files and streams
Files and streamsFiles and streams
Files and streams
Pranali Chaudhari
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
Hemantha Kulathilake
 
Lec 49 - stream-files
Lec 49 - stream-filesLec 49 - stream-files
Lec 49 - stream-filesPrincess Sam
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
sanya6900
 
Files in c++
Files in c++Files in c++
Files in c++
NivethaJeyaraman
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operationsTAlha MAlik
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
sparkishpearl
 
Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
anuvayalil5525
 
C++ files and streams
C++ files and streamsC++ files and streams
C++ files and streams
krishna partiwala
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
Harish Gyanani
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
MalligaarjunanN
 

Similar to Cpp lab 13_pres (20)

File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
working with files
working with filesworking with files
working with files
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
Files in c++
Files in c++Files in c++
Files in c++
 
Basics of file handling
Basics of file handlingBasics of file handling
Basics of file handling
 
basics of file handling
basics of file handlingbasics of file handling
basics of file handling
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
 
File management
File managementFile management
File management
 
File Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.pptFile Handling in C++ full ppt slide presentation.ppt
File Handling in C++ full ppt slide presentation.ppt
 
Files and streams
Files and streamsFiles and streams
Files and streams
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
Lec 49 - stream-files
Lec 49 - stream-filesLec 49 - stream-files
Lec 49 - stream-files
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
Files in c++
Files in c++Files in c++
Files in c++
 
Cs1123 10 file operations
Cs1123 10 file operationsCs1123 10 file operations
Cs1123 10 file operations
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
Files in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for referenceFiles in C++.pdf is the notes of cpp for reference
Files in C++.pdf is the notes of cpp for reference
 
C++ files and streams
C++ files and streamsC++ files and streams
C++ files and streams
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c language
 
C programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptxC programming power point presentation c ppt.pptx
C programming power point presentation c ppt.pptx
 

Recently uploaded

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

Cpp lab 13_pres

  • 1. OOP Object Oriented Programming Lab - 13 IDE Microsoft Visual C++ 6.0 Sajid Ali Gillal
  • 3. Files • A file is a collection of data in mass storage. • A data file is not a part of a program’s source code. • The same file can be read or modified by different programs. • The program must be aware of the format of the data in the file.
  • 4. Files (cont’d) • The file system is maintained by the operating system. • The system provides commands and/or GUI utilities for viewing file directories and for copying, moving, renaming, and deleting files. • The system also provides “core” functions, callable from programs, for reading and writing directories and files.
  • 5. File Random Access File & Sequential Access File
  • 6.
  • 7.
  • 8. Sequential Files Sequential file techniques provide a straightforward way to read and write files. Basic's sequential file commands manipulate text files: files of ASCII characters with carriage-return/linefeed pairs separating records. In computer science, sequential access means that a group of elements (e.g. data in a memory array or a disk file or on a tape) is accessed in a predetermined, ordered sequence. Sequential access is sometimes the only way of accessing the data, for example if it is on a tape. It may also be the access method of choice, for example if we simply want to process a sequence of data elements in order.
  • 9. Random Access Files Random access files consist of records that can be accessed in any sequence. This means the data is stored exactly as it appears in memory, thus saving processing time (because no translation is necessary) both in when the file is written and in when it is read. In computer science, random access (sometimes called direct access) is the ability to access an arbitrary element of a sequence in equal time.
  • 10. Random-Access Files • A program can start reading or writing a random-access file at any place and read or write any number of bytes at a time. • “Random-access file” is an abstraction: any file can be treated as a random-access file. • You can open a random-access file both for reading and writing at the same time.
  • 11. Random-Access Files (cont’d) • A binary file containing fixed-length data records is suitable for random-access treatment. • A random-access file may be accompanied by an “index” (either in the same or a different file), which tells the address of each record.
  • 12. File Types Text File Binary Stream Random-Access common use possible, but not as common
  • 13. What You Will Learn Create files Write files Read files Update files
  • 14. Random Access Files  A RandomAccessFile employs an internal pointer that points to the next byte to read.  This pointer is zero-based and the first byte is indicated by index 0.  When first created, a RandomAccessFile points to the first byte.  You can change the pointer's position by invoking the different methods.  The skipBytes method moves the pointer by the specified number of bytes.  If offset number of bytes would pass the end of file, the internal pointer will only move to as much as the end of file.
  • 15. How do I read an int from a file?
  • 16. "r". Open for reading only. "rw“. Open for reading and writing. If the file does not already exist, Random Access File creates the file. "rws". Open for reading and writing and require that every update to the file's content and metadata be written synchronously. "rwd". Open for reading and writing and require that every update to the file's content (but not metadata) be written synchronously.
  • 18. Create File P1.cpp #include <fstream> #include <iostream> using namespace std; void main( ) { ofstream Savefile("D:Rose.txt"); }
  • 20. Create File Q1.cpp #include <fstream> #include <iostream> using namespace std; void main( ) { ofstream Savefile("D:Rose.txt"); Savefile<< "Sajid Ali Gillal"; } May 21, 2010 Sajid Ali Gillal 20
  • 21. File output with strings or lines of output P4.cpp #include <fstream.h> void main( ) { ofstream outfile("E:Rose.txt"); outfile << "This is first line of Gillal Programn"; outfile << "This is second line of Gillal Programn"; outfile << "This is third line of Gillal Programn"; } May 21, 2010 Sajid Ali Gillal 21
  • 22. File input with characters P2.cpp #include <fstream> #include <iostream> using namespace std; void main( ) { char ch; ifstream Readfile("D:Rose.txt"); while(Readfile) { Readfile.get(ch); cout << ch; } cout << endl; } May 21, 2010 Sajid Ali Gillal 22
  • 23. file output with characters P5.cpp #include <fstream> #include <iostream> #include <string> using namespace std; void main( ) { string str = "If you start judging the people then you will have no time to love them!"; ofstream Savefile("E:Rose.txt"); Savefile<<str; cout << "File writtenn"; } May 21, 2010 Sajid Ali Gillal 23
  • 24. Reads person (full object) from disk P6.cpp #include <fstream.h> void main( ) #include <iostream.h> { #include <stdio.h> #include <conio.h> person pers; //create person variable FILE *ptr; class person ptr = fopen("E:data2.txt","w"); { fread(&pers,sizeof(pers),1,ptr); protected: pers.showData(); char name[80]; //person's name getch(); short age; //person's age } public: void showData( ) //display person's data { cout << "Name: " << name << endl; cout << "Age: " << age << endl; } }; May 21, 2010 Sajid Ali Gillal 24
  • 25. Save person (full object) to disk P7.cpp #include <fstream.h> void main( ) #include <iostream.h> { #include <stdio.h> person pers; //create a person pers.getData(); //get data for person class person { FILE *ptr; protected: ptr = fopen("E:Rose.dat","wb"); char name[80]; //person's name fwrite(&pers,sizeof(pers),1,ptr); short age; //person's age fclose(ptr); public: } void getData() //get person's data { cout << "Enter name: "; cin >> name; cout << "Enter age: "; cin >> age; } }; May 21, 2010 Sajid Ali Gillal 25
  • 26. OOP Object Oriented Programming Sajid Ali Gillal May 21, 2010 Sajid Ali Gillal 26