SlideShare a Scribd company logo
1 of 6
/*Q.12 Given a binary file PHONE.DAT, containing records of the following structure type-:
class phonlist
  {
     char Name[20] ;
     char Address[30] ;
     char AreaCode[5] ;
    char phoneNo[15] ;
    public :
    void Register();
    void show();
    };
Write a function TRANSFER() in C++, that would copy all those records which are having
AreaCode as "DEL" from PHONE.DAT to PHONBACK.DAT.           */



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>

class phonelist
  {
    char name[20] ;
    char address[30] ;
    char areacode[5] ;
    char phoneno[15] ;

public :

    void reg()
     {

     cout<<"enter name : ";
     gets(name);
     cout<<"enter address : ";
     gets(address);
     cout<<"enter areacode : ";
     gets(areacode);
     cout<<"enter phone number : ";
     gets(phoneno);
}

     void show()
    {
cout<<"enter name : ";
      cout<<"enter address : ";
      cout<<"enter areacode : ";
      cout<<"enter phone number : ";

  }

  char* return_code()
  {
   return areacode;
  }

 }p[5] ;



 void main()
 {
 phonelist temp;
 int n,i;
      cout<<"for how many people you wish to enter the details ";
      cin>>n;

  ofstream fout;
  fout.open("phone.dat",ios::binary);
                           //writing in phone.dat
   for(i=0;i<n;i++)
      {
         p[i].reg();
         fout.write((char*)&p[i],sizeof(phonelist));

        }




   ifstream fin;
   fin.open("phone.dat",ios::binary);




fin.open("phone.dat",ios::binary);
   fout.open("phoneback.dat",ios::binary);
                          //transferring records with del areacode to phoneback.dat
i=0;
       while(fin)
         {
           fin.read((char*)&temp,sizeof(phonelist));

              if(strcmp("del",p[i].return_code())==0)
                  {
                     fout.write((char*)&temp,sizeof(phonelist));
                     i++;
                   }
          }
                   //displaying the records in phoneback.dat
      fin.open("phoneback.dat",ios::binary);

      while(fin)
       {
        fin.read((char*)&temp,sizeof(phonelist));
        temp.show();
        }



   fin.close();
   fout.close();

   getch();

  }




/*Q.11 Write a program in C++ to transfer a particular type of stock from the file "stock.dat" to
another file "Site.dat". Assuming that the binary file is containing the records of following
structure:
struct Products
{
   int id;
   char Iname[30];
   int type;
};
   Remember that transfer means deletion from the "stock.dat" file and addition in the "site.dat"
     file.
*/



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>

struct products
  {
     int id;
    char iname[30];
    int type;
   };



void main()
{
  products p[5],temp;
  int n,t,i;



cout<<"for how many products you wish to enter information ";
cin>>n;




ofstream fout;

 fout.open("stock.dat",ios::binary);



         //entering the details in stock file



for(i=0;i<n;i++)
 {
   cout<<"enter id : ";
   cin>>p[i].id;
   cout<<"enter name : ";
   gets(p[i].iname);
cout<<"enter type : ";
      cin>>p[i].type;

 fout.write((char*)&p[i],sizeof(products));
 }
   fout.close();



 cout<<"which type of stock you wish to transfer to other file ";
 cin>>t;

 ifstream fin;

 fin.open("stock.dat",ios::binary);
 fout.open("site.dat",ios::binary);

  i=0;




//loop to transfer the specified records in site file



while(fin)
 {
  fin.read((char*)&temp,sizeof(products));

       if(p[i].type==t)
             fout.write((char*)&temp,sizeof(products));
              i++;
  }




 fin.close();
   fout.close();

  remove("stock.dat");



   fin.open("site.dat",ios::binary);
while(fin)
    {
     fin.read((char*)&temp,sizeof(products));

         cout<<" id : "<<temp.id;
         cout<<"n name : "<<temp.iname;
         cout<<"n type : "<<temp.type;

     }

fin.close();

    getch();
}

More Related Content

What's hot

What's hot (19)

1
11
1
 
C++ programs
C++ programsC++ programs
C++ programs
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Oop lab report
Oop lab reportOop lab report
Oop lab report
 
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
 
Introduction to F# for the C# developer
Introduction to F# for the C# developerIntroduction to F# for the C# developer
Introduction to F# for the C# developer
 
Computer hw1
Computer hw1Computer hw1
Computer hw1
 
