c酒店管理系统代码_酒店管理系统

c酒店管理系统代码_酒店管理系统主要功能:1.添加员工信息2.显示员工信息3.删除员工信息4.修改员工信息5.查找员工信息6.员工信息排序7.清空数据(1)显示数据(2)修改数据(3)查找数据(4)信息排序部分代码展示:workerManager.cpp。需要完整代码可以留邮箱,有时间就发#include”stdafx.h”#include”work…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

主要功能:

1.添加员工信息

2.显示员工信息

3.删除员工信息

4.修改员工信息

5.查找员工信息

6.员工信息排序

7.清空数据

(1)显示数据

c酒店管理系统代码_酒店管理系统

(2)修改数据

c酒店管理系统代码_酒店管理系统

c酒店管理系统代码_酒店管理系统

(3)查找数据

c酒店管理系统代码_酒店管理系统

(4)信息排序

c酒店管理系统代码_酒店管理系统

部分代码展示:workerManager.cpp。需要完整代码可以留邮箱,有时间就发

#include "stdafx.h"
#include "workerManager.h"
WorkerManager::WorkerManager()
{
//1.文件不存在
ifstream ifs;
ifs.open(FILENAME, ios::in);//读文件
if (!ifs.is_open())
{
//cout << "文件不存在" << endl;
this->m_staffNum = 0;
this->m_staffArray = NULL;
this->m_FileIsEmpty = true;
ifs.close();
return;
}
//2.文件存在,数据为空
char ch;
ifs >> ch;
if (ifs.eof())
{
//cout << "文件为空!" << endl;
this->m_staffNum = 0;
this->m_staffArray = NULL;
this->m_FileIsEmpty = true;
ifs.close();
return;
}
//3.文件存在数据
int num = this->get_staffNum();
this->m_staffNum = num;
//开辟空间
this->m_staffArray = new Worker*[this->m_staffNum];
//将文件中的数据存在数组中
this->init_staff();
}
void WorkerManager::Show_Menu()
{
cout << "*********************************************" << endl;
cout << "*************欢迎进入酒店管理系统************" << endl;
cout << "***************0.退出管理系统****************" << endl;
cout << "***************1.添加员工信息****************" << endl;
cout << "***************2.显示员工信息****************" << endl;
cout << "***************3.删除员工信息****************" << endl;
cout << "***************4.修改员工信息****************" << endl;
cout << "***************5.查找员工信息****************" << endl;
cout << "***************6.员工信息排序****************" << endl;
cout << "***************7.清空员工信息****************" << endl;
cout << "*********************************************" << endl;
cout << endl;
}
void WorkerManager::exitSystem()
{
cout << "系统退出" << endl;
system("pause");
exit(0);
}
void WorkerManager::Add_staff()
{
cout << "输入添加员工的数量:" << endl;
int  addNum = 0;  //保存员工的数量
cin >> addNum;
if (addNum > 0)
{
//计算新空间的大小
int newSize = this->m_staffNum + addNum;
//开辟新空间
Worker ** newSpace=new Worker *[newSize];
//将原始数据拷贝到新空间中
if (this->m_staffArray != NULL)
{
for (int i = 0; i < this->m_staffNum; i++)
{
newSpace[i] = this->m_staffArray[i];
}
}
for (int i = 0; i < addNum; i++)
{
int id;
string name;
int dId;
cout << "请输入第" << i + 1 << "个员工的编号:" << endl;
cin >> id;
//判断该编号是否存在
int ret = this->IsExist(id);  
if (ret != -1)
{
while (1)
{
cout << "该编号已存在,请重新输入编号:" << endl;
cin >> id;
ret = this->IsExist(id);
if (ret == -1)
{
break;
}
}
}
cout << "请输入第" << i + 1 << "个员工的姓名:" << endl;
cin >> name;
cout << "请输入该员工的岗位:" << endl;
cout << "1.普通员工" << endl;
cout << "2.经理" << endl;
cout << "3.老板" << endl;
cin >> dId;
Worker *worker = NULL;
switch (dId)
{
case 1:
worker = new staff(id, name, 1);
break;
case 2:
worker = new manager(id, name, 2);
break;
case 3:
worker = new boss(id, name, 3);
break;
default:
break;
}
//将数据保存
newSpace[this->m_staffNum + i] = worker;
}
//释放原有空间
delete[] this->m_staffArray;
//更改新空间的指向
this->m_staffArray = newSpace;
//更新新的员工数量
this->m_staffNum = newSize;
//提示添加成功
this->m_FileIsEmpty = false;//文件不为空
cout << "成功添加" << addNum << "个员工" << endl;
this->save();
}
else
{
cout << "输入有误!" << endl;
}
//按任意键回到上级目录
system("pause");
system("cls");
}
void WorkerManager::save()
{
ofstream ofs;
ofs.open(FILENAME, ios::out);  //写文件
for (int i = 0; i < this->m_staffNum; i++)  
{
ofs << this->m_staffArray[i]->m_Id << " "
<< this->m_staffArray[i]->m_Name << " "
<< this->m_staffArray[i]->m_dId << endl;
}
//关闭文件
ofs.close();
}
int WorkerManager::get_staffNum()
{
ifstream ifs;
ifs.open(FILENAME, ios::in); //打开文件,读操作
int id;
string name;
int dId;
int num = 0;
while (ifs >> id && ifs >> name && ifs >> dId)
{
num++;
}
return num;
}
void WorkerManager::init_staff()
{
ifstream ifs;
ifs.open(FILENAME, ios::in);
int id;
string name;
int dId;
int index = 0;
while (ifs >> id && ifs >> name && ifs >> dId)
{
Worker * worker = NULL;
if (dId == 1)
{
worker = new staff(id, name, dId);
}
else if (dId == 2)
{
worker = new manager(id, name, dId);
}
else if (dId == 3)
{
worker = new boss(id, name, dId);
}
this->m_staffArray[index] = worker;
index++;
}
ifs.close();
}
//显示员工数据
void WorkerManager::show_staff()   
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者记录为空" << endl;
}
else
{
for (int i = 0; i < m_staffNum; i++)
{
this->m_staffArray[i]->showInfo();
}
}
system("pause");
system("cls");
}
//
int WorkerManager::IsExist(int id)
{
int index = -1;
for (int i = 0; i < this->m_staffNum; i++)
{
if (this->m_staffArray[i]->m_Id == id)
{
index = i;
break;
}
}
return index;
}
//删除员工
void WorkerManager::Del_staff()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者为空" << endl;
}
else
{
cout << "请输入删除员工的的编号:" << endl;
int id = 0;
cin >> id;
int index = this->IsExist(id);
if (index != -1)  //员工存在,删除
{
for (int i = index; i < this->m_staffNum - 1; i++)
{
this->m_staffArray[i] = this->m_staffArray[i + 1];
}
this->m_staffNum--; //更新员工的数量
//文件数据同步
this->save();
cout << "删除成功" << endl;
}
else
{
cout << "该员工不存在" << endl;
}
//清屏操作
system("pause");
system("cls");
}
}
//修改员工数据
void WorkerManager::Mod_staff()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者为空" << endl;
}
else
{
cout << "请输入修改的职工编号:" << endl;
int id;
cin >> id;
int ret=this->IsExist(id);
if (ret != -1)
{
delete this->m_staffArray[ret];
int newId = 0;
string newName = " ";
int newdId = 0;
cout << "查找到" << id << "号职工,请输入新职工编号:" << endl;
cin >> newId;
cout << "请输入新的名字:" << endl;
cin >> newName;
cout << "请输入新的岗位" << endl;
cout << "1.清洁员" << endl;
cout << "2.经理" << endl;
cout << "3.老板" << endl;
cin >> newdId;
Worker * worker = NULL;
switch (newdId)
{
case 1:
worker = new staff(newId, newName, newdId);
break;
case 2:
worker = new manager(newId, newName, newdId);
break;
case 3:
worker = new boss(newId, newName, newdId);
break;
default:
break;
}
//更新数据到数组中
this->m_staffArray[ret] = worker;
cout << "修改成功" << endl;
//保存到文件中
this->save();
}
else
{
cout << "修改失败,查无此人" << endl;
}
}
system("pause");
system("cls");
}
//查找员工
void WorkerManager::Find_staff()
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者数据为空";
}
else
{
cout << "请输入查找方式:" << endl;
cout << "1.按编号查找" << endl;
cout << "2.按姓名查找" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
int id;
cout << "请输入查找的职工编号:" << endl;
cin >> id;
int ret = IsExist(id);
if (ret != -1)
{
cout << "查找成功!该员工信息如下:" << endl;
this->m_staffArray[ret]->showInfo();
}
else
{
cout << "查无此人" << endl;
}
}
else if (select == 2)
{
string name;
cout << "请输入查找的职工名字:" << endl;
cin >> name;
//判断是否查到
bool flag = false;//默认未找到
for (int i = 0; i < m_staffNum; i++)
{
if (this->m_staffArray[i]->m_Name == name)
{
cout << "查找成功,职工编号为:"
<< this->m_staffArray[i]->m_Id
<< "该员工信息如下:" << endl;
flag = true;
this->m_staffArray[i]->showInfo();
}
}
if (flag == false)
{
cout << "查无此人" << endl;
}
}
else
{
cout << "查无此人" << endl;
}
}
system("pause");
system("cls");
}
//对员工编号进行排序
void WorkerManager::Sort_staff()  
{
if (this->m_FileIsEmpty)
{
cout << "文件不存在或者为空" << endl;
system("pause");
system("cls");
}
else
{
cout << "请选择排序方式:" << endl;
cout << "1.升序排列" << endl;
cout << "2.降序排序" << endl;
int select = 0;
cin >> select;
for (int i = 0; i < m_staffNum; i++)
{
int minOrMax = i;  //最小值或者对大值的下标
for (int j = i + 1; j < m_staffNum; j++)
{
if (select == 1) //升序
{
if (this->m_staffArray[minOrMax]->m_Id > this->m_staffArray[j]->m_Id)
{
minOrMax = j;
}
}
else //降序
{
if (this->m_staffArray[minOrMax]->m_Id < this->m_staffArray[j]->m_Id)
{
minOrMax = j;
}
}
}
if (i != minOrMax)
{
Worker * temp = this->m_staffArray[i];
this->m_staffArray[i] = this->m_staffArray[minOrMax];
this->m_staffArray[minOrMax] = temp;
}
}
cout << "排序成功!" << endl;
this->show_staff();
this->save();
}
}
void WorkerManager::Clean_File()
{
cout << "确认清空数据?" << endl;
cout << "1.确认" << endl;
cout << "2.返回" << endl;
int select = 0;
cin >> select;
if (select == 1)
{
ofstream ofs(FILENAME, ios::trunc);//删除后重建,相当于清空
ofs.close();
if (this->m_staffArray != NULL)
{
//删除堆区的每个对象
for (int i = 0; i < this->m_staffNum; i++)
{
delete this->m_staffArray[i];
this->m_staffArray[i] = NULL;
}
//删除堆区数组指针
delete[] this->m_staffArray;
this->m_staffArray = NULL;
this->m_staffNum = 0;
this->m_FileIsEmpty = true;
}
cout << "清空成功" << endl;
}
system("pause");
system("cls");
}
WorkerManager::~WorkerManager()  //释放
{
if (this->m_staffArray != NULL)
{
for (int i = 0; i < m_staffNum; i++)
{
delete this->m_staffArray[i];
this->m_staffArray[i] = NULL;
}
delete[]this->m_staffArray;
this->m_staffArray = NULL;
}
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/189905.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • hdoj 2602 Bone Collector 【01背包】

    hdoj 2602 Bone Collector 【01背包】

  • python基础(3)列表list「建议收藏」

    python基础(3)列表list「建议收藏」列表列表特点:是一种序列结构,与元组不同,列表具有可变性,可以追加、插入、删除、替换列表中的元素新增元素appendappend添加一个对象,可以是任意类型a=['zhangsa

  • 怎么用python做自动回复机器人_微信群机器人哪个好用

    怎么用python做自动回复机器人_微信群机器人哪个好用首先,我们需要安装并配置好Python环境,并安装requests和itchat包,我用的是Windows7环境!https://www.python.org/python官网下载然后直接打开安装选择path那个选项勾选(直接添加环境变量以及路径)直接下一步直到安装完成运行cmd然后cmd命令行输入pipinstallitchatrequests等待安装完成现…

  • Java标识符命名规则(超详细!)[通俗易懂]

    Java标识符命名规则(超详细!)[通俗易懂]规则1:标识符只能由数字、字母(包括中文)、下划线_、美元符号$组成,不能含有其它符号。规则2:标识符不能以数字开头规则3:关键字不能做标识符。例如:publicclassstaticvoid这些蓝色的字体都是关键字,关键字是不能做标识符的。规则4:标识符是严格区分大小写的。大写A和小写a不一样。规则5:标识符理论上是没有长度限制的。…

  • jquery ajax步骤,jquery ajax(ajax请求的五个步骤jQuery)

    jquery ajax步骤,jquery ajax(ajax请求的五个步骤jQuery)jqueryajaxAJAX是与服务器交流数据的艺术,它在不重载全部页面的情况下,完成了对部分网页的更新。jQueryAJAX实例请点击下面的按钮,经过jQueryAJAX改变这段文本。获得外部的内容亲身试一试什么是AJAX?AJAX=异步JavaScript和XML(AsynchronousJavaScriptandXML)。简短地说,在不重载整个网页的情况下,AJAX经过后台加载数据,并在网页…

  • transactionscope mysql_c# – 嵌套的TransactionScope在测试中失败

    transactionscope mysql_c# – 嵌套的TransactionScope在测试中失败我正在使用MSTest通过MySQLConnector和使用EntityFramework4.3对MysqL5.5.19数据库运行一些自动化测试.我正在尝试在我的数据库访问类库中使用TransactionScope在需要时执行回滚.另外,在我的测试代码中,我希望在每次测试之前使用TransactionScope将数据库恢复到已知状态.我使用TestInitialize和TestCleanup…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号