Electric Bill
Electric Bill
h>
#include<dos.h>
#include<iomanip.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<math.h>
#include<fstream.h>
void main();
void search();
void layout();
void submenu();
void load()
{
delay(1000);
int i;
clrscr();
textcolor(WHITE);
textbackground(BLACK);
clrscr();
gotoxy(20,15);
cout<<"LOADING.....";
for(i=1;i<=55;i++)
{
gotoxy(12+i,19);
cout<<"";
}
for(i=1;i<=10;i++)
{
gotoxy(67,i+19);
cout<<"";
gotoxy(13,i+19);
cout<<"";
}
for(i=1;i<=55;i++)
{
gotoxy(12+i,29);
cout<<"";
}
for(i=1;i<50;i++)
{
gotoxy(28,35);
cout<<2*i<<" % complete";
}
for(i=1;i<=50;i++)
{
gotoxy(14+i,24);
cout<<"";
gotoxy(14+i,25);
cout<<"";
gotoxy(28,35);
cout<<2*i<<" % complete";
delay(150);
}
clrscr();
}
int s=0;
class EBill
{
private:
char name[30],cat;
long acc;
long unit;
double amt;
public:
void input();
EBill search();
void cal()
{
if(cat=='D')
{
if(unit<=100) amt=(float)unit*1.40;
if(unit>100 && unit<=200) amt=(float)100*1.40+(u
nit%100)*3.10;
if(unit>200) amt=(float)(unit%200)*4.10+200*3.10
;
}
if(cat=='C')
{
if(unit<=100) amt=(float)unit*4.20;
if(unit>100 && unit<=300) amt=unit*5.30;
if(unit>300) amt=(float)unit*5.90;
}
display();
}
long retacc()
{
return acc;
}
void getcat(char ch)
{
cat=ch;
}
void getname(char ptr[30])
{
strcpy(name,ptr);
}
void disp()
{
cout<<"\nConsumer name
cout<<"\nAccount No
cout<<"\nCategory
}
void display()
{
layout();
gotoxy(5,7);
cout<<"CONSUMER NAME :
gotoxy(5,8);
cout<<"ACCOUNT NO. :
gotoxy(5,9);
cout<<"CATEGORY
:
gotoxy(5,10);
cout<<"ENERGY UNIT :
gotoxy(5,15);
cout<<"ENERGY CHARGE :
if(unit>0&&unit<=100)
{
gotoxy(23,27);
: "<<name;
: "<<acc;
: "<<cat;
"<<name<<endl;
"<<acc<<endl;
"<<cat<<endl;
"<<unit<<endl;
"<<setprecision(2)<<amt<<endl;
cout<<unit<<"* 1.40";
}else
if(unit>100&&unit<=200)
{
gotoxy(23,27);
cout<<"100* 1.40";
gotoxy(23,28);
cout<<unit-100<<"* 3.10";
}
else
{
gotoxy(23,27);
cout<<"100* 1.40";
gotoxy(23,28);
cout<<"100* 3.10";
gotoxy(23,29);
cout<<unit-100<<"* 4.10";
}
gotoxy(5,12);
cout<<"FIX/DEM CHARGES: 20.00"<<endl;
gotoxy(5,13);
cout<<"METER RENT
: 40.00"<<endl;
gotoxy(5,14);
cout<<"ELEC. DUTY
: 6.00"<<endl;
double e=amt+20.00+40.00+6.00;
gotoxy(5,32);
cout<<"PRESS BILL AMT: "<<setprecision(2)<<e<<endl;
gotoxy(5,38);
cout<<"Net Bill Amt : "<<setprecision(2)<<ceil(e)<<endl
;
}
};
void EBill::input()
{
cout<<"\nEnter Consumer name : ";
gets(name);
strupr(name);
cout<<"\nEnter The account no : ";
cin>>acc;
C:
cout<<"\nEnter Category [D/d-> Domestic and C/c-> Commercial] : ";
cat=toupper(getche());
if(cat=='C' || cat=='D'){}
else {cout<<"\n\nInvalid Category";goto C;}
cout<<"\n\nEnter the Energy in Unit : ";
cin>>unit;
}
EBill EBill::search()
{
long ac;
clrscr();
fstream file;
cout<<"Enter Account No. to View : ";
cin>>ac;
//if(ac==0) return;
int flag=0;
cout<<"=================================================================
===============";
cout<<"\t\t\t
Current Consumer Details"<<endl;
cout<<"=================================================================
===============";
file.open("bill.txt",ios::in);
EBill e,t;
while((file.read((char*)&e,sizeof(e)))!=NULL)
{
if(ac==e.retacc())
{
e.disp();
t=e;
cout<<"\n
cout<<"\n
flag=1;
getch();
break;
}
}
file.close();
if(flag==0)cout<<"\nSuch record is not found ";
else return t;
cout<<"\n\nPress any key to back";
getch();
//return;
}
void submenu()
{
int P,flag;
long ac;
fstream file,temp;
EBill e,te;
topp:
clrscr();
cout<<endl<<endl;
cout<<"*****************************************************************
***************";
cout<<endl;
cout<<"\t\t\t
CONSUMER SECTION";
cout<<endl;
cout<<"\t\t\t
================";
cout<<endl<<endl<<endl;
cout<<"\t\t\t\t1) ADD\n\n";
cout<<"\t\t\t\t2) EDIT\n\n";
cout<<"\t\t\t\t3) DELETE\n\n";
cout<<"\t\t\t\t4) VIEW \n\n";
cout<<"\t\t\t\t5) BACK to MAIN";
cout<<endl<<endl<<endl;
cout<<"*****************************************************************
***************";
cout<<endl<<"
Enter Your Choice
: ";
cin>>P;
switch(P)
{
case 1:
char ch;
EBill ea;
file.open("bill.txt",ios::app);
do
{
clrscr();
ea.input();
file.write((char*)&ea,sizeof(ea));
clrscr();
char n[30],ct;
EBill eb;
cout<<"Enter Account No. to Edit : ";
cin>>ac;
if(ac==0) goto END2;
flag=0;
cout<<"\n===============================================
================================";
cout<<"\n\t\t\t Current Consumer Details"<<endl;
cout<<"\n===============================================
=================================";
file.open("bill.txt",ios::in);
temp.open("temp.txt",ios::out);
file.read((char*)&e,sizeof(e));
while(!file.eof())
{
if(ac==e.retacc())
{
e.disp();
flag=1;
cout<<"\n===============================
=================================================";
cout<<"\n\t\t\t\t Edit What ??????
"<<endl;
cout<<"\n
cout<<endl<<"\t
1.Name
2.Cat
egory
3.Don't Edit"<<endl;
cout<<"\n
int t;
cout<<"Enter Option : ";cin>>t;
if(t==1)
{
cout<<"\nEnter Name : ";
gets(n);
strupr(n);
e.getname(n);
}
else if(t==2)
{
C:
cout<<"\nEnter Category [D/d-> D
omestic and C/c-> Commercial] : ";
ct=toupper(getche());
if(ct=='C' || ct=='D'){}
else{cout<<"\n\nInvalid Category
";goto C;}
e.getcat(ct);
}
else if(t==3)
break;
else
cout<<"\n\nWrong choice .. Retry
aganin";
if(t==1||t==2)
{
temp.write((char*)&e,sizeof(e));
cout<<"\n\nCurrent record is Mod
ifyed, Thank You";
cout<<"\n\nPress any key......."
;
getch();
}
}
else
{
temp.write((char*)&e,sizeof(e));
}
file.read((char*)&e,sizeof(e));
}
file. close();temp.close();
remove("bill.txt");
rename("temp.txt","bill.txt");
END2:
if(flag==0)cout<<"Such record is not found ";
goto topp;
case 3:
clrscr();
cout<<"Enter Account No. to Delete : ";
cin>>ac;
if(ac==0) goto END3;
flag=0;
cout<<"\n===============================================
================================";
cout<<"\n\t\t\t Current Consumer Details"<<endl;
cout<<"\n===============================================
=================================";
file.open("bill.txt",ios::in);
temp.open("temp.txt",ios::out);
file.read((char*)&e,sizeof(e));
while(!file.eof())
{
if(ac==e.retacc())
{
e.disp();
flag=1;
cout<<"\n===============================
=================================================";
cout<<"\n\t\t\t Are You Delete this Det
ails ??????
"<<endl;
cout<<"\n
cout<<endl<<"\t1.Delete 2.Don't Delete"
<<endl;
cout<<"\n
int t;
cout<<"Enter Option : ";cin>>t;
if(t==1)
{
cout<<"\n\nCurrent Account No. D
etails is Deleted From Database";
cout<<"\n\nPress any key to Retu
rn";
getch();
}
else
{
temp.write((char*)&e,sizeof(e));
}
}
else
temp.write((char*)&e,sizeof(e));
file.read((char*)&e,sizeof(e));
}
file. close();temp.close();
remove("bill.txt");
rename("temp.txt","bill.txt");
END3:
if(flag==0){cout<<"Such record is not found ";getch();}
goto topp;
case 4:
clrscr();
e.search();
char ch1;
cout<<"\n\n\n\n\nPrint details (y/n)";
ch1=getche();
if(ch1=='y'||ch1=='Y')
{layout();
e.display();}
goto topp;
case 5:
main();
break;
default:
cout<<"\n\n\nWrong choice ... press any key to retry";
getch();
goto topp;
}
}
void main()
{
if(s==0)
{
load();
s++;
}
int x=0;
EBill e,tt;
top:
clrscr();
gotoxy(1,5);
cout<<"=========================================================================
=======";
gotoxy(32,6);
cout<<"ELECTRICITY BILLER";
cout<<endl;
cout<<"=========================================================================
=======";
gotoxy(27,10);
cout<<"1) ENTER CUSTOMER DATABASE";
gotoxy(27,13);
cout<<"2) ENTER BILL DATABASE";
gotoxy(27,16);
cout<<"3) ENTER BILLING DETAILS";
gotoxy(27,19);
cout<<"4) EXIT FROM PROGRAM"<<endl<<endl;
cout<<"=========================================================================
=======";
cout<<endl<<"
Enter Your Choice
: ";
gotoxy(1,25);
cout<<"=========================================================================
=======";
gotoxy(35,23);
cin>>x;
switch(x)
{
case 1:
submenu();
goto top;
case 2:
tt=e.search();clrscr();tt.cal();getch();
goto top;
case 3:
clrscr();
cout<<"\n\n\n
[ BILLING DETAILS ]";
cout<<"\n\n\n
ENERGY CHARGES [ DOMESTIC CONSUME
R ]";
cout<<"\n
cout<<"\n
FROM(>=) UNITS PER MTH TO(<=) UNITS PER MTH PER UN
IT(Rs.) ";
cout<<"\n
cout<<"\n
100
1.40 ";
cout<<"\n
101
200
3.10 ";
cout<<"\n
cout<<"\n
4.10 ";
cout<<"\n
cout<<"\n\n\n\n\n\n\n
AL CONSUMER ]";
cout<<"\n
cout<<"\n
cout<<"\n
cout<<"\n
100
cout<<"\n
cout<<"\n
cout<<"\n
IT(Rs.) ";
4.20
";
5.30
";
5.90
101
300
";
cout<<"\n
cout<<"\n\n\n
Press any key to back";
getch();
goto top;
case 4:
goto end;
default:
cout<<"\n\n\nWrong choice ... press any key to retry";
getch();
goto top;
}
end:;
}
void layout()
{
clrscr();
cout<<"\n
cout<<"\n
WESTERN ELECTRICITY COMPANY LIMITED
";
cout<<"\n
cout<<"\n
BILLING DETAILS
";
cout<<"\n
cout<<"\n
CONSUMER DETAILS:
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
";
cout<<"\n
cout<<"\n
";
cout<<"\n
BILL
SLABS
";
cout<<"\n
cout<<"\n
";
cout<<"\n
SLAB1(1-100):
";
cout<<"\n
SLAB2(101-200):
";
cout<<"\n
SLAB3(>200):
";
cout<<"\n
";
cout<<"\n
cout<<"\n
";
cout<<"\n
";
cout<<"\n
(to be payed by due date ,ie.,30 of current month)
";
cout<<"\n
";
cout<<"\n
cout<<"\n
";
cout<<"\n
LATE FEES :Rs.20
";
cout<<"\n
";
cout<<"\n
(to be payed after due date)
";
cout<<"\n
}