- GCC 版本升級(點擊此處查看)
- 源程式代碼(點擊此處下載)
- 三屬性,姓名/排班/科室
- 六功能,添加醫生/洗掉醫生/顯示醫生/修改資訊/查詢醫生/關閉系統
- 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;
}
效果圖:

轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/278891.html
標籤:其他
