hey xpert i'm class 12 cbse student...unfortunately i'm not able to get the output from my project. the project is based on bank employee detail.........i'm gettin the output ,but the thin is xcept aading records of the employee i'm not able to do other operation like modifiaction,deletion,listing...!!!!!!! your will be appreciated>.>!!!! ;)

//A PROGRAM TO MANAGE BANK ADMINISTRATION
#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<iomanip.h>
#include<string.h>
#include<graphics.h>
#include<dos.h>
void graphic_screen();
class group
{
private:
struct person
{
char flag;
char empcode[5];
char name[40];
int age;
int sal;
}p;
fstream file;
public:
group();
void addrec();
void listrec();
void modirec();
void delrec();
void recallrec();
void packrec();
void exit();
};
void main()
{
graphic_screen();
int choice;
group g;
clrscr();
cout<<"          ========UAE COMMERCIAL BANK========";
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
getch();
do
{
clrscr();
cout<<"\n                    UAE COMMERCIAL BANK";
cout<<"\n\n\n\n             1.ADD RECORDS OF EMPLOYEES";
cout<<"\n                   2.LIST RECORDS OF EMPLOYEES";
cout<<"\n                   3.MODIFY RECORDS OF EMPLOYEES";
cout<<"\n                   4.DELETE RECORDS OF EMPLOYEES";
cout<<"\n                   5.RECALL RECORDS OF EMPLOYEES";
cout<<"\n                   6.PACK RECORDS OF EMPLOYEES";
cout<<"\n                   7.EXIT";
cout<<"\n\n\n\n\nEnter your choice:";
cin>>choice;
clrscr();
switch (choice)
{
case 1:g.addrec();
break;
case 2:g.listrec();
break;
case 3:g.modirec();
break;
case 4:g.delrec();
break;
case 5:g.recallrec();
break;
case 6:g.packrec();
break;
case 7:g.exit();
exit(1);
}
}
while(choice!=7) ;
}
group::group()
{
file.open("EMP.DAT",ios::binary||ios::in|ios::out);
if(!file)
{
cout<<"\nUnable to open file";
exit();}
}
void group::addrec()
{
char ch;
file.seekp(0,ios::end);//set pointer to end of file
do
{
clrscr();
cout<<"\nEnter employee code:";
cin>>p.empcode;
cout<<"\nEnter employee's name:";
cin>>p.name;
cout<<"\nEnter employee's age:";
cin>>p.age;
cout<<"\nEnter employee's slary:";
cin>>p.sal;
p.flag= ' ';
file.write((char*)&p,sizeof (p));
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\nAdd another record?(Y/N)";
cin>>ch;
}
while (ch=='y'||ch=='Y');
}
void group::listrec()
{
int j=1;//record number
file.seekg(0,ios::beg);//set get pointer to the begining of the file
while(file.read((char*)&p,sizeof(p)))
{
if(p.flag!='*')
cout<<"\nRecord No."<<j++//Increment counter
<<setw(6)<<p.empcode
<<setw(20)<<p.name
<<setw(4)<<p.age
<<setw(9)<<p.sal;
}
file.clear();
cout<<"\nPress '->'key....";
getch();
}
void group::modirec()
{
char code[5];
int count=0;
long int pos;
cout<<"Enter employee code:";
cin>>code;
file.seekg(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(strcmp(p.empcode,code)==0)
{
cout<<"\nEnter new employee's code:"    ;
cin>>p.empcode;
cout<<"\nEnter new employee's name:"    ;
cin>>p.name;
cout<<"\nEnter new employee's age:"    ;
cin>>p.age;
cout<<"\nEnter new employee's salary:"    ;
cin>>p.sal;
p.flag='  ';
pos=count*sizeof(p);//set put pointer such that existing file is overwritten
file.seekp(pos,ios::beg);
file.write ((char*)&p,sizeof(p));
cout<<"\nModified....";
return;
}
count++;
}
cout<<"\nNo employee in file with code="<<code;
cout<<"\nPress'->'key ....";
getch();
file.clear();
}
void group::delrec()
{
char  code[5];
long int pos;
int count=0;
cout<<"Enter the employee code:";
cin>>code;
file.seekg(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(strcmp(p.empcode,code)==0)
{
p.flag='*';
pos=count*sizeof(p);
file.seekp(pos,ios::beg);
file.write((char*)&p,sizeof(p));
cout<<"\nDeleted....";
return;
}
count++;
}
cout<<"\nNo employee in file with code="<<code;
cout<<"\nPress'->' key....";
getch();
file.clear();
}
void group::recallrec()
{
char  code[5];
long int pos;
int count=0;
cout<<"Enter the employee code:";
cin>>code;
file.seekg(0,ios::beg);
while(file.read((char*)&p,sizeof(p)))
{
if(strcmp(p.empcode,code)==0)
{
p.flag=' ';
pos=count*sizeof(p);
file.seekp(pos,ios::beg);
file.write((char*)&p,sizeof(p));
return;
}
count++;
}
cout<<"\nNo employee in file with code="<<code;
cout<<"\nPress '->' key....";
getch();
file.clear();
}
void group::packrec()
{
ofstream outfile;
outfile.open("TEMP",ios::out);
file.seekg(0,ios::beg);
while (file.read((char*)&p,sizeof  (p)))
 {
if(p.flag!='*')
outfile.write((char*)&p,sizeof  (p));
}
outfile.close();
file.close();
remove("EMP.DAT");
rename("TEMP","EMP.DAT");
file.open("EMP.DAT",ios::binary|ios::in|ios::out|ios::nocreate);
}

