(C++)员工工资管理系统

#include

#include
#include
#include"guanli.h"
#include
#include  
using namespace std;
int main()
{
int  xuanze;
guanli yuangong;
guanli::LinkList L;
yuangong.creat(L);
yuangong.duqu(L);
while (1)
{
yuangong.zhujiemian();
cout << "              请输入===>:";
cin >> xuanze;
system("cls");
switch (xuanze)
{
case(1) : yuangong.ckxx(L); yuangong.back();system("cls"); break;//查看当前员工
case(5) : yuangong.xggz(L); yuangong.back(); system("cls"); break;//修改员工工资
case(2) : yuangong.lrxx(L); yuangong.back(); system("cls"); break;//录入新的员工
case(3) : yuangong.ckgz(L); yuangong.back(); system("cls"); break;//查看员工工资
case(4) : yuangong.czxx(L); yuangong.back(); system("cls"); break;//查找员工工资
case(7) : yuangong.gyzz(); yuangong.back(); system("cls"); break; //关于作者信息
case(6) : yuangong.scyg(L); yuangong.back(); system("cls"); break;//删除员工信息
case(8) : yuangong.xieru(L); exit(1);                                                    //退出系统
}

}


}

函数定义:

#include
#include  
#include
#include"guanli.h"
#include
using namespace std;
void guanli::zhujiemian()
{
cout << "                                                            " << endl;
cout << "                                                            " << endl;
cout << "                                                            " << endl;
cout << "                                                            " << endl;
cout << "                                                            " << endl;
cout << "                                                            " << endl;
cout << "                              ****************************************" << endl;


cout << "                              ****   欢迎使用此员工工资管理系统   ****" << endl;
cout << "                              ****          1.查看当前员工        ****" << endl;
cout << "                              ****          2.添加新的员工        ****" << endl;
cout << "                              ****          3.查看员工工资        ****" << endl;
cout << "                              ****          4.查找员工工资        ****" << endl;
cout << "                              ****          5.修改员工工资        ****" << endl;
cout << "                              ****          6.删除员工信息        ****" << endl;
cout << "                              ****          7.关于    作者        ****" << endl;
cout << "                              ****          8.退出    系统        ****" << endl;
cout << "                              ****************************************" << endl;




}
void guanli::ckxx(LinkList &v)  //查看当前员工
{
q = v->next;
cout<<"当前员工:"<name << endl;
q = q->next;
}
}
void guanli::xggz(LinkList &v)  //修改员工工资
{


q = v;
q = q->next;
//cout << "姓名            工资" << endl;
//while (q != NULL)
//{
//cout << q->name << endl;
//q = q->next;
//}
cout << "请输入想要修改工资的员工姓名:";
cin >> fname;
cout << endl;
//cout << "进入循环前q->name为 " << q->name << endl;
while (strcmp(q->name, fname) != 0 && NULL != q->next)
{
q = q->next;
}
//cout << "循环后q->name为 " << q->name << endl;
//cout << "        fanme为 " << fname << endl;


if (strcmp(q->name, fname) == 0)
{
cout << "是否确认修改员工工资" << endl;
cout << "      1.确认" << endl;
cout << "      2.否" << endl;
cin >> a;
if (1 == a)
{
system("cls");
cout << "请输入修改后的工资" << endl;
cin >> q->gongzi;
system("cls");
cout << "修改成功!"<> q;
for (i = 0; i < q; i++)
{
s= (LinkList)malloc(LEN);
cout << "请输入员工姓名:";
cin >> s->name;
s->gongzi=0;
s->next = p->next;        //将新结点插入到单链表中 
p->next = s;
}
}
void guanli::ckgz(LinkList &v)   //查看员工工资
{
int num = 0;
q = v->next;
char m[10];
int i=0, j, t;
while (NULL != q)
{


temp.gongzi = q->gongzi;
strcpy(temp.name, q->name);
zong[i] = temp;
q = q->next;
i = i + 1;
num = num + 1;


}
for (j = 0; j < num; j++)
{
for (i = 0; i < num; i++)
{
if (zong[i].gongzi next;
cout << "请输入员工姓名:";
cin >> fname;
cout << endl;
//cout << "进入循环前q->name为 "<name<name,fname)!=0&& NULL != q->next)
{
q = q->next;
}
//cout << "循环后q->name为 "<name << endl;
//cout << "        fanme为 "<name, fname)==0)
{

cout << q->name << "     工资:" << q->gongzi << endl;
}
else
{
cout << "无此员工!" << endl;
}




}
void guanli::scyg(LinkList &v)
{
q = v;
q = q->next;
//cout << "姓名            工资" << endl;
//while (q != NULL)
//{
//cout << q->name << endl;
//q = q->next;
//}
cout << "请输入想要删除的员工姓名:";
cin >> fname;
cout << endl;
//cout << "进入循环前q->name为 " << q->name << endl;
while (strcmp(q->next->name, fname) != 0 && NULL != q->next)
{
q = q->next;
}
//cout << "循环后q->name为 " << q->name << endl;
//cout << "        fanme为 " << fname << endl;
s = q->next;
if (strcmp(q->next->name, fname) == 0)
{
cout << "是否确认删除员工信息" << endl;
cout << "      1.确认" << endl;
cout << "      2.否" << endl;
cin >> a;
if (1 == a)
{
q->next = q->next->next;
system("cls");
cout << "删除成功。" << endl;
}
else
{
system("cls");
cout << "您已经取消操作。" << endl;
}
}
else
{
cout << "无此员工!" << endl;
}
}
void guanli::creat(LinkList &v)   //函数开始生成一个单链表
{   
v = (LinkList)malloc(LEN); 
v->next = NULL;
}
void guanli::back()
{


cout << "===>按Enter键返回主菜单";
getchar();
getchar();
}
void guanli::xieru(LinkList &v)
{
int num = 0;
q = v->next;
while (NULL != q)
{


temp.gongzi = q->gongzi;
strcpy(temp.name, q->name);
zong[i] = temp;
q = q->next;
i = i + 1;
num = num + 1;


}


ofstream outfile("wo.txt", ios::out | ios::in | ios::binary | ios::trunc);
for (i = 0; inext = NULL;
p = v;
int w=0;
ifstream infile("wo.txt");
string str;
for (i = 0; getline(infile, str) ; ++i)
{
istringstream instr(str);
instr >> str;
strcpy(zong[i].name, str.c_str());
instr >>zong[i].gongzi;
}
for (w = 0; w < i; w++)
{
s = (LinkList)malloc(LEN);
strcpy(s->name, zong[w].name);
s->gongzi = zong[w].gongzi;
s->next = p->next;        
p->next = s;
}




infile.close();
ofstream outfile("wo.txt", ios::out | ios::in | ios::binary | ios::trunc);
outfile.close();
}
类与函数定义

#include
#include
#include  
#include
#include
#include
using namespace std;
#define LEN sizeof(worker)   //LEN是节点的容量
class guanli
{
public:
typedef struct shuju   //数据是一种类型。和struct一样
{
char name[10]  ;    //数据域
int  gongzi;
shuju *next;     //指向下一个节点的指针
}worker;             


typedef worker *LinkList; //*LinkList与worker是一样的,只不过是为了突出前者是头指针
void zhujiemian();       //软件主界面
void xggz(LinkList &v);             //修改员工工资
void ckxx(LinkList &v);             //查看员工信息
void lrxx(LinkList &v);             //录入员工信息
void czxx(LinkList &v);             //查找员工信息
void ckgz(LinkList &v);             //查看员工工资
void scyg(LinkList &v);             //删除员工信息
void gyzz();                        //关于作者
void back();                        //返回主界面
void creat(LinkList &v);            //开始生成一个0节点的单链表
void xieru(LinkList &v);                          //写入文件   
void duqu(LinkList &v);               //打开程序读取文件
private:
LinkList q;
int i=0 ;
LinkList p;
LinkList s;
struct worker zong[100];
struct shuju temp;
char fname[30];
int a, money;
}


你可能感兴趣的:(数据结构与算法)