Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #include <process.h>
- #include <ctype.h>
- #include <fstream.h>
- class customer
- {
- char ph[10];
- char name[30];
- char add[40];
- char type;
- public :
- void append();
- void display();
- void del();
- void modify();
- void list();
- void help();
- }cust;
- void customer::append()
- {
- char choice;
- fstream f;
- f.open("tphone.dat", ios::app);
- if (!f)
- { cout<<"\n Unable to open FILE.";
- getch();
- return;
- }
- while(1)
- { clrscr();
- cout<<"\n\n***********************************************************************";
- cout<<"\n CUSTOMER RECORD";
- cout<<"\n\n***********************************************************************";
- while(1)
- { cout<<"\n\tEnter the name";
- cout<<"\nName : ";
- gets(name);
- if(strlen(name)==0)
- cout<<"\n\n\tName cannot be left blank\a\a";
- else
- break;
- }
- while(1)
- { cout<< "\n\tEnter the address";
- cout<<"\n Address : ";
- gets(add);
- if (strlen(add) != 0)
- break;
- }
- while(1)
- { cout<<"\nEnter TelePhone. No. : ";
- cin>>ph;
- if (ph != 0 )
- break;
- else
- {
- cout<<"\n\n\tTelePhone no. cannot be left blank\a\a";
- }
- }
- while(1)
- { cout<< "Enter O for Office and R for residential phone";
- cout<<"catagory ( O/R ) : ";
- cin>>type;
- if (type=='o'||type=='O'||type=='r'||type=='R')
- break;
- else{cout<<"\n Wrong choise...";
- }
- }
- cout<<"\n\n**********************************************************************";
- cout<<"\n 1 : Save & Exit 2 : Save & Cont. 0 : Exit without save";
- cout<<"\n\n**********************************************************************";
- cin>>choice;
- switch(choice)
- {
- case ('1') : f.write((char *) this,sizeof(cust));
- f.close();
- return;
- case ('2') : f.write((char *) this,sizeof(cust));
- break;
- case ('0') : f.close();
- return;
- default : f.close();
- return;
- }
- }
- void customer :: display()
- {
- char p[10];
- char choice;
- int found=0;
- int no;
- long float bill=0.0, tax=0.0, bbill=0.0,rent;
- fstream f;
- f.open("tphone.dat", ios::in);
- if (!f)
- { cout<<"Unable to open a file";
- getch();
- f.close();
- return;
- }
- while(choice != '0')
- {
- clrscr();
- cout<<"Please enter the Phone No. ";
- cin>>p;
- if (!strcmp(p,"0"))
- return;
- found = 0;
- f.seekg(0);
- while (f.read((char *)this ,sizeof(cust)))
- {
- if (found==1)
- break;
- if (!strcmp(ph,p))
- {
- clrscr();
- cout<<"\n\n===================================================";
- cout<<"\n\t TELEPHONE BILL";
- cout<<"\n\n===================================================";
- cout<<"\n\n Name :- \t ";
- cout<<name;
- cout<<"\n Address :- \t ";
- cout<<add;
- cout<<"\n TelePhone No. :- \t ";
- cout<<ph;
- cout<<"\n Catagory ( O/R ) :- \t ";
- cout<<type;
- cout<<"\nNo. of calls :- \t ";
- cin>>no;
- if ( no<=150)
- {if (toupper(type) == 'O')
- { bill=0;
- rent=150; }
- else
- bill=0;rent=200;}
- if( no>150)
- { no = no - 150;
- if (toupper(type) == 'O')
- { bill =(no * 1.00) ; rent=150;
- }
- else
- {bill = (no * .80);
- rent=200;
- }}
- cout<<"\n=====================================================";
- cout<<"\n Charge :";
- cout<<bill;
- tax = (5*bill)/100;
- cout<<"\n Service tax(5% ): Rs ";
- cout<<tax;
- cout<<"\n Rent :- \nRs ";
- cout<<rent;
- cout<<"\n--------------------------------------------------------------------------------------------";
- cout<<"\n\n\tTOTAL BILL : Rs " ;
- bbill = bill+tax+rent;
- cout<<bbill;
- cout<<"\n======================================================";
- found = 1;
- cout<< "\n Press a Key to continue";
- getch();
- }
- }
- cout<<"\n=====================================================";
- cout<<"\n\n 1 : Cont. 0 : Exit ";
- cout<<"\n=====================================================";
- cin>>choice;
- switch(choice)
- {
- case ('1') :
- break;
- case ('0') : return;
- default : return;
- }}
- f.close();
- }
- void customer :: list()
- {
- clrscr();
- fstream fp;
- int r;
- fp.open("tphone.dat", ios::in);
- if (!fp)
- {
- cout<<"Unable to open";
- getch();
- fp.close();
- return;
- }
- gotoxy(35,2);
- cout<<"List of Customers";
- gotoxy(35,3);
- cout<<"*****************";
- gotoxy(5,4);
- cout<<"Name";
- gotoxy(40,4);
- cout<<"Phone No.";
- gotoxy(65,4);
- cout<<"Catagory";
- gotoxy(1,5);
- cout<<"**************************************************************************";
- r=6;
- while (fp.read((char *) this, sizeof(cust)))
- {
- if (r >= 21)
- {
- getch();
- clrscr();
- gotoxy(35,2);
- cout<<"List of customers";
- gotoxy(35,3);
- cout<<"*****************";
- gotoxy(5,4);
- cout<<"Name";
- gotoxy(40,4);
- cout<<"Phone No.";
- gotoxy(65,4);
- cout<<"Catagory";
- gotoxy(1,5);
- cout<<"***************************************************************************";
- r=6;
- }
- gotoxy(5,r);
- cout<<name;
- gotoxy(40,r);
- cout<<ph;
- gotoxy(65,r);
- if (toupper(cust.type) == 'O')
- cout<<"Office";
- else
- cout<<"Residential";
- r++;
- }
- cout<<"\n\n\nPress any key to continue ...";
- getch();
- fp.close();
- }
- void customer :: del()
- {
- char ch;
- char p[10];
- fstream tp,f;
- f.open("tphone.dat", ios::in);
- if (!f)
- {
- cout<<"Unable to open Telephone file";
- getch();
- f.close();
- return;
- }
- tp.open("temp.dat", ios::out);
- if (!tp)
- {cout<<"Unable to open Temporary file";
- getch();
- tp.close();
- return;
- }
- clrscr();
- cout<<"\n\n***********************************************************************";
- cout<<"\n Enter the Phone No. to be deleted : ";
- cin>>p;
- if(!strcmp(p,"0"))
- return;
- int found=0;
- while (f.read((char *) this, sizeof(cust)))
- {
- if (!strcmp(p,ph))
- {
- found = 1;
- cout<<"\n Name : "<<name;
- cout<<"\n Address : " <<add;
- cout<<"\n Catagory : "<<type;
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n Delete this record (Y/N) ";
- cin>>ch;
- if (toupper(ch) == 'N')
- tp.write((char *) this,sizeof(cust));
- }
- else
- tp.write((char *) this,sizeof(cust));
- }
- f.close();
- tp.close();
- if (toupper(ch) == 'N')
- return;
- if (!found)
- {
- cout<<"\n\nTelephone no. not found";
- getch();
- return;
- }
- f.open("tphone.dat", ios::out);
- tp.open("temp.dat", ios::in);
- while (tp.read((char *) this, sizeof(cust)))
- f.write((char *) this, sizeof(cust));
- f.close();
- tp.close();
- }
- void customer :: modify()
- {
- char ch;
- char p[10];
- fstream tp,f;
- f.open("tphone.dat", ios::in);
- if (!f)
- {
- cout<<"\n Unable to open Telephone file";
- getch();
- f.close();
- return;
- }
- tp.open("temp.dat", ios::out);
- if (!tp)
- {
- cout<<"\n Unable to open Temporary file";
- getch();
- tp.close();
- return;
- }
- clrscr();
- cout<<"\n\n***********************************************************************";
- cout<<"\n Enter the Phone No. to be Modify : ";
- cin>>p;
- if(!strcmp(ph,"0"))
- return;
- int found=0;
- while (f.read((char *) this, sizeof(cust)))
- {
- if (!strcmp(p,ph))
- {
- found = 1;
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n Name "<<name;
- cout<<"\n Address " <<add;
- cout<<"\n Catagory "<<type;
- cout<<"\n\n**********************************************************************";
- cout<<"\n\n Modify this record (Y/N) ";
- cin>>ch;
- if (toupper(ch) == 'Y')
- {
- cout<<"\n\n***********************************************************************"; cout<<"\n CUSTOMER RECORD";
- cout<< "\n Enter the customer record";
- while(1)
- {
- cout<<"\n\n Name : ";
- gets(name);
- if (strlen(name) != 0)
- break;
- }
- cout<<"\n Address : ";
- gets(add);
- while(1)
- {
- cout<<"\n Assigned Ph. No. : ";
- cin>>ph;
- if (ph != 0 )
- break;
- }
- { cout<< "Enter O for Office and R for residential phone";
- cout<<"catagory ( O/R ) : ";
- cin>>type;
- } } }
- tp.write((char *) this,sizeof(cust));
- }
- f.close();
- tp.close();
- if (toupper(ch) == 'N')
- return;
- if (!found)
- {
- cout<<"\n\n Telephone no. not found....!!";
- getch();
- return;
- }
- f.open("tphone.dat", ios::out);
- tp.open("temp.dat", ios::in);
- while (tp.read((char *) this, sizeof(cust)))
- f.write((char *) this, sizeof(cust));
- f.close();
- tp.close();
- }
- void customer :: help()
- {
- clrscr();
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n This program is used to create a telephone bill for the customers. ";
- cout<<"\n There are two categories of the customers. First categories is of";
- cout<<" \n Residential phones and second categories is of Office phones. Both";
- cout<<"\n the categories have different charges of the telephone bill. Charges";
- cout<<"\n of residential phones are 80 Paisa per call and Charges of Office ";
- cout<<"\n office phones are Rs. 1 per call. 150 call are free for each category";
- cout<<"\n Total bill for is equal to 5% tax plus and there is a fixed monthly charge ";
- cout<<"\n called rent for Office customers rent is Rs.150 and for Residential customers it is Rs.200. ";
- cout<<"\n CREATED BY-\n\t Anmol Shrivastava , Ankit Puri & Manish Pandey";
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n***********************************************************************";
- getch();
- }
- void main()
- {
- clrscr();
- char pass[10];
- cout<<"enter your password "<<endl;
- for(int i=0;i<5;i++)
- {
- pass[i]=getch();
- cout<<"*";
- }
- if(strcmp(pass,"password")==0)
- {
- cout<<endl;
- char ch,ch1;
- while(1)
- {
- cout<<"****************************************************************************";
- cout<<"\n\t\t\t BHARAT SANCHAR NIGAM LIMITED (B.S.N.L)";
- cout<<"\n\n***********************************************************************";
- cout<<"\n\n\n\n\n\t\t D - Display a Bill";
- cout<<"\n\n\t\t L - List of customers";
- cout<<"\n\n\t\t H - Help";
- cout<<"\n\n\t\t R - Enter \ Modify a record";
- cout<<"\n\n\t\t Q - Quit";
- cout<<"\nEnter your choise :";
- cin>>ch;
- ch = toupper(ch);
- switch(ch)
- {
- case ('Q') :clrscr();
- cout<<"***************************************************************************";
- cout<<" \n\n\t Thank you for using Hybrid telephone billing program\n\n\n"; cout<<"Good Bye \n\n\t";
- cout<<"\n\n\n CREATED BY- Ankit Puri , Anmol Shrivastava & Manish Pandey ";
- cout<<"\n\n***********************************************************************";
- getch();
- exit(0);
- case ('D') : cust.display();
- break;
- case ('L') : cust.list();
- break;
- case ('H') : cust.help();
- break;
- case ('R') :
- ch1 = 'A' ;
- while(ch1 != 'Q')
- {
- clrscr();
- cout<<"***************************************************************************";cout<<"\n\n\t\t\t BHARAT SANCHAR NIGAM LIMITED (B.S.N.L)";
- cout<<"\n\n***********************************************************************";
- cout<<" \n\n\t A - Append a record";
- cout<<" \n\t D - Delete a record";
- cout<<" \n\t M - Change a record";
- cout<<" \n\t Q - Quit";
- cout<< "\n\n\tSelect your choice :- ";
- cout<<"\n\n***********************************************************************";
- cin>> ch1;
- ch1 = toupper(ch1);
- switch(ch1)
- {
- case ('A') : cust.append();
- break;
- case ('D') : cust.del();
- break;
- case ('M') : cust.modify();
- break;
- }
- }
- }