dknlkndfkndf#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h> //for exit function
#include<time.h>
class LIC
{
char name[30],gender[10],nationality[15],occupation[16]; char address[150],fathersname[80]; long sum_ass,premium,cno; long income; int agentid,p_no,p_code,years; struct date //for input of dates { int dd,mm,yy; } dos,dob;
public: date dom; void getinfo(); void basicshowinfo(); void getpolicy_code(); void licshowinfo(); int getp_no(); void mod(); int rp_code();
} l1,l2; int LIC::rp_code() //acessor function
{
return p_code;
}
void LIC::getinfo()
{
cout<<"\nENTER THE NAME:"<<" "; gets(name); cout<<"\nENTER THE FATHER'S NAME:"<<" "; gets(fathersname); cout<<"\nENTER THE GENDER: "<<" "; gets(gender); cout<<"\nENTER THE ADDRESS:"<<" "; gets(address); cout<<"\nENTER THE NATIONALITY:"<<" "; gets(nationality); cout<<"\nENTER THE DATE OF BIRTH (dd\mm\yy):"<<" "; cin>>dob.dd>>dob.mm>>dob.yy; cout<<"\nENTER THE ANNUAL INCOME:"<<" "; cin>>income; cout<<"\nENTER THE CONTACT NUMBER:"<<" "; cin>>cno; cout<<"\nENTER THE AGENT ID:"<<" "; cin>>agentid; cout<<"\nENTER THE DATE OF START(dd\mm\yy):"<<" "; cin>>dos.dd>>dos.mm>>dos.yy; cout<<"\nENTER THE DURATION OF POLICY (1 YEAR OR 2 YEARS):"<<" "; cin>>years; cout<<"\nENTER THE POLICY HOLDER NUMBER:"<<" "; cin>>p_no; cout<<endl; cout<<"\t\tPOLICY LIST\n" ; cout<<endl; cout<<"\n1.JEEVAN SARAL"; cout<<"\n2.JEEVAN ANAND" ; cout<<"\n3.JEEVAN CHAYA"; cout<<"\n4.JEEVAN VRIDHI"; cout<<endl; cout<<"\nENTER THE POLICY CODE(1-4):"<<" "; cin>>p_code;
}
void LIC::basicshowinfo()
{
cout<<"\nNAME:"<<"\t\t\t"; puts(name); cout<<"\nFATHER'S NAME:"<<"\t\t\t"; puts(fathersname); cout<<"\nGENDER:"<<"\t\t\t"; puts(gender); cout<<"\nADDRESS:"<<"\t\t\t"; puts(address); cout<<"\nNATIONALITY:"; puts(nationality); cout<<"\nDATE OF BIRTH:"<<"\t\t\t"; cout<<dob.dd<<"/"<<dob.mm<<"/"<<dob.yy; cout<<"\nANNUAL INCOME:"<<"\t\t\t"; cout<<income; cout<<"\nCONTACT NUMBER:"<<"\t\t\t"; cout<<cno;
}
void LIC::getpolicy_code()
{
dom.dd=dos.dd; dom.mm=dos.mm; if(years==1) dom.yy=dos.yy+1; else if(years==2) //calculation of date of maturity dom.yy=dos.yy+2;
if(years==1) { if(p_code==1) { sum_ass=5550.0; premium=500.0; } else if(p_code==2) { sum_ass=10000.0; premium=1000.0; } else if(p_code==3) { sum_ass=15000.0; premium=1500.0; } else if(p_code==4) { sum_ass=20000.0; premium=2000.0; } else cout<<"\nWRONG POLICY CODE!!!\n"; } else if(years==2) { if(p_code==1) { sum_ass=10000.0; premium=500.0; } else if(p_code==2) { sum_ass=20000.0; premium=1000.0; } else if(p_code==3) { sum_ass=30000.0; premium=1500.0; } else if(p_code==4) { sum_ass=40000.0; premium=2000.0; } else cout<<"\nWRONG POLICY CODE!!!\n"; }
}
void LIC::licshowinfo()
{
cout<<"\nPOLICY NUMBER:"<<"\t\t\t"; cout<<p_no; cout<<"\nPOLICY NAME:"; switch(p_code) { case 1:cout<<"\t\t\tJEEVAN SARAL"; break; case 2:cout<<"\t\t\tJEEVAN ANAND"; break; case 3:cout<<"\n\t\t\tJEEVAN CHAYA"; break; case 4:cout<<"\n\t\t\tJEEVAN VRIDHI"; break; default:break; } cout<<"\nPREMIUM:"<<"\t\t\t" ; cout<<premium; cout<<"\nAGENT ID:"<<"\t\t\t"; cout<<agentid; cout<<"\nDATE OF START:"<<"\t\t\t"; cout<<dos.dd<<"/"<<dos.mm<<"/"<<dos.yy<<"\n"; cout<<"\nDATE OF MATURITY:"<<"\t\t\t" ; cout<<dom.dd<<"/"<<dom.mm<<"/"<<dom.yy<<"\n"; cout<<"\nSUM ASSURED:"<<"\n"; cout<<sum_ass;
}
int LIC::getp_no() //accesor function as p_no. is a private member of class
{
return p_no;
}
void SEARCH()
{
int p_no; char found='n'; ifstream f1("LIC.dat",ios::in); cout<<"\n\t\tENTER THE POLICY NUMBER WHOSE RECORDS ARE TO BE SEARCHED:\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"; cin>>p_no; while(f1.read((char*)&l1,sizeof(l1))) { if(l1.getp_no()==p_no) {
l1.licshowinfo() ; found='y'; break; } } if(found=='n') cout<<"\nLIC POLICY NUMBER NOT PRESENT\n"; f1.close();
}
void INSERT()
{
ifstream f1("LIC.dat",ios::in); ofstream f2("new.dat",ios::out); char last='y'; cout<<"\n\t\tENTER THE DETAILS OF CLIENT TO BE INSERTED\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"; l1.getinfo(); l1.getpolicy_code(); while(f1.read((char*)&l2,sizeof(l2))) { if(l1.getp_no()<=l2.getp_no()) { f2.write((char*)&l1,sizeof(l1)); last='n'; break; } else f2.write((char*)&l2,sizeof(l2)); } if(last=='y') f2.write((char*)&l1,sizeof(l1)); else { int pos=f1.tellg(); pos-=sizeof(l2) ; f1.seekg(pos) ; while(f1.read((char*)&l2,sizeof(l2))) f2.write((char*)&l2,sizeof(l2)) ;
} f1.close(); f2.close(); remove("LIC.dat"); rename("new.dat","LIC.dat"); f1.open("LIC.dat",ios::in); cout<<"\nTHE FILE NOW CONTAINS:\n"; cout<<endl; cout<<"**********************************************************************"; cout<<endl; while(f1.read((char*)&l2,sizeof(l2))) { if(f1.eof()) break; l2.basicshowinfo(); l2.licshowinfo(); } f1.close();
}
void DELETE()
{
ifstream f1("LIC.dat",ios::in); ofstream f2("new.dat",ios::out); int lic_id; char found='f',confirm='n'; cout<<"\n\t\tENTER THE POLICY NUMBER WHOSE RECORD IS TO BE DELETED:\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"; cin>>lic_id; while(f1.read((char*)&l1,sizeof(l1))) { if(l1.getp_no()==lic_id) { l1.licshowinfo(); found='t'; cout<<"\nARE YOU SURE YOU WANT TO DELETE THE RECORD:(y/n)"<<" "; cin>>confirm; if(confirm=='n') f2.write((char*)&l1,sizeof(l1)); } else f2.write((char*)&l1,sizeof(l1)); } if(found=='f') cout<<"\n\nNO RECORD FOUND!!!\n\n"; f1.close(); f2.close(); remove("LIC.dat"); rename("new.dat","LIC.dat"); f1.open("LIC.dat",ios::in); cout<<"\nTHE FILE NOW CONTAINS:\n"; cout<<endl; cout<<"**********************************************************************"; cout<<endl; while(f1.read((char*)&l2,sizeof(l2))) { if(f1.eof()) break; l2.licshowinfo(); } f1.close();
}
void LIC::mod() // member function for function modify()
{
cout<<"\nADDRESS:"<<" "<<address; cout<<"\nCONTACT NUMBER:"<<" "; cout<<cno; cout<<"\nSUM ASSURED:"<<" "; cout<<sum_ass; cout<<"\nPREMIUM:"<<" "; cout<<premium; cout<<"\nPOLICY NUMBER:"<<p_no; cout<<"\nPOLICY CODE:"<<p_code; char newaddress[80]; int newp_code; long newcno; cout<<"\nENTER THE NEW DETAILS OF CLIENT:"<<" "; cout<<endl; cout<<"######################################################################"; cout<<endl; cout<<"\nENTER THE NEW CONTACT NUMBER OF CLIENT:(Enter '-1' to retain the old one)"<<" "; cin>>newcno; if(newcno!=-1) { cno=newcno;} cout<<"\nENTER THE NEW ADDRESS OF CLIENT:(Enter '.' to retain the old one)"<<" "; gets(newaddress); if(strcmpi(newaddress,".")!=0) { strcpy(address,newaddress); } cout<<"\nENTER THE POLICY CODE OF THE CLIENT:(Enter '-1' to retain the old one)"<<" "; cin>>newp_code; if(newp_code!=-1) {p_code=newp_code; } if(years==1) { if(newp_code==1) { sum_ass=5550.0; premium=500.0; } else if(newp_code==2) { sum_ass=10000.0; premium=1000.0; } else if(newp_code==3) { sum_ass=15000.0; premium=1500.0; } else if(newp_code==4) { sum_ass=20000.0; premium=2000.0; } else cout<<"\nWRONG POLICY CODE!!!"; } else if(years==2) { if(newp_code==1) { sum_ass=10000.0; premium=500.0; } else if(newp_code==2) { sum_ass=20000.0; premium=1000.0; } else if(newp_code==3) { sum_ass=30000.0; premium=1500.0; } else if(newp_code==4) { sum_ass=40000.0; premium=2000.0; } else cout<<"\nWRONG POLICY CODE!!!"; }
}
void MODIFY()
{
fstream f1("LIC.dat",ios::in|ios::out); int lic_id; long pos; char found='f'; cout<<"\n\t\tENTER THE POLICY NUMBER WHOSE RECORD IS TO BE MODIFIED\n"; cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n"; cin>>lic_id; while(f1.read((char*)&l1,sizeof(l1))) { pos=f1.tellg(); if(l1.getp_no()==lic_id) { l1.mod(); pos-=sizeof(l1); f1.seekg(pos); f1.write((char*)&l1,sizeof(l1)); found='t'; break; } } if(found=='f') cout<<"\n\nRECORD NOT FOUND!!!\n"; f1.seekg(0); f1.close(); f1.open("LIC.dat",ios::in); cout<<"\nTHE FILE NOW CONTAINS:\n"; cout<<endl; cout<<"**********************************************************************"; cout<<endl; while(f1.read((char*)&l1,sizeof(l1))) { l1.basicshowinfo(); l1.licshowinfo(); } f1.close();
}
//for counting clients in particular policy void counter()
{
ifstream f1("LIC.dat",ios::in); int js=0, ja=0, jc=0, jv=0,c=0; while(f1.read((char*)&l1,sizeof(l1))) { if(l1.rp_code()==1) js++; else if(l1.rp_code()==2) ja++; else if(l1.rp_code()==3) jc++; else jv++; c=js+ja+jc+jv; } f1.close(); cout<<"\nTOTAL POLICY HOLDER OF JEEVAN SARAL:"<<" "<<js<<endl; cout<<"\nTOTAL POLICY HOLDER OF JEEVAN ANAND:" <<" "<<ja<<endl; cout<<"\nTOTAL POLICY HOLDER OF JEEVAN CHAYA:"<<" "<<jc<<endl; cout<<"\nTOTAL POLICY HOLDER OF JEEVAN VRIDHI:"<<" "<<jv<<endl; cout<<"\nTOTAL NUMBER OF CLIENTS:"<<" "<<c<<endl;
}
void main()
{
char ch; char ch1; int a=1; clrscr(); cout<<"\n**********************************************************************\n"; cout<<"\n\t\tWELCOME TO LIC DATABASE MANAGEMENT\n"; cout<<"\n*********************************************************************\n"; cout<<"\n\t\tPROJECT MADE BY:\n"; cout<<"\n*********************************************************************\n"; cout<<"\n\t\tCHAITALI MITRA\n"; char password[15]; cout<< "\n\nENTER THE PASSWORD TO PROCEED:" <<" "; gets(password) ; a=strcmpi(password,"comp"); while(a) { exit(0);
}
char date[10]; _strdate(date); cout<<endl; cout<<"TODAY'S DATE IS(mm/dd/yy):"<<" "<<date; cout<<endl;
do {
cout<<"\nMAIN MENU\n"; cout<<"\n\t\t\t"; cout<<"\n1.INSERT \n"; cout<<"\t\t\t\t"; cout<<"\n2.SEARCH \n"; cout<<"\t\t\t\t"; cout<<"\n3.DELETE \n"; cout<<"\t\t\t"; cout<<"\n4.MODIFY \n"; cout<<"\t\t\t\t"; cout<<"\n5.EXIT \n"; cout<<"\t\t\t\t"; cout<<"\nENTER YOUR CHOICE:"<<" "; cin>>ch; switch(ch) { case '1': INSERT(); break; case '2': SEARCH(); break; case '3': DELETE(); break; case '4': MODIFY(); break; case '5': exit(0); default: cout<<"INVALID CHOICE!!!"; }
counter(); cout<<"\n\t\t\tDO WANT TO CONTINUE?????????? (y/n): "; cin>>ch1; } while((ch1=='y')||(ch1=='Y')); cout<<"\n**********************************************************************"; cout<<"\n\t\tTHANK YOU FOR USING LIC DATABASE SYSTEM!!!!!!!!!!!"; cout<<endl; cout<<"**********************************************************************"; cout<<endl; getch();
}