kulang ung una eto pla ung buo nid ko lagyan ng switch para sa add,edit,view,search help naman po kung pano langyan to ng switch
// add new employee
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iomanip.h>
#include<string.h>
struct e
{
char empno[50];
char name[20];
char dept[15];
char position[20];
float rate;
};
struct e emp;
int k;
fstream employ;
char ans='y';
char empno[50],name[20],dept[15],position[20];
float rate;
void head();
void line(int y);
void search();
void add ();
void edit();
void view();
void add()
{
employ.open("employ.txt",ios::app);
if (employ.fail())
{
cout<<"Error wrutting to output file ";
cin.get();
cin.get();
exit(1);
}
while(ans)
{
clrscr();
for(k=1;k<=80;k++)
{
gotoxy(k,2);cout<<"-";
}
gotoxy(20,3);cout<<" ADD NEW EMPLOYEE RECORDS ";
for(k=1;k<=80;k++)
{
gotoxy(k,4);cout<<"-";
}
gotoxy(12,7);cout<<"Employee No. ";
gets(emp.empno);
gotoxy(12,9);cout<<"Employee Name ";
gets(emp.name);
gotoxy(12,11);cout<<"Department ";
gets(emp.dept);
gotoxy(12,13);cout<<"Position ";
gets(emp.position);
gotoxy(12,15);cout<<"Rate ";
cin>>emp.rate;
employ<<emp.empno<<" "<<emp.name<<" "<<emp.dept<<" "<<emp.position<<" "<<emp.rate<<endl;
gotoxy(12,18);cout<<" Do you want to continue [Y/N]? ";
cin>>ans;
if ((ans=='Y') || (ans=='y'))
{
continue;
}
else
{
break;
}
}
}
void head()
{
clrscr();
x=1;
for(k=1;k<=75;k++)
{
gotoxy(x,1);cout<<"_";
x++;
}
gotoxy(34,2);cout<<"EDIT RECORDS";
x=1;
for(k=1;k<=75;k++)
{
gotoxy(x,3);cout<<"_";
x++;
}
}
void line(int y)
{
x=1;
for(k-1;k<=75;k++)
{
gotoxy(x,y);out<<"_";
x++;
}
}
void clearline()
{
gotoxy(22,9);clreol();
gotoxy(22,10);clreol();
gotoxy(22,11);clreol();
gotoxy(22,12);clreol();
gotoxy(10,15);clreol();
gotoxy(10,16);clreol();
gotoxy(10,17);clreol();
gotoxy(10,18);clreol();
gotoxy(10,19);clreol();
gotoxy(10,20);clreol();
}
void edit()
{
employ.open("employ.txt",ios::in);
out.open("temp.txt",ios:
ut);
gotoxy(10,5);cout<<"Enter employee number";
gets(empno);
while(!employ.eof())
{
employ>>emp.empno>>emp.name>>emp.dept>>emp.position>>emp.rate;
if(strcmp(emp.empno,empno)==0)
{
flag=1;
line(7);
gotoxy(22,9);cout<<"name"<<emp.name;
gotoxy(22,10);cout<<"Department"<<emp.dept;
gotoxy(22,11);cout<<"position"<<emp.position;
gotoxy(22,12);cout<<"rate"<<emp.rate;
line(14);
gotoxy(10,15);cout<<"Editthis record (y/n);";
sgt=getche();
if((sgt=='y') || (sgt=='Y'))
{
gotoxy(10,16);cout<<"Enter new name ";
gets(emp.name);
gotoxy(10,17);cout<<"Enter new department ";
gets(emp.dept);
gotoxy(10,18);cout<<"Enter new position ";
gets(emp.position);
gotoxy(10,19);cout<<"Enter new rate";
gets(emp.rate);
out<<emp.empno<<" "<<emp.name<<" "<<emp.dept<<" "<<emp.position<<""<<emp.rate<<endl;
clearline();
gotoxy(22,10);cout<<"Your new record is ";
gotoxy(22,10);cout<<"name"<<emp.name;
gotoxy(22,11);cout<<"Department"<<emp.dept;
gotoxy(22,12);cout<<"position"<<emp.position;
gotoxy(22,13);cout<<"rate"<<emp.rate;
}
else
{
out<<emp.empno<<" "<<emp.name<<" "<<emp.dept<<" "<<emp.position<<""<<emp.rate<<endl;
}
}
else
{
out<<emp.empno<<" "<<emp.name<<" "<<emp.dept<<" "<<emp.position<<""<<emp.rate<<endl;
}
}
if (flag==0)
{
gotoxy(10,20);cout<<"Record does not exist";
}
emp;oy.close();
out.close();
remove("employ.txt");
rename("temp.txt","employ.txt");
}
void head()
{
clrscr();
for(k=1;k<=80;k++)
{
gotoxy(k,2);cout<<"_";
}
gotoxy(32,3);cout<<"LIST OF EMPLOYEE";
for (k=1;k<=80;k++)
{
gotoxy(k,4);cout<<"_";
}
gotoxy(5,5);cout<<"Employee No. ";
gotoxy(20,5);cout<<"Name ";
gotoxy(36,5);cout<<"Department ";
gotoxy(53,5);cout<<"Position ";
gotoxy(70,5);cout<<"Rate ";
}
void view()
{
employ.open("employ.txt",ios::in);
if(employ.fail())
{
gotoxy(25,8);cout<<"Error reading input file";
cin.get();
cin.get();
exit(1);
}
k=6;
while(!employ.eof())
{
employ>>emp.empno;
strcpy(empno,emp.empno);
employ>>emp.name;
strcpy(name,emp.name);
employ>>emp.dept;
strcpy(dept,emp.dept);
employ>>emp.position;
strcpy(position,emp.position);
employ>>emp.rate;
strcpy(rate,emp.rate);
gotoxy(5,k);cout<<empno;
gotoxy(20,k);cout<<name;
gotoxy(36,k);cout<<dept;
gotoxy(53,k);cout<<position;
gotoxy(70,k);cout<<rate;
k++;
}
}
void head()
{
clrscr();
x=1;
for(k=1;k<=80;k++)
{
textbackground(BLUE);
textcolor(BLACK);
gotoxy(x,1);cprintf("_");
x++;
}
textbackground(BLUE);
textcolor(RED);
gotoxy(34,2);cprintf("SEARCH RECORDS ");
x=1;
for(k=1;k<=80;k++)
{
textbackground(BLUE);
textcolor(BLACK);
gotoxy(x,3);cprintf("_");
x++;
}
}
void line(int y)
{
x=1;
for(k=1;k<=80;k++)
{
textbackground(YELLOW);
textcolor(BLUE);
gotoxy(x,y);cprintf("-");
x++;
}
}
void search()
{
employ.open("employ.txt",ios::in);
textbackground(GREEN);
textcolor(BLUE);
gotoxy(10,5);cprintf("Enter employee number ");
gets(empno);
if(employ.fail())
{
cout<<"Error reading input file";
cin.get();
cin.get();
exit(1);
}
while (!employ.eof())
{
employ>>emp.empno;
if(strcmp(emp.empno,empno)==0)
{
flag=1;
line(7);
employ>>emp.name;
employ>>emp.dept;
employ>>emp.position;
employ>>emp.rate;
gotoxy(22,9);cout<<"Name "<<emp.name;
gotoxy(22,10);cout<<"Department "<<emp.dept;
gotoxy(22,11);cout<<"Position "<<emp.position;
gotoxy(22,12);cout<<"Rate "<<emp.rate;
line(14);
break;
}
else
{
flag=0;
}
}
if(flag==0)
{
gotoxy(12,16);cout<<"Record does not exist";
}
emp;oy.close();
out.close();
remove("employ.txt");
rename("temp.txt","employ.txt");
}
}