void group::exit()
 {
clrscr();
clrscr();
cout<<setw(12)<<"     PROJECT DEVELOPED BY";
cout<<"\n -------------------------------\n";
cout<<"\n\n  MOHAMED QAMAR,SHAHSAD ASHRAF\n\n";
cout<<"                AND\n\n";
cout<<setw(16) <<"     SAAD ABDURRAHMAN\n\n";
cout<<"\n\n\n\n\n\n\nThank you...\n\n\n\n\n\n\n";
getch();
file.close();
}
   void graphic_screen()
   {
   int driver,mode;
   driver=DETECT;
   initgraph(&driver,&mode,"c:\\tc\\bgi");
   setbkcolor (18);
   setcolor(1);
   settextstyle(7,0,7);
   outtextxy(150,150,"WELCOME");
   outtextxy(250,250,"TO");
   delay(5000);
   closegraph();
   initgraph(&driver,&mode,"c:\\tc\\bgi") ;
   setbkcolor(18);
   setcolor(5);
   settextstyle(7,0,6);
   outtextxy(10,150,"BANK MANGEMENT");
   outtextxy(19,300,"SYSTEM");
   delay(5000);
   closegraph();
   initgraph(&driver,&mode,"c:\\bc5\\bgi") ;
   setbkcolor(18);
   setcolor(5);
   settextstyle(7,0,8);
   outtextxy(100,100,"CREATED");
   settextstyle(7,0,6);
   outtextxy(250,250,"BY");
   delay(5000);
   closegraph();
   initgraph(&driver,&mode,"c:\\tc\\bgi") ;
   setbkcolor(18);
   setcolor(5);
   settextstyle(7,0,5);
   outtextxy(80,80,"MOHAMED QAMAR");
   outtextxy(180,140,"SHAHSAD ASHRAF");
   outtextxy(230,230,"AND");
   outtextxy(160,290,"SAAD ABDURRAHMAN");
   delay(5000);
   closegraph();
   }
Comments
BOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!

line 22: when is that file stream ever opened? Its a bad idea to make fstream an object of a class. Just declare it in the functions that need it, open it, use it, then close it when the function ends.

lin33: void main -- main NEVER EVER returns void. There are only two acceptable ways to declare main

int main()
{
{

int main(int argc, char* argv[])
{
}

Any other way is non-standard and could cause confusion with other programs.

Edited 6 Years Ago by Ancient Dragon: n/a

This article has been dead for over six months. Start a new discussion instead.