Doubly linklist
Doubly linklistDoubly linklist
Doubly linklist
 
C++ file
C++ fileC++ file
C++ file
 
Sol7
Sol7Sol7
Sol7
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Qno 1 (b)
Qno 1 (b)Qno 1 (b)
Qno 1 (b)
 
Cs project
Cs projectCs project
Cs project
 
Hotel Management In C++
Hotel Management In C++Hotel Management In C++
Hotel Management In C++
 
Basic Programs of C++
Basic Programs of C++Basic Programs of C++
Basic Programs of C++
 
CBSE Computer Project for Class 12 ( C++)
CBSE Computer Project for Class 12 ( C++)CBSE Computer Project for Class 12 ( C++)
CBSE Computer Project for Class 12 ( C++)
 
Class array
Class arrayClass array
Class array
 
Quiz using C++
Quiz using C++Quiz using C++
Quiz using C++
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 

Viewers also liked

Viewers also liked (16)

brain gain
brain gainbrain gain
brain gain
 
koperasi
koperasikoperasi
koperasi
 
Descriptive text ^ ^
Descriptive text ^ ^Descriptive text ^ ^
Descriptive text ^ ^
 
Hukum Perkawinan Adat
Hukum Perkawinan AdatHukum Perkawinan Adat
Hukum Perkawinan Adat
 
Sintaksis
SintaksisSintaksis
Sintaksis
 
Unsur Unsur Transisi Fisika
Unsur Unsur Transisi FisikaUnsur Unsur Transisi Fisika
Unsur Unsur Transisi Fisika
 
Letak bilangan pada garis bilangan
Letak bilangan pada garis bilanganLetak bilangan pada garis bilangan
Letak bilangan pada garis bilangan
 
Teori perkembangan muka bumi
Teori perkembangan muka bumiTeori perkembangan muka bumi
Teori perkembangan muka bumi
 
Sistem Ekonomi Campuran
Sistem Ekonomi CampuranSistem Ekonomi Campuran
Sistem Ekonomi Campuran
 
City of Moore Parks Master Plan 2012
City of Moore Parks Master Plan 2012City of Moore Parks Master Plan 2012
City of Moore Parks Master Plan 2012
 
Biologi sel
Biologi selBiologi sel
Biologi sel
 
استارتاپ و حومه
استارتاپ و حومهاستارتاپ و حومه
استارتاپ و حومه
 
(3) signos pureba 1
(3) signos pureba 1(3) signos pureba 1
(3) signos pureba 1
 
Kolorki. ;)))
Kolorki. ;)))Kolorki. ;)))
Kolorki. ;)))
 
Kolory-stardolla
Kolory-stardollaKolory-stardolla
Kolory-stardolla
 
Indices tecnologia ii imprimir
Indices tecnologia ii imprimirIndices tecnologia ii imprimir
Indices tecnologia ii imprimir
 

Similar to Cmptr ass

c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservationSwarup Kumar Boro
 
Railway reservation
Railway reservationRailway reservation
Railway reservationSwarup Boro
 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++zain ul hassan
 
Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxrennaknapp
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdfannucommunication1
 
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdfnum.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdfANSAPPARELS
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handlingsparkishpearl
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMKrishna Raj
 
Computer science project work
Computer science project workComputer science project work
Computer science project workrahulchamp2345
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into itmelakusisay507
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Deepak Singh
 
C s investigatory project on telephone directory
C s  investigatory project on telephone directoryC s  investigatory project on telephone directory
C s investigatory project on telephone directorySHUBHAM YADAV
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfSANDEEPARIHANT
 

Similar to Cmptr ass (20)

c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Railway reservation
Railway reservationRailway reservation
Railway reservation
 
Files
FilesFiles
Files
 
File Handling Program
File Handling ProgramFile Handling Program
File Handling Program
 
File handling complete programs in c++
File handling complete programs in c++File handling complete programs in c++
File handling complete programs in c++
 
Data structures
Data structuresData structures
Data structures
 
Railwaynew
RailwaynewRailwaynew
Railwaynew
 
Language is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docxLanguage is C++ I'm having trouble making my code meet these requireme.docx
Language is C++ I'm having trouble making my code meet these requireme.docx
 
File in cpp 2016
File in cpp 2016 File in cpp 2016
File in cpp 2016
 
#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf#include iostream #includeData.h #includePerson.h#in.pdf
#include iostream #includeData.h #includePerson.h#in.pdf
 
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdfnum.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
Exmaples of file handling
Exmaples of file handlingExmaples of file handling
Exmaples of file handling
 
RAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAMRAILWAY RESERWATION PROJECT PROGRAM
RAILWAY RESERWATION PROJECT PROGRAM
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
source code which create file and write into it
source code which create file and write into itsource code which create file and write into it
source code which create file and write into it
 
Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009Cbse question-paper-computer-science-2009
Cbse question-paper-computer-science-2009
 
C s investigatory project on telephone directory
C s  investigatory project on telephone directoryC s  investigatory project on telephone directory
C s investigatory project on telephone directory
 
To write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdfTo write a program that implements the following C++ concepts 1. Dat.pdf
To write a program that implements the following C++ concepts 1. Dat.pdf
 

Recently uploaded

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
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
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
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
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
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
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 

Recently uploaded (20)

Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
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
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
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
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
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...
 
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...
 
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
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
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)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
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
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 

Cmptr ass

  • 1. /*Q.12 Given a binary file PHONE.DAT, containing records of the following structure type-: class phonlist { char Name[20] ; char Address[30] ; char AreaCode[5] ; char phoneNo[15] ; public : void Register(); void show(); }; Write a function TRANSFER() in C++, that would copy all those records which are having AreaCode as "DEL" from PHONE.DAT to PHONBACK.DAT. */ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<fstream.h> #include<string.h> class phonelist { char name[20] ; char address[30] ; char areacode[5] ; char phoneno[15] ; public : void reg() { cout<<"enter name : "; gets(name); cout<<"enter address : "; gets(address); cout<<"enter areacode : "; gets(areacode); cout<<"enter phone number : "; gets(phoneno); } void show() {
  • 2. cout<<"enter name : "; cout<<"enter address : "; cout<<"enter areacode : "; cout<<"enter phone number : "; } char* return_code() { return areacode; } }p[5] ; void main() { phonelist temp; int n,i; cout<<"for how many people you wish to enter the details "; cin>>n; ofstream fout; fout.open("phone.dat",ios::binary); //writing in phone.dat for(i=0;i<n;i++) { p[i].reg(); fout.write((char*)&p[i],sizeof(phonelist)); } ifstream fin; fin.open("phone.dat",ios::binary); fin.open("phone.dat",ios::binary); fout.open("phoneback.dat",ios::binary); //transferring records with del areacode to phoneback.dat
  • 3. i=0; while(fin) { fin.read((char*)&temp,sizeof(phonelist)); if(strcmp("del",p[i].return_code())==0) { fout.write((char*)&temp,sizeof(phonelist)); i++; } } //displaying the records in phoneback.dat fin.open("phoneback.dat",ios::binary); while(fin) { fin.read((char*)&temp,sizeof(phonelist)); temp.show(); } fin.close(); fout.close(); getch(); } /*Q.11 Write a program in C++ to transfer a particular type of stock from the file "stock.dat" to another file "Site.dat". Assuming that the binary file is containing the records of following structure: struct Products { int id; char Iname[30]; int type; }; Remember that transfer means deletion from the "stock.dat" file and addition in the "site.dat" file.
  • 4. */ #include<iostream.h> #include<conio.h> #include<stdio.h> #include<fstream.h> struct products { int id; char iname[30]; int type; }; void main() { products p[5],temp; int n,t,i; cout<<"for how many products you wish to enter information "; cin>>n; ofstream fout; fout.open("stock.dat",ios::binary); //entering the details in stock file for(i=0;i<n;i++) { cout<<"enter id : "; cin>>p[i].id; cout<<"enter name : "; gets(p[i].iname);
  • 5. cout<<"enter type : "; cin>>p[i].type; fout.write((char*)&p[i],sizeof(products)); } fout.close(); cout<<"which type of stock you wish to transfer to other file "; cin>>t; ifstream fin; fin.open("stock.dat",ios::binary); fout.open("site.dat",ios::binary); i=0; //loop to transfer the specified records in site file while(fin) { fin.read((char*)&temp,sizeof(products)); if(p[i].type==t) fout.write((char*)&temp,sizeof(products)); i++; } fin.close(); fout.close(); remove("stock.dat"); fin.open("site.dat",ios::binary);
  • 6. while(fin) { fin.read((char*)&temp,sizeof(products)); cout<<" id : "<<temp.id; cout<<"n name : "<<temp.iname; cout<<"n type : "<<temp.type; } fin.close(); getch(); }