Monday, June 7, 2010

manipulator

/*===================================================================
PRACTICAL NO:-
AIM:-WRITE A PROGRAM IN C++ FOR DISPLAYING TELEPHONE BILL
     OF BSNL (Bharat Sanchar Nigam limited) USING MANIPULATOR
ROLL NO:-
====================================================================*/
#include
#include
#include
#include
#include //exit
#include //toupper
#include
#include
#include
// CLASS HAVING THE RECORD OF CUSTOMER
class customer//CREAT A CUSTOMER CLASS
{
      char ph[10];
      char name[30];
      char add[40];
      char type;
     public :
      void append();
      void display();

}cust;//Declare the class variable

// MAIN FUNCTION HAVING THE MAIN MENU
void main()
{
     char ch,ch1;
     while(1)
     {
      clrscr();
      cout<<<<<<<<<<
      cout<<<<"MAHASANCHAR TELEPHONE NIGA LTD.";
      cout<<<<" "<<<

      cout<<<<"D-Display a Bill"<<<
      cout<<<"A-Append a record"<<<
      cout<<<"Q-Quit"<<<
      cout<<<"Select your choice:-";
      ch =getch();
      ch = toupper(ch);
      switch(ch)
      {
      case ('Q') :
               clrscr();
               exit(1);
      case ('D') : cust.display();
               break;

      case ('A') :cust.append();
              break;
        }
      }
     }
// FUNCTION TO ADD THE CUSTOMER RECORD IN THE FILE
void customer :: append()
{
     char choice;
     fstream fp;
     fp.open("tphone.dat", ios::app);
     if (!fp)
     {
      cout<<"Unable to open FILE.";
      getch();
      return;
     }
     while(1)
     {
      clrscr();
      cout<<<<<<<
      cout<<<<"ENTER  THE  CUSTOMER  RECORD";
      cout<<<<" "<<<

      while(1)
      {
           cout<<<<"Enter the name:-";
           gets(name);
           cout<<<
           if(strlen(name)==0)
           {
        cout<<<"Name cannot be left blank\a"<<
        }
           else
            break;
      }
      while(1)
      {
           cout<<<"Enter the address:-";
           gets(add);
           cout<<<
           if (strlen(add) != 0)
           break;
      }

      while(1)
      {
           cout<<<"Assigned Phone. No.:";
           cin>>ph;
           cout<<<
           if (ph != 0 )
            break;

      }
      cout<<<"Enter O for Office and R for residential phone"<
      cout<
      cout<<<"Catagory ( O/R ) :";
      cin>>type;
      fp.write((char *) this,sizeof(cust));
      return;
      fp.close();
    }
}
// FUNCTION TO DISPLAY THE CUSTOMER RECORD AND CALCULATE THE BILL
void customer :: display()
{
     char p[10];
     char choice;
     int found=0;
     int no;
     float bill, tax, fine, bbill, abill;
     fstream fp;
     fp.open("tphone.dat", ios::in);
     if (!fp)
     {
      cout<<"Unable to open a file";
      getch();
      fp.close();
      return;
     }
     while(choice != '0')
     {
      clrscr();
      cout<<<<<<<<<<
      cout<<<"Please enter the Phone No:- ";
      cin>>p;
      if (!strcmp(p,"0"))
      return;
      found = 0;
      fp.seekg(0);
      while (fp.read((char *)this ,sizeof(cust)))
      {
           if (found==1)
            break;
           if (!strcmp(ph,p))
           {
            clrscr();
            cout<
            cout<<<<" ";;
            cout<<
            cout<<<<"MASANCHAR TELEPHONE BILL"<<
            cout<<<<(" ");
            cout<<
            cout<<<"Name:";
            cout<
            cout.width(57);
            cout<<"Assigned Ph. No.:";
            cout<<<
            cout<<"Catagory ( O/R ):";
            cout<
            cout<<<"Address:";
            cout<<<

            cout<<<"No. of calls:- ";
            cout<<"____";
            cin>>no;
            if ( no <= 150 )
             bill = 0 ;
            else
            {
             no = no - 150;
             if (toupper(type) == 'O')
                  bill = no * 1.00 ;
             else
                  bill = no * .80;
            }
             cout<<
            cout<<<<(" ");
            cout<<
             cout<<<<"Bill:-";
            cout<<<

            tax = (5*bill)/100;
            cout<<
            cout<<<"5% Tax:-";
            cout<<<
            cout<<

            cout<<<"Duties:-";
            cout<<<"100";
            int dd,mm,yy;
            struct date d;   // Getting system Date
            getdate(&d);
            dd = d.da_day;
            mm = d.da_mon;
            yy = d.da_year;
            cout<<<<<

            cout<<<"TOTAL BILL before " ;
            cout<

<<"/"<<<"/"<<<":";
            bbill = bill+tax+100;

            cout<<<
            cout<<

            cout<<<"Late Fine:-";
            fine = (bbill*5)/100;
            cout<<<

            cout<<
            cout<<<"TOTAL BILL after ";
            cout<
<<"/"<<<"/"<<<":-";
            abill = bbill+fine;
            cout<<<
            found = 1;

            cout<<
            cout<<<<(" ");
            cout<<
            cout<<<<"Press a Key";
            getch();
           }
         return;

    }
   }
     fp.close();
}
//end of program

No comments: