SlideShare a Scribd company logo
/*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

DOCX
Applications of list
PPTX
งานนำเสนอ อาจารย์ลาวัลย์
PDF
C++ Programming - 2nd Study
PDF
C++ Programming - 4th Study
PPTX
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
PPTX
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
PDF
runtimestack
Applications of list
งานนำเสนอ อาจารย์ลาวัลย์
C++ Programming - 2nd Study
C++ Programming - 4th Study
การเข ยนคำส _งควบค_มข__นพ__นฐาน (1)
เธเธฒเธฃเน€เธ‚ เธขเธ™เธ„เธณเธช _เธ‡เธ„เธงเธšเธ„_เธกเธ‚__เธ™เธž__เธ™เธเธฒเธ™
runtimestack

What's hot (19)

PDF
C++ programs
DOCX
Pratik Bakane C++
DOCX
Oop lab report
PDF
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
PPTX
Introduction to F# for the C# developer
DOC
Computer hw1
DOCX
Doubly linklist
DOCX
C++ file
DOCX
Pratik Bakane C++
PPT
DOCX
Cs project
PPT
Hotel Management In C++
DOCX
Basic Programs of C++
DOCX
CBSE Computer Project for Class 12 ( C++)
DOCX
Class array
DOC
Quiz using C++
PPTX
Circular linked list
C++ programs
Pratik Bakane C++
Oop lab report
ECSE 221 - Introduction to Computer Engineering - Tutorial 1 - Muhammad Ehtas...
Introduction to F# for the C# developer
Computer hw1
Doubly linklist
C++ file
Pratik Bakane C++
Cs project
Hotel Management In C++
Basic Programs of C++
CBSE Computer Project for Class 12 ( C++)
Class array
Quiz using C++
Circular linked list
Ad

Viewers also liked (16)

PPTX
brain gain
DOCX
koperasi
PPTX
Descriptive text ^ ^
PPT
Hukum Perkawinan Adat
PPTX
Sintaksis
PPT
Unsur Unsur Transisi Fisika
PPTX
Letak bilangan pada garis bilangan
PPT
Teori perkembangan muka bumi
PPTX
Sistem Ekonomi Campuran
PPTX
City of Moore Parks Master Plan 2012
PPT
PDF
استارتاپ و حومه
PPTX
(3) signos pureba 1
ODP
Kolorki. ;)))
ODP
Kolory-stardolla
PDF
Indices tecnologia ii imprimir
brain gain
koperasi
Descriptive text ^ ^
Hukum Perkawinan Adat
Sintaksis
Unsur Unsur Transisi Fisika
Letak bilangan pada garis bilangan
Teori perkembangan muka bumi
Sistem Ekonomi Campuran
City of Moore Parks Master Plan 2012
استارتاپ و حومه
(3) signos pureba 1
Kolorki. ;)))
Kolory-stardolla
Indices tecnologia ii imprimir
Ad

Similar to Cmptr ass (20)

TXT
c++ program for Railway reservation
TXT
Railway reservation
TXT
File handling complete programs in c++
DOCX
Data structures
TXT
Railwaynew
DOCX
Language is C++ I'm having trouble making my code meet these requireme.docx
PPT
File in cpp 2016
PDF
#include iostream #includeData.h #includePerson.h#in.pdf
PDF
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
DOCX
File handling in c++
ODP
Sysprog17
DOCX
Exmaples of file handling
PPTX
PythonProgramming-Binary-file-handling-2.pptx
DOCX
RAILWAY RESERWATION PROJECT PROGRAM
DOCX
Computer science project work
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
DOCX
source code which create file and write into it
PDF
Cbse question-paper-computer-science-2009
c++ program for Railway reservation
Railway reservation
File handling complete programs in c++
Data structures
Railwaynew
Language is C++ I'm having trouble making my code meet these requireme.docx
File in cpp 2016
#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
File handling in c++
Sysprog17
Exmaples of file handling
PythonProgramming-Binary-file-handling-2.pptx
RAILWAY RESERWATION PROJECT PROGRAM
Computer science project work
Object Oriented Programming (OOP) using C++ - Lecture 3
source code which create file and write into it
Cbse question-paper-computer-science-2009

Recently uploaded (20)

PDF
Trump Administration's workforce development strategy
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
1_English_Language_Set_2.pdf probationary
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Introduction to Building Materials
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Lesson notes of climatology university.
PDF
Classroom Observation Tools for Teachers
PDF
advance database management system book.pdf
PPTX
Cell Types and Its function , kingdom of life
Trump Administration's workforce development strategy
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Weekly quiz Compilation Jan -July 25.pdf
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
1_English_Language_Set_2.pdf probationary
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Introduction to Building Materials
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Supply Chain Operations Speaking Notes -ICLT Program
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
Complications of Minimal Access Surgery at WLH
Lesson notes of climatology university.
Classroom Observation Tools for Teachers
advance database management system book.pdf
Cell Types and Its function , kingdom of life

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(); }