?? 456.cpp
字號:
// 456.cpp : Defines the entry point for the application.
//
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <fstream.h>
const int maxr=100;
class Employee //職工類
{
int tag;//刪除標(biāo)記
int no;//職工編號
char name[20];
char zw[20];//職工姓名
int salary;//職工工資
public:
Employee(){}
char *getname() {return name;}//獲取名字
int gettag() {return tag;}//獲取標(biāo)記
int getno() {return no;}//獲取編號
int getsalary(){return salary;}
void setzw(char q[])//設(shè)置名字
{
strcpy(zw,q);
}
void setname(char na[])//設(shè)置名字
{
strcpy(name,na);
}
void getsalary(int sa){salary=sa;}
void delna(){tag=1;}//刪除
void addemp(int n,int sa,char *na,char *q)//增加
{
tag=0;
no=n;
salary=sa;
strcpy(name,na);
strcpy(zw,q);
}
void disp()//顯示職工信息
{
cout<<"│"<<setw(10)<<no<<"│"<<setw(10)<<name<<"│"<<setw(10)<<salary<<"│"<<setw(10)<<zw<<"│"<<endl;
cout<<"├—————┼—————┼—————┼—————┤"<<endl;
}
};
class Database//職工數(shù)據(jù)類
{
int top;
Employee read[Maxr];
public:
Database()//將職工信息從employee.txt讀取到read[]中
{ Employee s;
top=-1;
fstream file("employee.txt",ios::in);
while (1)
{
file.read((char *)&s,sizeof(s));
if (!file) break;
top++;
read[top]=s;
}
file.close();
}
void clear()//刪除所有
{
top=-1;
}
int addemp (int n, int sa,char *na,char*q) //增加職工
{
Employee *p=query(n);
if (p==NULL)
{
top++;
read[top].addemp(n,sa,na,q);
return 1;
}
return 0;
}
Employee *query(int empid)
{
for (int i=0;i<=top;i++)
if (read[i].getno()==empid && read[i].gettag()==0)
return &read[i];
return NULL;
}
Employee *query1(char empna[20])
{
for (int i=0;i<=top;i++)
if ((read[i].getname()==empna) && read[i].gettag()==0)
return &read[i];
return NULL;
}
void disp() //職工信息顯示
{
for (int i=0;i<=top;i++)
read[i].disp();
}
void empdata();
~Database() //將read[]中的信息讀如到employee.txt中
{
fstream file("employee.txt",ios::out);
for (int i=0;i<=top;i++)
if (read[i].gettag()==0)
file.write((char *)&read[i],sizeof(read[i]));
file.close();
}
};
void Database::empdata()//職工維護(hù)
{
int choice=1;
int m=1;int b=1;
char rname[20];
int empid; int empsa;char q[20];
Employee *r;
while (choice!=0)
{
cout<<"職工維護(hù) 1:新增 2:更改 3:刪除 4:查找 5:顯示 6:全刪 0:退出=>";
cin>>choice;
switch (choice)
{
case 1:
cout<<setw(50)<<" ┌—————————————┐\n";
cout<<setw(50)<<" │ 請選擇您所需的操作 │\n";
cout<<setw(50)<<" │ 經(jīng)理: 1,并按回車鍵 │\n";
cout<<setw(50)<<" │ 業(yè)務(wù)經(jīng)理:2,并按回車鍵 │\n";
cout<<setw(50)<<" │ 普通職工:3,并按回車鍵 │\n";
cout<<setw(50)<<" └—————————————┘\n";
cin>>m;
while(m!=0){
switch(m)
{
case 1:
cout<<"輸入經(jīng)理編號:";
cin>>empid;
cout<<"輸入獎金: ";
cin>>empsa;
cout<<"輸入經(jīng)理姓名:";
cin>>rname;
addemp(empid,8000+empsa,rname,"經(jīng)理");
break;
case 2:
cout<<"輸入業(yè)務(wù)經(jīng)理編號:";
cin>>empid;
cout<<"輸入月提成: ";
cin>>empsa;
cout<<"輸入業(yè)務(wù)經(jīng)理姓名:";
cin>>rname;
addemp(empid,4000+empsa,rname,"業(yè)務(wù)經(jīng)理");
break;
case 3:
cout<<"輸入職工編號:";
cin>>empid;
cout<<"輸入工資: ";
cin>>empsa;
cout<<"輸入職工姓名:";
cin>>rname;
addemp(empid,empsa,rname,"普通職工");
break;
}
break;
}
break;
case 2:
cout<<"輸入職工編號:";
cin>>empid;
r=query(empid);
if (r==NULL)
{
cout<<"該職工不存在"<<endl;
break;
}
cout<<"輸入新的工資:"<<endl;
cin>>empsa;
r->getsalary(empsa);
cout<<"請輸入新的職務(wù)"<<endl;
cin>>q;
r->setzw(q);
addemp(empid,empsa,rname,q);
break;
case 3:
cout<<"輸入職工編號:";
cin>>empid;
r=query(empid);
if (r==NULL)
{
cout<<"該讀者不存在"<<endl;
break;
}
r->delna();
break;
case 4:
cout<<setw(50)<<" ┌—————————————┐\n";
cout<<setw(50)<<" │ 請選擇您所需的操作 │\n";
cout<<setw(50)<<" │ 按編號查找1,并按回車鍵 │\n";
cout<<setw(50)<<" │ 返回 2,并按回車鍵 │\n";
cout<<setw(50)<<" └—————————————┘\n";
cin>>b;
while(b!=0){
switch(b)
{
case 1:
cout<<"輸入職工編號:";
cin>>empid;
r=query(empid);
if (r==NULL)
{
cout<<"該職工不存在"<<endl;
break;
}
cout<<"├—————┼—————┼—————┼—————┤"<<endl;
cout<<"│"<<setw(10)<<"編號"<<"│"<<setw(10)<<"姓名"<<"│"<<setw(10)<<"工資"<<"│"<<setw(10)<<"職務(wù)"<<"│"<<endl;
cout<<"├—————┼—————┼—————┼—————┤"<<endl;
r->disp();
break;
case 2:
break;
}
break;
}
break;
case 5:
cout<<"├—————┼—————┼—————┼—————┤"<<endl;
cout<<"│"<<setw(10)<<"編號"<<"│"<<setw(10)<<"姓名"<<"│"<<setw(10)<<"工資"<<"│"<<setw(10)<<"職務(wù)"<<"│"<<endl;
cout<<"├—————┼—————┼—————┼—————┤"<<endl;
disp();
break;
case 6:
clear();
break;
}
}
}
void main()
{
int choice=1;Database EmpDB;
while(choice!=0)
{
cout<<"********************************************************************************"<<endl;
cout<<endl;
cout<<endl;
cout<<setw(20)<<"******************************歡迎使用職工管理系統(tǒng)******************************"<<endl;
cout<<endl;
cout<<endl;
cout<<setw(50)<<" ┌—————————————┐\n";
cout<<setw(50)<<" │ 請選擇您所需的操作 │\n";
cout<<setw(50)<<" │ │\n";
cout<<setw(50)<<" │ 操作 1,并按回車鍵 │\n";
cout<<setw(50)<<" │ │\n";
cout<<setw(50)<<" │ 返回 0,并按回車鍵 │\n";
cout<<setw(50)<<" └—————————————┘\n";
cin>>choice;
switch(choice)
{
case 1:
while(1){
cout<<setw(20);
EmpDB.empdata();
break;
break;}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -