总结遇到最多的问题,这个坑真大
#define once
#include
#include
#include
#include "worker.h"
using namespace std;
#define SIZE_MAX 3
class LinkClass
{
public:
Worker *wp;
LinkClass *next;
};
class WorkerManager
{
public:
WorkerManager(LinkClass *L);
~WorkerManager();
int M_no;
int M_duty;
string M_name;
LinkClass *LinkList;
int M_size;
void DeleteLink(LinkClass *L);
//显示菜单
void ShowMenu();
//添加
bool Ems_Add(LinkClass *L);
//删除
bool Ems_Delete(LinkClass *L);
//修改
bool Ems_Edit(LinkClass *L);
//查找
bool Ems_Find(LinkClass *L);
//本地存储
bool Ems_Write(const LinkClass *L);
//本地读取
bool Ems_Read(LinkClass *L, WorkerManager *pw);
//打印Link
void Ems_Show(const LinkClass *L);
//
void Ems_DeleteAll(LinkClass *L);
};
void InfoLink(LinkClass *p, WorkerManager *pw);
#define _CRT_SECURE_NO_WARNINGS 1
#include
#include
using namespace std;
//职工类
class Worker
{
public:
//显示个人信息
virtual void showInfo() = 0;
//获取岗位
virtual string getDeptName() = 0;
int M_Id;//编号
int M_Duty;//部门编号
string M_Name;//姓名
};
//老板
class Boss : public Worker
{
public:
//构造
Boss(int id,int duty,string name);
//显示个人信息
void showInfo();
//获取岗位
string getDeptName();
};
//经理
class Manager : public Worker
{
public:
//构造
Manager(int id, int duty, string name);
//显示个人信息
void showInfo();
//获取岗位
string getDeptName();
};
//员工
class FlWorker : public Worker
{
public:
//构造
FlWorker(int id, int duty, string name);
//显示个人信息
void showInfo();
//获取岗位
string getDeptName();
};
#define _CRT_SECURE_NO_WARNINGS 1
#include "Ems.h"
void InfoLink(LinkClass *p, WorkerManager *pw)
{
p->wp = (Worker*)new int(0);
p->next = NULL;
pw->Ems_Read(p, pw);
}
void WorkerManager::DeleteLink(LinkClass *L)
{
LinkClass *p = L;
while (p)
{
LinkClass *cur = p->next;
delete p->wp;
delete p;
p = cur;
this->M_size--;
}
}
bool WorkerManager::Ems_Write(const LinkClass *L)
{
bool flag = true;
LinkClass *p = L->next;
ofstream ofs;
ofs.open("Ems.dat", ios::out | ios::binary | ios::trunc);
if (!(ofs.is_open()))
return false;
while (p)
{
ofs.write((char*)p->wp, sizeof(Worker));
p = p->next;
flag = false;
}
if (flag)
ofs > c))
return false;
ifs.seekg(0);
while (ifs.read((char*)L->wp, sizeof(Worker)))
{
LinkClass *s = new LinkClass;
int id = L->wp->M_Id;
int duty = L->wp->M_Duty;
string name = L->wp->M_Name;
switch (duty)
{
case 1:
s->wp = new Boss(id, duty, name);
break;
case 2:
s->wp = new Manager(id, duty, name);
break;
case 3:
s->wp = new FlWorker(id, duty, name);
break;
default:
break;
}
s->next = NULL;
p->next = s;
p = p->next;
pw->M_size++;
}
ifs.close();
return true;
}
void WorkerManager::ShowMenu()
{
cout M_size = 0;
this->LinkList = L;
}
WorkerManager::~WorkerManager()
{
this->DeleteLink(LinkList);
cout 请输入工号:>";
cin >> id;
if (-1 == id)
break;
while (p->next)
{
if (p->wp->M_Id == id)
{
cout next;
}
LinkClass *s = NULL;
s = new LinkClass;
cout 请选择职位:>";
cin >> duty;
cin.clear(); cin.ignore();
switch (duty)
{
case 1:
cout 请输入姓名:>";
cin >> name;
s->wp = new Boss(id, duty, name);
break;
case 2:
cout 请输入姓名:>";
cin >> name;
s->wp = new Manager(id, duty, name);
break;
case 3:
cout 请输入姓名:>";
cin >> name;
s->wp = new FlWorker(id, duty, name);
break;
default:
cout 职位选项无效,添加失败!" wp)
return false;
s->next = NULL;
p->next = s;
this->M_size++;
p = p->next;
cout 添加成功,继续添加!" 请输入工号:>";
cin >> id;
while (p->next)
{
if (p->next->wp->M_Id == id)
{
LinkClass *tmp = p->next;
if (!p->next->next)
p->next = NULL;
else
p->next = p->next->next;
delete tmp;
this->M_size--;
cout 删除成功!" next;
}
if (!flag)
{
cout 删除失败,工号不存在!" 输入要修改人的工号:>";
cin >> id;
while (p)
{
if (p->wp->M_Id == id)
{
int duty = 0;
string name;
LinkClass *tmp = L;
bool repaet = false;
cout 请输入修改后工号:>";
cin >> id;
if (!(-1 == id))
{
while (tmp)
{
if (tmp->wp->M_Id == id)
{
cout next;
}
if (repaet)
continue;
p->wp->M_Id = id;
}
cout 请选择修改后职位:>";
cin >> duty;
cin.clear(); cin.ignore();
if (1 == duty || 2 == duty || 3 == duty)
{
p->wp->M_Duty = duty;
cout 请输入修改后姓名:>";
cin >> name;
flag = true;
}
else if (-1 == duty)
{
cout 请输入修改后姓名:>";
cin >> name;
flag = true;
}
else
cout 职位选项无效,修改失败!";
} while (!flag);
flag = true;
break;
}
p = p->next;
}
if (!flag)
{
cout 工号不存在!" 请选择:" > choice;
while (true)
{
if (1 == choice)
{
cout 请输入工号:>";
cin >> id;
while (p)
{
if (p->wp->M_Id == id)
{
if (p->wp->M_Duty > 0)
p->wp->showInfo();
flag = true;
}
p = p->next;
}
break;
}
else if (2 == choice)
{
cout 请输入姓名:>";
cin >> name;
while (p)
{
if (p->wp->M_Name == name)
{
if (p->wp->M_Duty > 0)
p->wp->showInfo();
flag = true;
}
p = p->next;
}
break;
}
else
{
cout 输入选项无效!" 查找结果不存在!" next;
cout wp->showInfo();
p = p->next;
}
}
}
void WorkerManager::Ems_DeleteAll(LinkClass *L)
{
LinkClass *p = L;
if (0 == M_size)
return;
string input;
cout 请输入' yes '确认(输入其他视为取消操作) :>";
cin >> input;
if (input == "yes")
{
this->DeleteLink(p);
cout
#define _CRT_SECURE_NO_WARNINGS 1
#include "Ems.h"
Boss::Boss(int id,int duty,string name)
{
M_Id = id;
M_Duty = duty;
M_Name = name;
}
void Boss::showInfo()
{
cout M_Id M_Name
getDeptName() M_Id M_Name
getDeptName() M_Id M_Name
getDeptName()
#define _CRT_SECURE_NO_WARNINGS 1
#include "Ems.h"
enum Ch
{
EMS_EXIT,//退出 0
EMS_ADD,//增 1
EMS_DELETE,//删 2
EMS_EDIT,//改3
EMS_FIND,//查 4
EMS_SHOW,//显示 5
EMS_DELETEALL//销毁表 6
};
void test()
{
LinkClass Lc;
WorkerManager w(&Lc);
int choice = 0;
//bool flag = true;
InfoLink(&Lc, &w);
while (true)
{
//if (!flag)
// break;
w.ShowMenu();
cout 请选择:>";
cin >> choice;
cin.clear(); cin.ignore();
switch (choice)
{
case EMS_EXIT://退出
w.Ems_Write(&Lc);
cout
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
几十年来,运筹学(OR)和机器学习(ML)一直作为两个相对独立的研究领域不断发展。数据科学和人工智能领域的专家可能更熟悉机器学习而不是运筹学,尽管每个机器学习实践者都应该至少了解一些优化技术,因为每个机器学习问题本质上都是一个优化问题。在本文中,我将把运筹学和…