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
Cpp lab 13_pres
Cpp lab 13_pres
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 (20)

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

Viewers also liked (20)

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

Similar to Cpp lab 13_pres (20)

PPT
File in cpp 2016
Dr .Ahmed Tawwab
 
PPTX
working with files
SangeethaSasi1
 
PDF
Filesinc 130512002619-phpapp01
Rex Joe
 
PPSX
Files in c++
Selvin Josy Bai Somu
 
PPTX
Basics of file handling
pinkpreet_kaur
 
PPTX
basics of file handling
pinkpreet_kaur
 
PPT
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
PPTX
File management
Mohammed Sikander
 
PPTX
File Handling in C++ full ppt slide presentation.ppt
muhazamali0
 
PDF
Files and streams
Pranali Chaudhari
 
PPTX
COM1407: File Processing
Hemantha Kulathilake
 
PPT
Lec 49 - stream-files
Princess Sam
 
PPT
File handling in_c
sanya6900
 
PPTX
Files in c++
NivethaJeyaraman
 
PPTX
Cs1123 10 file operations
TAlha MAlik
 
PPTX
Introduction to files management systems
araba8
 
PPT
PL-II Lecture19 oop in c++ pyaray bachon .ppt
inambscs4508
 
PPT
file_handling_in_c.ppt......................................
nadoj47203
 
PPT
file_handling_in_c.pptbbbbbbbbbbbbbbbbbbbbb
SanskritiGupta39
 
DOCX
Exmaples of file handling
sparkishpearl
 
File in cpp 2016
Dr .Ahmed Tawwab
 
working with files
SangeethaSasi1
 
Filesinc 130512002619-phpapp01
Rex Joe
 
Files in c++
Selvin Josy Bai Somu
 
Basics of file handling
pinkpreet_kaur
 
basics of file handling
pinkpreet_kaur
 
new pdfrdfzdfzdzzzzzzzzzzzzzzzzzzzzzzzzzzgggggggggggggggggggggggggggggggggggg...
AzanMehdi
 
File management
Mohammed Sikander
 
File Handling in C++ full ppt slide presentation.ppt
muhazamali0
 
Files and streams
Pranali Chaudhari
 
COM1407: File Processing
Hemantha Kulathilake
 
Lec 49 - stream-files
Princess Sam
 
File handling in_c
sanya6900
 
Files in c++
NivethaJeyaraman
 
Cs1123 10 file operations
TAlha MAlik
 
Introduction to files management systems
araba8
 
PL-II Lecture19 oop in c++ pyaray bachon .ppt
inambscs4508
 
file_handling_in_c.ppt......................................
nadoj47203
 
file_handling_in_c.pptbbbbbbbbbbbbbbbbbbbbb
SanskritiGupta39
 
Exmaples of file handling
sparkishpearl
 
Ad

Recently uploaded (20)

PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
community health nursing question paper 2.pdf
Prince kumar
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Dimensions of Societal Planning in Commonism
StefanMz
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 

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
  • 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