Bank1.cpp
#include<stdio.h>
struct c
{
int accno;
char
name[20];
float
balance;
};
void main()
{
struct c
cust;
FILE *fp;
fp=fopen("bankstore.dat","ab+");
printf("\n
enter 0 for acc no to terminate");
for(;;)
{
printf("enter
acc number");
scanf("%d",&cust.accno);
if(cust.accno==0)break;
fflush(stdin);
printf("
enter the custmour name");
gets(cust.name);
printf("enter
the balance");
scanf("%f",&cust.balance);
fwrite(&cust,sizeof(cust),1,fp);
}
printf("bank
file is created");
fclose(fp);
}
Bank2.cpp
#include<stdio.h>
#include<conio.h>
#define
space(k) for(j=1;j<=k;j++)\
fprintf(stdprn,"
");
#define LINE
for(j=1;j<80;j++)\
fprintf(stdprn,"-");
struct c
{
int accno;
char
name[20];
float
balance;
};
void main()
{
char
fname[20];
struct c
cust;
int j,k,i=1;
FILE *fp;
clrscr();
printf("enter
the file name to open");
gets(fname);
fp=fopen(fname,"rb");
if(fp==NULL)
{
printf("file
not found");
return;
}
clrscr();
space(30);
fprintf(stdprn,"S.B.I
custmours report\n ");
LINE;
fprintf(stdprn,"\n%10s","SNO");
fprintf(stdprn,"%10s","ACCNO");
fprintf(stdprn,"%25s","NAME");
fprintf(stdprn,"%12s\n","BALANCE");
LINE;
fread(&cust,sizeof(cust),1,fp);
while(!feof(fp))
{
fprintf(stdprn,"\n%10d",i);
fprintf(stdprn,"%10d",cust.accno);
fprintf(stdprn,"%25s",cust.name);
fprintf(stdprn,"%10.2f",cust.balance);
i++;
fread(&cust,sizeof(cust),1,fp);
}
fprintf(stdprn,"\n");
LINE;
fclose(fp);
getch();
}
Bank3.cpp
#include<stdio.h>
#include<conio.h>
#define
space(k) for(j=1;j<=k;j++)\
fprintf(stdout,"
");
#define LINE
for(j=1;j<80;j++)\
fprintf(stdout,"-");
struct c
{
int accno;
char
name[20];
float
balance;
};
void main()
{
char
fname[20];
struct c
cust;
int j,k,i=1;
FILE *fp;
clrscr();
printf("enter
the file name to open");
gets(fname);
fp=fopen(fname,"rb");
if(fp==NULL)
{
printf("file
not found");
return;
}
clrscr();
space(30);
fprintf(stdout,"S.B.I
custmours report\n ");
LINE;
fprintf(stdout,"\n%10s","SNO");
fprintf(stdout,"%10s","ACCNO");
fprintf(stdout,"%25s","NAME");
fprintf(stdout,"%12s\n","BALANCE");
LINE;
fread(&cust,sizeof(cust),1,fp);
while(!feof(fp))
{
fprintf(stdout,"\n%10d",i);
fprintf(stdout,"%10d",cust.accno);
fprintf(stdout,"%25s",cust.name);
fprintf(stdout,"%10.2f",cust.balance);
i++;
fread(&cust,sizeof(cust),1,fp);
}
fprintf(stdout,"\n");
LINE;
fclose(fp);
getch();
}
Database.cpp
#include<fstream.h>
#include<iomanip.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<myclass.cpp>
#include<fun.cpp>
void main()
{
int choice;
for(;;)
{
menu();
gotoxy(27,11);
cout<<"enter
your choice";
gotoxy(47,11);
cin>>choice;
switch(choice)
{
case
1:add();break;
case
2:del();break;
case
3:modify();break;
case
4:disp();break;
case
5:exit(0);break;
deafult:gotoxy(27,11);
cout<<"wrong
choice enter again";
}
}
}
Fun.cpp
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<fstream.h>
#include<iomanip.h>
void menu()
{
clrscr();
gotoxy(27,1);cout<<"project
devoloped by the rmau senior software engineer";
gotoxy(27,2);cout<<"employee
inforamtion maintaince";
gotoxy(27,3);cout<<"============================";
gotoxy(27,4);cout<<"1) ADDING EMPLOYEE DATA";
gotoxy(27,5);cout<<"2) DELETING EMPLOYEE DATA";
gotoxy(27,6);cout<<"3) MODIFY EMPLOYEE DATA";
gotoxy(27,7);cout<<"4) DISPLAY
EMPLOYEE DATA";
gotoxy(27,8);cout<<"5) EXIT";
gotoxy(27,9);cout<<"=============================";
}
void add()
{
char ch;
employee
emp;
ofstream
empfile;
empfile.open("emp.dat",ios::app);
emp.accept();
empfile.write((char*)&emp,sizeof(emp));
empfile.close();
getch();
}
void del()
{
int
no,flag=0;
gotoxy(27,12);cout<<"enter
the employee number to delete";
gotoxy(27,14);cin>>no;
employee
emp;
ifstream
empfile("emp.dat");
ofstream
tempfile("temp.dat");
empfile.read((char*)&emp,sizeof(emp));
while(empfile)
{
if(no==emp.empno)flag=1;
if(no!=emp.empno)
{
tempfile.write((char*)&emp,sizeof(emp));
}
empfile.read((char*)&emp,sizeof(emp));
}
empfile.close();
tempfile.close();
remove("emp.dat");
rename("temp.dat","emp.dat");
empfile.close();
tempfile.close();
if(flag==0)
{
gotoxy(27,14);
cout<<"record
not found in the database";
}
else
{
gotoxy(27,14);
cout<<"employee
record is deleted from the
database";
}
gotoxy(27,15);
cout<<"press
any key";
getch();
}
void disp()
{
clrscr();
int i=1;
int c=1;
employee
emp;
ifstream
empfile("emp.dat");
cout<<setw(5)<<"sno"<<setw(10)<<"empno"<<setw(25)<<"employee
name"<<setw(10)<<"salary"<<endl;
cout<<setw(5)<<"===="<<setw(10)<<"======"<<setw(25)<<"======"<<setw(10)<<"======"<<endl;
empfile.read((char*)&emp,sizeof(emp));
while(empfile)
{
cout<<setw(5)<<i;
emp.display();
empfile.read((char*)&emp,sizeof(emp));
i++;
c++;
if(c>20)
{
c=i%20;
cout<<"press
any key to the next page";
getch();
clrscr();
}
}
empfile.close();
cout<<"\npress
any key"<<endl;
getch();
}
void
modify()
{
int tno,no;
char
tname[20];
float tsal;
int flag=0;
gotoxy(27,12);cout<<"enter
employee number to modify";
gotoxy(27,13);cin>>no;
employee
emp;
fstream
empfile;
empfile.open("emp.dat",ios::in|ios::out);
empfile.read((char*)&emp,sizeof(emp));
while(empfile)
{
if(no==emp.empno)
{
gotoxy(27,14);cout<<"old
values";
gotoxy(52,14);cout<<"new values";
gotoxy(27,15);cout<<emp.empno;
gotoxy(52,15);cin>>tno;
cin.ignore(1);
gotoxy(27,16);cout<<emp.name;
gotoxy(52,16);cin.get(tname,20,'\n');
gotoxy(27,17);cout<<emp.sal;
gotoxy(52,17);cin>>tsal;
if(tno!=0)
emp.empno=tno;
if(tname[0]!='\0')
strcpy(emp.name,tname);
if(tsal!=0.0)
emp.sal=tsal;
int
n=empfile.tellg();
n=n-sizeof(emp);
empfile.seekp(n,ios::beg);
empfile.write((char*)&emp,sizeof(emp));
flag=1;
}
empfile.read((char*)&emp,sizeof(emp));
}
gotoxy(28,18);
if(flag==0)
cout<<"record
not found in the database";
else
cout<<"record
is modified with new data";
empfile.close();
gotoxy(27,19);
cout<<"press
any key";
getch();
}
Myclass.cpp
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class
employee
{
private:
int empno;
char
name[20];
float sal;
public:
void
display()
{
cout<<setw(10)<<empno<<setw(25)<<name<<setw(10)
<<setiosflags(ios::floatfield)<<setprecision(2)
<<setiosflags(ios::showpoint)<<sal<<endl;
}
void
accept()
{
gotoxy(27,12);
cout<<"enter
the employee number";
gotoxy(27,13);cin>>empno;
cin.ignore(1);
gotoxy(27,14);cout<<"enter
the employee name";
gotoxy(27,15);cin.get(name,20,'\n');
gotoxy(27,16);cout<<"enter
the salary";
cin>>sal;
gotoxy(27,18);cout<<"press
any key";
}
friend void
del();
friend void
modify();
};
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి