- 三属性,姓名/排班/科室
- 六功能,添加医生/删除医生/显示医生/修改信息/查询医生/关闭系统
- PS,需要新建pHIS.txt & temp.txt
- system(“cls”); //无效
system(“pause”); //无效
且头文件需要加 #include stdlib.h
/*
* 东软云HIS医院管理系统
* 简介:三属性,姓名/排班/科室
* 六功能,添加医生/删除医生/显示医生/修改信息/查询医生/关闭系统
* 作者:181203616-宋明桥-GodOuO
* 修改履历:
* 21年4月,创建文件
*/
#include <iostream>
#include <stdlib.h>
#include <iomanip> //设置流操作符
#include <fstream> //文件流操作
using namespace std;
class HIS{ //类HIS
private:
string name; //姓名
string roster; //排班
string department; //科室
public:
HIS(); //构造函数
char inter_face(); //首页
void add_person(); //添加医生
void del_person(); //删除医生
void show_all(); //显示所有医生
void alter(); //修改信息
void select(); //查询医生
void save_new(); //保存新增加的医生
};
HIS::HIS(){
name = "\0";
roster = "\0";
department = "\0";
}
//首页
char HIS::inter_face(){ //实现首界面的函数
system("cls"); //清屏操作
cout<<endl;
cout
<<" ._________________________. "<<endl
<<" | _______________________ | "<<endl
<<" | I I | "<<endl
<<" | I HIS医院管理系统 I | "<<endl
<<" | I_____________________I | "<<endl
<<" !_________________________! "<<endl
<<" (1) 添加医生 "<<endl
<<" (2) 删除医生 "<<endl
<<" (3) 显示医生 "<<endl
<<" (4) 修改信息 "<<endl
<<" (5) 查询医生 "<<endl
<<" (6) 关闭系统 "<<endl
<<endl
<<" 选择 :" ;
char choose;
cin>>choose;
return choose;
}
void HIS::add_person(){ //类外定义添加医生函数
cout<<"请输入新医生信息" <<endl;
cout <<"姓名 : ";
cin >>name;
cout <<"科室 : ";
cin >>department;
cout <<"排班 : ";
cin >>roster;
save_new();
cout<<"新信息已经保存!" <<endl;
system("pause");
}
void HIS::del_person(){ //类外定义删除医生函数
string sign,str1,str; //定义字符串
bool flag = true; //布尔型变量初始为真
cout<<"你要删除输入姓名或科室号 :"<<endl; //输入要查找的相关信息
cin>>sign;
ofstream outData("temp.txt", ios::out); //磁盘文件的输出
ifstream inData("pHIS.txt", ios::in); //输入
if (!outData || !inData){ //判断
cout<<"对不起,找不到文件!" <<endl;
system("pause");
}
while (inData>>name>>department){ //将数组或字符输入indata
getline(inData, str); //接收一个字符串
if ((sign==name) || (sign==department)){ //存在此医生
cout <<"你想删除的医生:"<<endl;
cout <<str1 <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<name<<" " <<department <<str <<endl; //左对齐
flag = false;
break;
}
outData <<setiosflags(ios::left) <<setw(17) <<name<<" " <<department <<str <<endl;
}
if (flag){
cout <<endl <<"系统中不存在!" <<endl <<endl;
}
else{
while (getline(inData, str)){
outData <<str <<endl;
}
outData.close();
inData.close();
ofstream out("pHIS.txt", ios::out);
ifstream in("temp.txt", ios::in);
if (!out || !in){
cout <<endl <<"对不起不能打开文件!" <<endl <<endl;
system("pause");
return;
}
while (getline(in, str)){
out <<str <<endl;
}
out.close(); //文件流关闭
in.close();
cout <<endl <<"信息已中删除!" <<endl <<endl;
}
system("pause");
}
void HIS::show_all(){ //显示所有医生
//类外定义显示所有医生函数
ifstream inData("pHIS.txt",ios::in);
if (!inData){
cout <<endl <<"对不起,没有找到文件!" <<endl;
system("pause");
return;
}
bool flag = true;
string record;
while (getline(inData, record)){
if (flag){
cout <<endl <<"所有医生信息如下: \n"<<endl;
}
cout <<" 姓名\t\t"<<"科室\t\t"<<"排班\t\t"<<endl;
cout <<record <<endl;
flag = false;
}
if (flag){
cout <<endl <<"你的HIS医院管理系统中没有医生!" <<endl <<endl;
}
else{
cout <<endl <<"所有医生已经全部显示!" <<endl <<endl;
}
system("pause");
}
//修改信息
void HIS::alter(){ //类外定义显示信息函数
ofstream outData("temp.txt", ios::out);
ifstream inData("pHIS.txt", ios::in);
if (!outData || !inData){ //任意为假值运行
cout <<endl <<"找不到文件!" <<endl;
system("pause");
return;
}
string sign;
cout <<endl <<"你要修改输入姓名或科室号 :";
cin >>sign;
bool flag = true;
string str;
while (inData >>name >>department){
getline(inData, str);
if ((sign==name) || (sign==department)){
cout <<endl <<"你想修改的医生:" <<endl <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<name<<" " <<department <<str <<endl;
cout <<endl <<"请修改信息 : " <<endl;
cout <<"姓名 :" ;
cin >>name;
cout <<"科室 :";
cin >>department;
cout <<"排班 :";
cin >>roster;
save_new();
flag = false;
break;
}
outData <<setiosflags(ios::left) <<setw(17) <<name<<" " <<department <<str <<endl;
}
if (flag){
cout <<endl <<"医系统中不存在!"<<endl;
}
else{
while (getline(inData, str)){
outData <<str <<endl;
}
outData.close();
inData.close();
ofstream out("pHIS.txt", ios::out);
ifstream in("temp.txt", ios::in);
if (!out || !in){
cout <<endl <<"对不起不能打开文件!!!"<<endl;
system("pause");
return;
}
while (getline(in, str)){
out <<str <<endl;
}
out.close();
in.close();
cout<<"已修改!!!"<<endl;
}
system("pause");
}
//查询医生
void HIS::select(){ //类外定义查询医生函数
ifstream inData("pHIS.txt",ios::in);
if (!inData){
cout <<endl <<"文件找不到!" <<endl;
system("pause");
return;
}
string sign;
cout <<endl <<"输入你想查找的医生的姓名或科室: ";
cin >>sign;
bool flag = true;
string str;
while (inData >>name >>department){
getline(inData, str);
if ((name==sign) || (department==sign)){
cout <<endl <<"你要查找的医生是: " <<endl <<endl;
cout <<setiosflags(ios::left) <<setw(17) <<name <<department <<str <<endl;
flag = false;
//system("pause");
}}}
void HIS::save_new(){ //类外定义保存医生函数
ofstream outData("pHIS.txt", ios::app);
if (!outData){
cout <<"对不起,打开文件失败!"<<endl;
system("pause");
return;
}
outData << setiosflags(ios::left) << setw(17) << name<<" " << setw(16) << department <<" "<< setw(20) << roster <<endl;
outData.close();
}
enum power{a1 = '1', a2 = '2', a3 = '3', a4 = '4', a5 = '5', a6 = '6'};
int main(){
char choose;
HIS song;
while (choose = song.inter_face()){
switch (choose){
case a1:
song.add_person();//添加医生
break;
case a2:
song.del_person();//删除医生
break;
case a3:
song.show_all();//显示所有医生
break;
case a4:
song.alter();//修改信息
break;
case a5:
song.select();//查询医生
break;
case a6:
cout <<endl <<"谢谢使用!" <<endl <<endl;
exit(0);
break;
default:
break;}}
return 0;
}
效果图: