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;
	}
}

 

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

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • hmac 签名_em球衣签名

    hmac 签名_em球衣签名在提供第三方接口的时候,我们需要确认:1.消息未被其他人篡改(签名和验证签名)2.从消息中确认第三方的身份(appid)因为hash是不可逆的,所以签名的过程是不可逆的;HMACSHA1是从SHA1哈希函数构造的一种键控哈希算法,被用作HMAC(基于哈希的消息验证代码)。此HMAC进程将密钥与消息数据混合,使用哈希函数对混合结果进行哈希计算,将所得哈希值与该密钥混…

    2025年7月31日
    0
  • int和int32的区别_int是多少位的

    int和int32的区别_int是多少位的大家有没有写了很久代码,还不知道这个Int8,Int16,Int32,Int64有什么区别呢?或者是为什么后面的数字不一样呢?初步了解了一下,才清楚这个东西。先来扫盲一下计算机存储单元,  在计算机内部,信息都是釆用二进制的形式进行存储、运算、处理和传输的。信息存储单位有位、字节和字等几种。各种存储设备存储容量单位有KB、MB、GB和TB等几种计算机的基本的存储单元有:…

    2022年8月15日
    2
  • PLSQL安装步骤

    PLSQL安装步骤PLSQL安装注意事项1、安装下载PLSQL安装包,解压,默认安装选择自己需要的版本安装,一路默认即可2、添加客户端路径解压instantclient_11_2.rar放到自定义目录下,我是放在D盘下的Tools目录没有配置客户端,是无法登陆的,所以先不登录进入:找到plsql的configure–>preferences,如图配置,完成后重启即可3、配置tnsnames文件在客户端解压的目录“D:\Tools\instantclient_11_2”下创建NE

    2022年6月15日
    34
  • 暑假训练赛第六场

    暑假训练赛第六场

    2021年9月27日
    45
  • 160个练手CrackMe-034

    160个练手CrackMe-0341 无壳 FileKey 类型 2 OD 载入 00 6A00push0x0 hTemplateFil NULL00 push0x80 Attributes NOR

    2025年6月18日
    0
  • ViewStub总结

    ViewStub总结ViewStub是一个不可见的,大小为0的View,最佳用途就是实现View的延迟加载,避免资源浪费,在需要的时候才加载View;其特性如下:1、调用其inflate()的时候,其布局属性android:layout=”@layout/布局”将会替换这个ViewStub标签,这个时候我们使用findViewById将获取这个ViewStub对象为空,所以是可以被替换这一点的;2、infla

    2022年6月28日
    24

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

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