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)


相关推荐

  • 资源-好用的网站_有有资源网

    资源-好用的网站_有有资源网##获取随机图片的API接口:https://uploadbeta.com/api/pictures/random/?key=BingEverydayWallpaperPicturehttps:/

  • c浅拷贝和深拷贝的区别_js中深拷贝和浅拷贝的区别

    c浅拷贝和深拷贝的区别_js中深拷贝和浅拷贝的区别先考虑一种情况,对一个已知对象进行拷贝,编译系统会自动调用一种构造函数——拷贝构造函数,如果用户未定义拷贝构造函数,则会调用默认拷贝构造函数。先看一个例子,有一个学生类,数据成员时学生的人数和名字:#include<iostream>usingnam…

  • Tp-link路由器怎么设置端口映射 内网端口映射听语音

    Tp-link路由器怎么设置端口映射 内网端口映射听语音

  • python查看pkl文件保存模型参数_python 文件路径

    python查看pkl文件保存模型参数_python 文件路径#show_pkl.pyimportpicklepath=’E:/somecode/Faster-RCNN-TensorFlow\default/voc_2007_trainval/default/vgg16_faster_rcnn_iter_10000.pkl’#path=’/root/……/aus_openface.pkl’pkl文件所在路径f=open(path,’rb’)data=pickle.load(f)print(data)print(len(

  • 傅里叶变换及其实现(MATLAB)

    傅里叶变换及其实现(MATLAB)傅立叶变换傅立叶变换是一种常见的分析方法,傅立叶变换将满足一定条件的函数表示为一些函数的加权和(或者积分)。可以分为四个类别:1.非周期连续性信号对应于傅里叶变换,频域连续非周期2.周期性连续性信号对应于傅立叶级数,频域离散非周期3.非周期离散信号对应于DTFT(离散时间傅立叶变换),频域连续周期4.周期性离散信号对应于D

  • 微机原理与接口技术知识点整理复习–纯手打

    微机原理与接口技术知识点整理复习–纯手打明天就要考试了,来一波知识点整理。都会了,期末考试你不过你来找我!第一章1.按微处理器的字节分类4位微处理器8位微处理器16位微处理器32位微处理器2.这个必须背,不是简答就是简答,肯定出简答3.系统软件给一个实例判断是否是系统软件!常见的系统软件:操作系统、程序语言设计、语言处理程序、数据库管理程序、系统辅助处理程序第二章1….

发表回复

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

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