Advertisement
masokis

C++ - Telephone bill

Mar 23rd, 2011
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.26 KB | None | 0 0
  1.  /* -------------------------------------------------------------------------------------------------------------------------------
  2.                     *TELEPHONE BILLING SYSTEM*             
  3. --------------------------------------------------------------------------------------------------------------------------------*/
  4.  
  5.  /* -------------------------------------------------------------------------------------------------------------------------------
  6.                     *HEADER FILES INCLUDED*
  7. --------------------------------------------------------------------------------------------------------------------------------*/
  8.  
  9.  
  10. #include <stdio.h>
  11. #include <conio.h>
  12. #include <string.h>
  13. #include <process.h>
  14. #include <ctype.h>
  15. #include <dos.h>
  16. #include <dir.h>
  17. #include <fstream.h>
  18.  
  19.  
  20.  
  21.  /* -------------------------------------------------------------------------------------------------------------------------------
  22.                     *CLASS DECLARATION*
  23. --------------------------------------------------------------------------------------------------------------------------------*/
  24.  
  25.  
  26. class customer
  27. {
  28.           char ph[10];
  29.           char name[30];
  30.           char add[40];
  31.           char type;
  32.      public :
  33.           void append();
  34.           void display();
  35.           void deleter();
  36.           void modify();
  37.           void list();
  38.           void help();
  39. }cust;
  40.  
  41.  
  42.  /* -------------------------------------------------------------------------------------------------------------------------------
  43.                     * FUNCTION TO DISPLAY THE MESSAGE*
  44. --------------------------------------------------------------------------------------------------------------------------------*/
  45.  
  46. void message(char mess[80])
  47. {
  48.      int l,d;
  49.      l=strlen(mess);
  50.      d=l/2;
  51.      gotoxy(2,24);
  52.      textcolor(WHITE+BLINK);
  53.      textbackground(BLACK);
  54.      cout<<("                                                                            ");
  55.      gotoxy(40-d,24);
  56.      clreol();
  57.      cout<<("%s",mess);
  58.      textcolor(BLACK);
  59.      textbackground(WHITE);
  60. }
  61.  
  62. /* -------------------------------------------------------------------------------------------------------------------------------
  63.                     * MAIN FUNCTION *
  64. --------------------------------------------------------------------------------------------------------------------------------*/
  65.  
  66.  void main()
  67. {
  68.      textcolor(BLACK);
  69.      textbackground(WHITE);
  70.      char ch,ch1;
  71.      while(1)
  72.      {
  73.           clrscr();
  74.           textcolor(WHITE);
  75.           textbackground(BLACK);
  76.           gotoxy(25,5);
  77.           cout<<("MAHANAGAR TELEPHONE NIGAM LTD.");
  78.           textcolor(BLACK);
  79.           textbackground(WHITE);
  80.           gotoxy(25,8);
  81.           cout<<"  D    -    Display a Bill";
  82.           gotoxy(25,10);
  83.           cout<<"  L    -    List of customers";
  84.           gotoxy(25,12);
  85.           cout<<"  H    -    Help";
  86.           gotoxy(25,14);
  87.           cout<<"  M    -    Modify a record";
  88.           gotoxy(25,16);
  89.           cout<<"  Q    -    Quit";
  90.           message("Select your choice");
  91.           gotoxy(40,18);
  92.           ch =getch();
  93.           ch = toupper(ch);
  94.           switch(ch)
  95.           {
  96.           case ('Q') : textcolor(WHITE);
  97.                        textbackground(BLACK);
  98.                        clrscr();
  99.                        exit(1);
  100.           case ('D') : cust.display();
  101.                        break;
  102.           case ('L') : cust.list();
  103.                        break;
  104.           case ('H') : cust.help();
  105.                        break;
  106.           case ('M') :
  107.                          ch1 = 'A' ;
  108.                          while(ch1 != 'Q')
  109.                          {
  110.                               clrscr();
  111.                               textcolor(WHITE);
  112.                               textbackground(BLACK);
  113.                               gotoxy(25,5);
  114.                               cout<<("MAHANAGAR TELEPHONE NIGAM LTD.");
  115.                               textcolor(BLACK);
  116.                               textbackground(WHITE);
  117.                               gotoxy(25,9);
  118.                               cout<<"  A    -    Append a record";
  119.                               gotoxy(25,11);
  120.                               cout<<"  D    -    Delete a record";
  121.                               gotoxy(25,13);
  122.                               cout<<"  M    -    Change a record";
  123.                               gotoxy(25,15);
  124.                               cout<<"  Q    -    Quit";
  125.                               message("Select your option");
  126.                               ch1 = getch();
  127.                               ch1 = toupper(ch1);
  128.                               switch(ch1)
  129.                               {
  130.                                    case ('A') : cust.append();
  131.                                                 break;
  132.                                    case ('D') : cust.deleter();
  133.                                                 break;
  134.                                    case ('M') : cust.modify();
  135.                                                 break;
  136.                               }
  137.                     }
  138.  
  139.           }
  140.      }
  141. }
  142.  
  143.  
  144. /* -------------------------------------------------------------------------------------------------------------------------------
  145.             * FUNCTION TO ADD THE CUSTOMER RECORD IN THE FILE*
  146. --------------------------------------------------------------------------------------------------------------------------------*/
  147.  
  148. void customer :: append()
  149. {
  150.      char choice;
  151.      fstream fp;
  152.      fp.open("tphone.dat", ios::app);
  153.      if (!fp)
  154.      {
  155.           cout<<"Unable to open FILE.";
  156.           getch();
  157.           return;
  158.      }
  159.      while(1)
  160.      {
  161.           clrscr();
  162.           gotoxy(3,3);
  163.           cout<<"Customer Record #";
  164.           message("Enter the customer record");
  165.           while(1)
  166.           {
  167.                message("Enter the name");
  168.                gotoxy(3,5);
  169.                cout<<"Name              :   ";
  170.                gotoxy(25,5);
  171.                gets(name);
  172.                if(strlen(name)==0)
  173.                {
  174.                     gotoxy(2,23);
  175.                     clreol();
  176.                     textcolor(WHITE+BLINK);
  177.                     textbackground(BLACK);
  178.                     cout<<("Name cannot be left blank\a");
  179.                     textcolor(BLACK);
  180.                }
  181.                else
  182.                     break;
  183.           }
  184.           while(1)
  185.           {
  186.                message("Enter the address");
  187.                gotoxy(3,6);
  188.                cout<<"Address           :   ";
  189.                gotoxy(25,6);
  190.                gets(add);
  191.                if (strlen(add) != 0)
  192.                break;
  193.           }
  194.  
  195.           while(1)
  196.           {
  197.                gotoxy(3,7);
  198.                cout<<"Assigned Ph. No.  :   ";
  199.                gotoxy(25,7);
  200.                cin>>ph;
  201.                if (ph != 0 )
  202.                     break;
  203.                else
  204.                {
  205.                     gotoxy(25,7);
  206.                     clreol();
  207.                }
  208.           }
  209.           message("Enter O for Office and R for residential phone");
  210.           gotoxy(3,8);
  211.           cout<<"catagory ( O/R )  :   ";
  212.           cin>>type;
  213.           gotoxy(4,10);
  214.           cout<<"1 : Save & Exit    2 :  Save & Cont.   0 : Exit without save";
  215.           gotoxy(4,11);
  216.           cout<<"? ";
  217.           cin>>choice;
  218.           switch(choice)
  219.           {
  220.                case ('1') :      fp.write((char *) this,sizeof(cust));
  221.                               fp.close();
  222.                               return;
  223.                case ('2') :     fp.write((char *) this,sizeof(cust));
  224.                               break;
  225.                case ('0') :   fp.close();
  226.                               return;
  227.                default :      fp.close();
  228.                               return;
  229.           }
  230.      }
  231. }
  232.  
  233. /* -------------------------------------------------------------------------------------------------------------------------------
  234.     * FUNCTION TO DISPLAY THE CUSTOMER RECORD AND CALCULATE THE BILL*
  235. --------------------------------------------------------------------------------------------------------------------------------*/
  236.  
  237. void customer :: display()
  238. {
  239.      char p[10];
  240.      char choice;
  241.      int found=0;
  242.      int no;
  243.      float bill=0.0, tax=0.0, fine=0.0, bbill=0.0, abill=0.0;
  244.      fstream fp;
  245.      fp.open("tphone.dat", ios::in);
  246.      if (!fp)
  247.      {
  248.           cout<<"Unable to open a file";
  249.           getch();
  250.           fp.close();
  251.           return;
  252.      }
  253.      while(choice != '0')
  254.      {
  255.           clrscr();
  256.           gotoxy(3,20);
  257.           cout<<"Please enter the Phone No. ";
  258.           cin>>p;
  259.           if (!strcmp(p,"0"))
  260.                return;
  261.           found = 0;
  262.           fp.seekg(0);
  263.           while (fp.read((char *)this ,sizeof(cust)))
  264.           {
  265.                if (found==1)
  266.                     break;
  267.                if (!strcmp(ph,p))
  268.                {
  269.                     clrscr();
  270.                     gotoxy(28,2);
  271.                     textcolor(BLACK+BLINK) ;
  272.                     textbackground(WHITE);
  273.                     cout<<("MAHANAGAR TELEPHONE BILL");
  274.                     textcolor(WHITE);
  275.                     textbackground(BLACK);
  276.                     gotoxy(3,4);
  277.                     cout<<"Name              :   ";
  278.                     cout<<name;
  279.                     gotoxy(35,5);
  280.                     cout<<"Address           :   ";
  281.                     cout<<add;
  282.                     gotoxy(35,4);
  283.                     cout<<"Assigned Ph. No.  :   ";
  284.                     cout<<ph;
  285.                     gotoxy(3,5);
  286.                     cout<<"Catagory ( O/R )  :   ";
  287.                     cout<<type;
  288.                     gotoxy(23,8);
  289.                     cout<<"___________";
  290.                     gotoxy(10,8);
  291.                     cout<<"No. of calls ";
  292.                     cin>>no;
  293.                     if ( no <= 150 )
  294.                          bill = 0 ;
  295.                     else
  296.                     {
  297.                          no = no - 150;
  298.                          if (toupper(type) == 'O')
  299.                               bill = no * 1.00 ;
  300.                          else
  301.                               bill = no * .80;
  302.                     }
  303.                     gotoxy(10,9);
  304.                     cout<<"Bill";
  305.                     gotoxy(70,9);
  306.                     cout<<bill;
  307.                     tax = (5*bill)/100;
  308.                     gotoxy(10,10 );
  309.                     cout<<"5% Tax";
  310.                     gotoxy(70,10);
  311.                     cout<<tax;
  312.                     gotoxy(10,11);
  313.                     cout<<"Duties";
  314.                     gotoxy(70,11);
  315.                     cout<<"100";
  316.                     int dd,mm,yy;
  317.                     struct date d;   // Getting system Date
  318.                     getdate(&d);
  319.                     dd = d.da_day;
  320.                     mm = d.da_mon;
  321.                     yy = d.da_year;
  322.                     gotoxy(10,15)    ;
  323.                     cout<<"TOTAL BILL before " ;
  324.                     cout<<dd<<"/"<<mm<<"/"<<yy;
  325.                     bbill = bill+tax+100;
  326.                     gotoxy(70,15);
  327.                     cout<<bbill;
  328.                     gotoxy(10,17);
  329.                     cout<<"Late Fine";
  330.                     fine = (bbill*5)/100;
  331.                     gotoxy(70,17);
  332.                     cout<<fine;
  333.                     gotoxy(10,21);
  334.                     cout<<"TOTAL BILL after ";
  335.                     cout<<dd<<"/"<<mm<<"/"<<yy;
  336.                     abill = bbill+fine;
  337.                     gotoxy(70,21);
  338.                     cout<<abill;
  339.                     found = 1;
  340.                     message("Press a Key");
  341.                     getch();
  342.                }
  343.           }
  344.           message("Enter 1 or 2 to cont.");
  345.           gotoxy(4,22);
  346.           cout<<"1 :  Cont.   0 : Exit ";
  347.           cout<<"? ";
  348.           cin>>choice;
  349.           switch(choice)
  350.           {
  351.                case ('1') :
  352.                          break;
  353.                case ('0') : return;
  354.                default : return;
  355.           }
  356.  
  357.      }
  358.      fp.close();
  359. }
  360.  
  361.  
  362. /* -------------------------------------------------------------------------------------------------------------------------------
  363.         * FUNCTION TO DISPLAY THE LIST OF THE CUSTOMERS*
  364. --------------------------------------------------------------------------------------------------------------------------------*/
  365.  
  366. void customer :: list()
  367. {
  368.      clrscr();
  369.      fstream fp;
  370.      int r;
  371.      fp.open("tphone.dat", ios::in);
  372.      if (!fp)
  373.      {
  374.           cout<<"Unable to open";
  375.           getch();
  376.           fp.close();
  377.           return;
  378.      }
  379.      gotoxy(35,2);
  380.      cout<<"List of Customers";
  381.      gotoxy(35,3);
  382.      cout<<"*****************";
  383.      gotoxy(5,4);
  384.      cout<<"Name";
  385.      gotoxy(40,4);
  386.      cout<<"Phone No.";
  387.      gotoxy(65,4);
  388.      cout<<"Catagory";
  389.      gotoxy(1,5);
  390.      cout<<"*******************************************************************************";
  391.      r=6;
  392.      while (fp.read((char *) this, sizeof(cust)))
  393.      {
  394.           if (r >= 21)
  395.           {
  396.                message("Press a key");
  397.                getch();
  398.                clrscr();
  399.                gotoxy(35,2);
  400.                cout<<"List of customers";
  401.                gotoxy(35,3);
  402.                cout<<"*****************";
  403.                gotoxy(5,4);
  404.                cout<<"Name";
  405.                gotoxy(40,4);
  406.                cout<<"Phone No.";
  407.                gotoxy(65,4);
  408.                cout<<"Catagory";
  409.                gotoxy(1,5);
  410.                cout<<"*******************************************************************************";
  411.                r=6;
  412.           }
  413.           gotoxy(5,r);
  414.           cout<<name;
  415.           gotoxy(40,r);
  416.           cout<<ph;
  417.           gotoxy(65,r);
  418.           if (toupper(cust.type) == 'O')
  419.                cout<<"Office";
  420.           else
  421.                cout<<"Residential";
  422.           r++;
  423.      }
  424.      message("Press a key");
  425.      getch();
  426.      fp.close();
  427. }
  428.  
  429. /* -------------------------------------------------------------------------------------------------------------------------------
  430.         * FUNCTION TO DELETE THE RECORD OF CUSTOMER FROM THE FILE*
  431. --------------------------------------------------------------------------------------------------------------------------------*/
  432.  
  433. void customer :: deleter()
  434. {
  435.      char ch;
  436.      char p[10];
  437.      fstream temp,fp;
  438.      fp.open("tphone.dat", ios::in);
  439.      if (!fp)
  440.      {
  441.           cout<<"Unable to open Telephone file";
  442.           getch();
  443.           fp.close();
  444.           return;
  445.      }
  446.      temp.open("temp.dat", ios::out);
  447.      if (!temp)
  448.      {
  449.           cout<<"Unable to open Temporary file";
  450.           getch();
  451.           temp.close();
  452.           return;
  453.      }
  454.      clrscr();
  455.      gotoxy(5,3);
  456.      cout<<"Enter the Phone No. to be deleted : ";
  457.      cin>>p;
  458.      if(!strcmp(p,"0"))
  459.           return;
  460.      int found=0;
  461.      while (fp.read((char *) this, sizeof(cust)))
  462.      {
  463.           if (!strcmp(p,ph))
  464.           {
  465.                found = 1;
  466.                gotoxy(5,5);
  467.                cout<<"Name       "<<name;
  468.                gotoxy(5,6);
  469.                cout<<"Address    " <<add;
  470.                gotoxy(5,7);
  471.                cout<<"Catagory   "<<type;
  472.                gotoxy(6,10);
  473.                cout<<"Delete this record (Y/N) ";
  474.                cin>>ch;
  475.                if (toupper(ch) == 'N')
  476.                     temp.write((char *) this,sizeof(cust));
  477.           }
  478.           else
  479.                temp.write((char *) this,sizeof(cust));
  480.      }
  481.      fp.close();
  482.      temp.close();
  483.      if (toupper(ch) == 'N')
  484.           return;
  485.      if (!found)
  486.      {
  487.           cout<<"\n\nTelephone no. not found";
  488.           getch();
  489.           return;
  490.      }
  491.      fp.open("tphone.dat", ios::out);
  492.      temp.open("temp.dat", ios::in);
  493.      while (temp.read((char *) this, sizeof(cust)))
  494.           fp.write((char *) this, sizeof(cust));
  495.      fp.close();
  496.      temp.close();
  497. }
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506. /* -------------------------------------------------------------------------------------------------------------------------------
  507.         * FUNCTION TO MODIFY THE RECORD OF CUSTOMER FROM THE FILE*
  508. --------------------------------------------------------------------------------------------------------------------------------*/
  509.  
  510.  void customer :: modify()
  511. {
  512.      char ch;
  513.      char p[10];
  514.      fstream temp,fp;
  515.      fp.open("tphone.dat", ios::in);
  516.      if (!fp)
  517.      {
  518.           cout<<"Unable to open Telephone file";
  519.           getch();
  520.           fp.close();
  521.           return;
  522.      }
  523.      temp.open("temp.dat", ios::out);
  524.      if (!temp)
  525.      {
  526.           cout<<"Unable to open Temporary file";
  527.           getch();
  528.           temp.close();
  529.           return;
  530.      }
  531.      clrscr();
  532.      gotoxy(5,3);
  533.      cout<<"Enter the Phone No. to be Modify : ";
  534.      cin>>p;
  535.      if(!strcmp(ph,"0"))
  536.           return;
  537.      int found=0;
  538.      while (fp.read((char *) this, sizeof(cust)))
  539.      {
  540.           if (!strcmp(p,ph))
  541.           {
  542.                found = 1;
  543.                gotoxy(5,5);
  544.                cout<<"Name       "<<name;
  545.                gotoxy(5,6);
  546.                cout<<"Address    " <<add;
  547.                gotoxy(5,7);
  548.                cout<<"Catagory   "<<type;
  549.                gotoxy(6,10);
  550.                cout<<"Modify this record (Y/N) ";
  551.                cin>>ch;
  552.                if (toupper(ch) == 'Y')
  553.                {
  554.                     gotoxy(3,13);
  555.                  
  556.    cout<<"Customer Record #";
  557.                     message("Enter the customer record");
  558.                     while(1)
  559.                     {
  560.                          gotoxy(3,15);
  561.                          cout<<"Name              :   ";
  562.                          gets(name);
  563.                          if (strlen(name) != 0)
  564.                               break;
  565.                     }
  566.                     gotoxy(3,16);
  567.                     cout<<"Address           :   ";
  568.                     gets(add);
  569.                     while(1)
  570.                     {
  571.                          gotoxy(3,17);
  572.                          cout<<"Assigned Ph. No.  :   ";
  573.                          cin>>ph;
  574.                          if (ph != 0 )
  575.                               break;
  576.                     }
  577.                     message("Enter O for Office and R for residential phone");
  578.                     gotoxy(3,18);
  579.                     cout<<"catagory ( O/R )      :   ";
  580.                     cin>>type;
  581.                }
  582.           }
  583.           temp.write((char *) this,sizeof(cust));
  584.      }
  585.      fp.close();
  586.      temp.close();
  587.      if (toupper(ch) == 'N')
  588.           return;
  589.      if (!found)
  590.      {
  591.           cout<<"\n\nTelephone no. not found";
  592.           getch();
  593.           return;
  594.      }
  595.      fp.open("tphone.dat", ios::out);
  596.      temp.open("temp.dat", ios::in);
  597.      while (temp.read((char *) this, sizeof(cust)))
  598.           fp.write((char *) this, sizeof(cust));
  599.      fp.close();
  600.      temp.close();
  601. }
  602.  
  603.  
  604.  
  605.  
  606.  
  607.  
  608. /* -------------------------------------------------------------------------------------------------------------------------------
  609.         * FUNCTION TO DISPLAY THE DISCRIPTION FOR THE PROJECT WORKING*
  610. --------------------------------------------------------------------------------------------------------------------------------*/
  611.  
  612. void customer :: help()
  613. {
  614.      clrscr();
  615.      gotoxy(35,2);
  616.      textcolor(WHITE + BLINK);
  617.      textbackground(BLACK);
  618.      cout<<(" HELP ");
  619.  
  620.  
  621.     textcolor(BLACK);
  622.      textbackground(WHITE);
  623.      gotoxy(8,5);
  624.      cout<<"This software is used to create a telephone bill for the customers. ";
  625.      gotoxy(8,7);
  626.      cout<<"There are two catagories of the customers. First catagories is  of";
  627.      gotoxy(8,9);
  628.      cout<<"Residential phones and second catagories is of Office phones. Both";
  629.      gotoxy(8,11);
  630.      cout<<"the catagories have different charges of the telephone bill. Charges";
  631.      gotoxy(8,13);
  632.      cout<<"of residential phones are 80 Paise per call and Charges of Office ";
  633.      gotoxy(8,15);
  634.      cout<<"office phones are Rs. 1 per call. 150 call are free for each catogory";
  635.      gotoxy(8,17);
  636.      cout<<"Total bill for is equal to 5% tax plus 100 rupees charges for  other";
  637.      gotoxy(8,19);
  638.      cout<<"charges. If bill is not paid before the paticular date then penalty ";
  639.      gotoxy(8,21);
  640.      cout<<"should also be given.";
  641.      getch();
  642. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement