Ask a Teacher



DEFINE A CLASS TELEPHONE &NAME OF SUBSCRIBER INCLUDE MEMBER FUNCTION For INPUTTING DATA&DISPLAYING THE NAME Of The SUBSCRIBER For A GIVEN NUMBER AS ARGUMENTS USE 10 OBJECT TO STORE The DETAILS Of 10 CUSTOMERS & DISPLAY The NAME Of The SUBSCRIBER for a given phone number

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>
#include <process.h>
#include <dos.h>
#include <graphics.h>

//                 #### Bill Center ####class bill{
      char cno[5];
      char bdate[8];
      char dueamt[6];
      char oamt[6];
      char duedate[8];
      public:
      void assign();
      void putdata();
      char* cus(){return cno;}
      void billupdate(char* cusno,char* outamt,char* damt,char* billd,char* dued)
      {
         strcpy(cno,cusno);
         strcpy(oamt,outamt);
         strcpy(dueamt,damt);
         strcpy(bdate,billd);
         strcpy(duedate,dued);
      }
      };
void bill:: assign()
   {
     cout<<"\n Enter customer no.:";
     cin>>cno;
     cout<<"\n Enter bill date:";
     cin>>bdate;
     cout<<"\n Enter due amount:";
     cin>>dueamt;
     cout<<"\n Enter outstanding amount:";
     cin>>oamt;
     cout<<"\n Enter duedate:";
     cin>>duedate;
    }
void bill::putdata()
    {
     cout<<"\n Customer No.: "<<cno;
     cout<<"\n Bill date: "<<bdate;
     cout<<"\n Due Amt.: "<<dueamt;
     cout<<"\n Outstanding Amt.: "<<oamt;
     cout<<"\n Due date: "<<duedate;
    }

void readbill()
{
 bill rec;
 fstream file;
 file.open("bill.dat",ios::ate|ios::in|ios::out|ios::binary);
 char ch;
 char cusno[5],outamt[6],damt[6],billd[8],dued[8];
 int choice,found=0;
 while(1){
       clrscr();
       cout<<"\n*****Bill Centre*****\n";
       cout<<"1)Add New Record\n";
       cout<<"2)Display All Records\n";
       cout<<"3)Search Bill Details\n";
       cout<<"4)Update Bill Details\n";
       cout<<"5)Exit\n";
       cout<<"\nEnter your choice: ";
       cin>>choice;
       switch (choice){
          case 1://New Record
             rec.assign();
             cin.get(ch);
             file.write((char *)&rec, sizeof(rec));
             break;
          case 2://Display All Records
             file.seekg(0,ios::beg);
             cout<<"\n\n Records in Bill Centre\n";
             while(file){
             file.read((char *)&rec, sizeof(rec));
             if (!file.eof())
             rec.putdata();
             }
             file.clear();
             getch();
             break;
          case 3://Search Bill Details when customer no.is known.
             cout<<"\n\nEnter Customer No.: ";
             cin>>cusno;
             file.seekg(0,ios::beg);
             found=0;
             while(file.read((char *)&rec, sizeof(rec)))
             {
              if(strcmp(cusno,rec.cus())==0)
              {
               found=1;
               rec.putdata();
              }
             }
             file.clear();
             if(found==0)
             cout<<"\n---Record Not Found---\n";
             getch();
             break;
          case 4://Update Bill Details.
             cout<<"\n\n Enter Customer No.: ";
             cin>>cusno;
             file.seekg(0,ios::beg);
             found=0;
             int cnt=0;
             while(file.read((char *)&rec, sizeof(rec)))
             {
              cnt++;
              if(strcmp(cusno,rec.cus())==0)
              {
               found=1;
               break;
              }
             }
             file.clear();
             if(found==0)
             cout<<"\n\n---Record Not Found---";
             else
             {
             int location=(cnt-1) * sizeof(rec);
             cin.get(ch);
             if(file.eof())
             file.clear();
             cout<<"\n Enter new Bill Date: ";
             cin>>billd;
             cout<<"\n Enter new Due Date: ";
             cin>>dued;
             cout<<"\n Enter new Due Amt.: ";
             cin>>damt;
             cout<<"\n Enter new Outstanding Amt.: ";
             cin>>outamt;
             file.seekp(location);
             rec.billupdate(cusno,outamt,damt,billd,dued);
             file.write((char *)&rec, sizeof(rec));
             file.flush();
             }
             break;
          case 5://Exitgotoout;
             }
          }
          out:
          file.close();

          }

//                  #### Telephone Directory ####class phoneBook{
    char name[20],phno[6];
    public:
    void getdata();
    void showdata();
    char *getname(){ return name; }
    char *getphno(){ return phno; }
    void update(char *nm,char *telno){
        strcpy(name,nm);
        strcpy(phno,telno);
    }
};

void phoneBook :: getdata(){
    cout<<"\nEnter Name : ";
    cin>>name;
    cout<<"Enter Phone No. : ";
    cin>>phno;
}

void phoneBook :: showdata(){
    cout<<"\n";
    cout<<setw(15)<<name;
    cout<<setw(8)<<phno;
}
void readphone(){
    phoneBook rec;
    fstream file;
    file.open("phone.dat", ios::ate | ios::in | ios::out | ios::binary);
    char ch,nm[20],telno[6];
    int choice,found=0;
    while(1){
        clrscr();
        cout<<"\n*****Phone Book*****\n";
        cout<<"1) Add New Record\n";
        cout<<"2) Display All Records\n";
        cout<<"3) Search Telephone No.\n";
        cout<<"4) Search Person Name\n";
        cout<<"5) Update Telephone No.\n";
        cout<<"6) Exit\n";
        cout<<"Choose your choice : ";
        cin>>choice;
        switch(choice){
            case 1 : //New Record
                 rec.getdata();
                 cin.get(ch);
                 file.write((char *) &rec, sizeof(rec));
                 break;

            case 2 : //Display All Records
                 file.seekg(0,ios::beg);
                 cout<<"\n\nRecords in Phone Book\n";
                 while(file){
                    file.read((char *) &rec, sizeof(rec));
                    if(!file.eof())
                        rec.showdata();
                 }
                 file.clear();
                 getch();
                 break;

            case 3 : //Search Tel. no. when person name is known.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 getch();
                 break;

            case 4 : //Search name on basis of tel. no
                 cout<<"\n\nEnter Telephone No : ";
                 cin>>telno;
                 file.seekg(0,ios::beg);
                 found=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    if(strcmp(telno,rec.getphno())==0)
                    {
                        found=1;
                        rec.showdata();
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 getch();
                 break;

            case 5 : //Update Telephone No.
                 cout<<"\n\nEnter Name : ";
                 cin>>nm;
                 file.seekg(0,ios::beg);
                 found=0;
                 int cnt=0;
                 while(file.read((char *) &rec, sizeof(rec)))
                 {
                    cnt++;
                    if(strcmp(nm,rec.getname())==0)
                    {
                        found=1;
                        break;
                    }
                 }
                 file.clear();
                 if(found==0)
                    cout<<"\n\n---Record Not found---\n";
                 else
                 {
                    int location = (cnt-1) * sizeof(rec);
                    cin.get(ch);
                    if(file.eof())
                        file.clear();

                    cout<<"Enter New Telephone No : ";
                    cin>>telno;
                    file.seekp(location);
                    rec.update(nm,telno);
                    file.write((char *) &rec, sizeof(rec));
                    file.flush();
                 }
                 break;
            case 6 ://Exitgotoout;
        }
    }
out:
file.close();
}

void main()
{
   int gdriver = DETECT, gmode, errorcode;

   initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
   setcolor(BLUE);
   for(int i=300,j=240;i>=20;i--,j++)
      {
       cleardevice();
       rectangle(i,i,j,j);
       delay(7);
      }
   settextstyle(10,0,5);
   cleardevice();
   rectangle(20,20,600,450);
   delay(100);
   outtextxy(60,200,"W ");delay(80);
   for(i=0;i<1;i++)
    {
       for(int j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(150,200,"E ");delay(80);
   for(i=0;i<1;i++)
    {
       for(j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(210,200,"L ");delay(80);
   for(i=0;i<1;i++)
    {
       for(j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(270,200,"C ");delay(80);
   for(i=0;i<1;i++)
    {
       for(j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(330,200,"O ");delay(80);
   for(i=0;i<1;i++)
    {
       for(j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(390,200,"M ");delay(80);
   for(i=0;i<1;i++)
    {
       for(j=100;j<500;j=j+50)
       {sound(j);delay(100);nosound();}
    }

   outtextxy(450,200,"E ");

   getch();
   closegraph();

 clrscr();
int choice;
do{
cout<<"\n****** TELEPHONE INFORMATION CENTER ******";
cout<<"\n\n 1. Telephone Directory";
cout<<"\n 2. Bill Center";
cout<<"\n 3. Exit";
cout<<"\n Enter your choice";
cin>>choice;
{
if(choice==1)
readphone();
elseif(choice==2)
readbill();
else
exit(0);
}
}
while(choice!=3);
getch();
}

NOTE: Modify this program according to your need and try to develop programs by yourself.


comments powered by Disqus