SlideShare une entreprise Scribd logo
1  sur  26
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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 LanguageESUG
 
Redis/Lessons learned
Redis/Lessons learnedRedis/Lessons learned
Redis/Lessons learnedTit Petric
 
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 azurecloudbeatsch
 
Huong dan cai dat hadoop
Huong dan cai dat hadoopHuong dan cai dat hadoop
Huong dan cai dat hadoopQuỳnh Phan
 
Swift 4 : Codable
Swift 4 : CodableSwift 4 : Codable
Swift 4 : CodableSeongGyu 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.2Itamar Haber
 
Hands On Spring Data
Hands On Spring DataHands On Spring Data
Hands On Spring DataEric Bottard
 
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 Postgressyerram
 
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 PHPMudasir Syed
 
2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekinge2015 bioinformatics python_strings_wim_vancriekinge
2015 bioinformatics python_strings_wim_vancriekingeProf. Wim Van Criekinge
 
Introducing FSter
Introducing FSterIntroducing FSter
Introducing FSteritsmesrl
 
Object Storage with Gluster
Object Storage with GlusterObject Storage with Gluster
Object Storage with GlusterGluster.org
 
Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501Tajo Seoul Meetup-201501
Tajo Seoul Meetup-201501Jinho Kim
 
A Brief Introduction to Redis
A Brief Introduction to RedisA Brief Introduction to Redis
A Brief Introduction to RedisCharles Anderson
 

Tendances (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
 

En vedette

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 valueGirija Muscut
 
Cognitive information science
Cognitive information scienceCognitive information science
Cognitive information scienceS. 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.netGirija Muscut
 
Part 1 picturebox using vb.net
Part 1 picturebox using vb.netPart 1 picturebox using vb.net
Part 1 picturebox using vb.netGirija 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.netGirija 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 DesignHubbard 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 HenrichsWolfgang Stock
 
How Not To Be Seen
How Not To Be SeenHow Not To Be Seen
How Not To Be SeenMark Pesce
 
Logical Programming With ruby-prolog
Logical Programming With ruby-prologLogical Programming With ruby-prolog
Logical Programming With ruby-prologPreston Lee
 
Part 3 binding navigator vb.net
Part 3 binding navigator vb.netPart 3 binding navigator vb.net
Part 3 binding navigator vb.netGirija Muscut
 
Transforming the world with Information technology
Transforming the world with Information technologyTransforming the world with Information technology
Transforming the world with Information technologyGlenn 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
 

En vedette (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...
 

Similaire à Cpp lab 13_pres

Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Rex Joe
 
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
 
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_csanya6900
 
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 handlingsparkishpearl
 
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 referenceanuvayalil5525
 
File handling in c language
File handling in c languageFile handling in c language
File handling in c languageHarish 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.pptxMalligaarjunanN
 
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
 
File management in C++
File management in C++File management in C++
File management in C++apoorvaverma33
 

Similaire à 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
 
Files in c++
Files in c++Files in c++
Files in c++
 
Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01Filesinc 130512002619-phpapp01
Filesinc 130512002619-phpapp01
 
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
 
File management
File managementFile management
File management
 
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
 
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)
 
File management in C++
File management in C++File management in C++
File management in C++
 

Dernier

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 

Dernier (20)

Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.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