- /***
- 医院挂号管理系统,主函数主要实现
- 挂号人员挂号、计费、查询、修改等
- 操作.
- 何晏波 作者 2013,7,1
- 杨凯 重写 2013,9,6
- ***/
- #include<iostream>
- #include<windows.h> //windowsAPI
- #include<iomanip> //IO流控制
- #include<fstream> //文件
- #include<string>
- #include<ctime>
- using namespace std;
- #include"user.h";
- int main()
- {
- system("color 9f");
- cout<<setfill(' ')<<setw(28)<<' ';
- cout<<"欢迎进入医院挂号管理系统"<<endl;
- main_select(); //挂号操作人员登陆
- return 0;
- }
- //********************************main.cpp
- SYSTEMTIME _time; //系统时间
- struct patient //病人类
- {
- char order_number[10];
- char name[10];
- char sex[10];
- char birth[10];
- char tel_number[20];
- };
- patient pat[4] = {{"01","丁丁","男","1994","1234"},{"02","冬冬","女","1993","5678"}};
- //*********************写入病人挂号信息
- void write_in(patient sick,char s1[])
- {
- ifstream f("C:\\\\患者信息.txt");
- ofstream f1("C:\\\\患者信息.txt",ios::app);
- f1<<"患者医保编号:"<<sick.order_number<<endl;
- f1<<"患者姓名:"<<sick.name<<endl;
- f1<<"患者性别:"<<sick.sex<<endl;
- f1<<"患者出生年份:"<<sick.birth<<endl;
- f1<<"患者联系电话:"<<sick.tel_number<<endl;
- f1<<"患者就诊科室:"<<s1<<endl;
- GetLocalTime(&_time); //取得当前时间并写入文档
- f1<<"挂号时间:"<<_time.wYear<<"年"<<_time.wMonth<<"月"<<_time.wDay<<"日"<<endl;
- f1<<"*****************************"<<endl;
- f1.close();
- }
- //********************检查是否已经挂号
- patient inf_check(char s[])
- {
- patient sick;
- ifstream f("C:\\\\患者信息.txt");
- if(f.fail())
- {
- strcpy(sick.order_number,s);
- strcpy(sick.name,"no");
- return sick;
- }
- else
- {
- for(int i = 0;i<2;i++)
- {
- if(strcmp(s,pat[i].order_number) == 0)
- {
- strcpy(sick.order_number,pat[i].order_number);
- strcpy(sick.name,pat[i].name);
- strcpy(sick.sex,pat[i].sex);
- strcpy(sick.birth,pat[i].birth);
- strcpy(sick.tel_number,pat[i].tel_number);
- return sick;
- }
- }
- strcpy(sick.name,"no");
- strcpy(sick.order_number,s);
- return sick;
- }
- f.close();
- }
- //定义所有操作的基类
- class operate
- {
- public:
- void register_new(); //执行挂号
- void calculate(); //统计费用
- void refer(); //查询并显示患者信息
- void modify(); //修改挂号科室与门诊类型
- void delete_data(); //删除文档信息
- void exit_all(); //退出
- };
- //*******************挂号
- void operate::register_new()
- {
- string n;
- int m;
- patient sick;
- system("cls");
- cout<<"请输入患者的医保编号:\\n";
- cin>>sick.order_number;
- sick = inf_check(sick.order_number);
- if(strcmp(sick.name,"no")!=0) //已经挂号
- {
- cout<<"该患者以前挂过号,请直接选择就诊科室与就诊类型"<<endl;
- Sleep(2000);
- goto q;
- } //未挂号先录入个人信息
- cout<<"请输入患者的姓名:\\n";
- cin>>sick.name;
- cout<<"请输入患者的性别:\\n";
- cin>>sick.sex;
- cout<<"请输入患者的出生年份:\\n";
- cin>>sick.birth;
- cout<<"请输入患者的联系电话:\\n";
- cin>>sick.tel_number;
- q:system("cls"); //挂号后之间选择科室
- cout<<setw(32)<<setfill(' ')<<'*'<<"挂号科室*\\n";
- cout<<setw(32)<<setfill(' ')<<'*'<<"1.内科*\\n";
- cout<<setw(32)<<setfill(' ')<<'*'<<"2.外科*\\n";
- cout<<setw(32)<<setfill(' ')<<'*'<<"3.骨科*\\n";
- cout<<setw(32)<<setfill(' ')<<'*'<<"4.五官科*\\n\\n";
- cout<<"请选择科室:\\n";
- cin>>m;
- system("cls");
- switch (m) //选择好科室,写入
- {
- case 1:
- write_in(sick,"内科");break;
- case 2:
- write_in(sick,"外科");break;
- case 3:
- write_in(sick,"骨科");break;
- case 4:
- write_in(sick,"五官科");break;
- }
- cout<<"挂号成功"<<endl;
- Sleep(1000);
- system("cls");
- }
- //************************统计挂号总费用
- //根据科室不同收费不同
- void operate::calculate()
- {
- string *s,s1;
- s=new string[1000];
- int i = 0;
- system("cls");
- ifstream f("C:\\\\患者信息.txt");
- if(f.fail())
- {
- cout<<"目前患者名单为空!"<<endl;
- Sleep(1000);
- }
- else
- {
- while(!f.eof())
- {
- f>>s[i]; //文件指针
- i++; //每个s[i]为txt文件中的一行记录
- }
- if(s[5].substr(13,4)=="内科") //字符串截取,比较
- { //以字节为单位,汉字为2位
- cout<<"内科挂号费为20"<<endl; //(13,4)定位到科室所在的位置
- }
- if(s[5].substr(13,4)=="外科")
- {
- cout<<"外科挂号费为30"<<endl;
- }
- Sleep(3000);
- }
- f.close();
- system("cls");
- }
- //***************************查询,打印患者信息
- void operate::refer()
- {
- char s[10];
- int x = 0;
- ifstream f("C:\\\\患者信息.txt");
- if(f.fail()) //没有记录
- {
- cout<<"目前患者名单为空!"<<endl;
- Sleep(1000);
- system("cls");
- }
- else
- {
- cout<<"请输入患者医保编号:"<<endl; //查询并打印信息
- cin>>s;
- for(int i = 0;i <2;i++)
- {
- if(strcmp(s,pat[i].order_number)==0)
- {
- cout<<"\\n该患者信息如下:"<<endl;
- cout<<"患者医保编号:"<<pat[i].order_number<<endl;
- cout<<"患者姓名:"<<pat[i].name<<endl;
- cout<<"患者性别:"<<pat[i].sex<<endl;
- cout<<"患者出生年份:"<<pat[i].birth<<endl;
- cout<<"患者联系电话:"<<pat[i].tel_number<<endl;
- x++;
- Sleep(1000);
- system("cls");
- }
- }
- if(!x) //找不到记录
- {
- cout<<"没有该患者的信息!"<<endl;
- Sleep(1000);
- system("cls");
- }
- }
- f.close();
- }
- //******************************修改电话号码
- void operate::modify()
- {
- int x=0;
- char m[10],n[10];
- ifstream f("C:\\\\患者信息.txt");
- if(f.fail()) //文件打开失败
- {
- cout<<"目前患者名单为空!"<<endl;
- Sleep(1000);
- system("cls");
- }
- else //根据医保编号修改号码
- {
- cout<<"请输入你要修改的医保编号"<<endl;
- cin>>m;
- for(int i = 0;i < 2;i++)
- {
- if(strcmp(m,pat[i].order_number)==0)
- {
- cout<<"请输入你要修改的号码"<<endl;
- cin>>n;
- strcpy(pat[i].tel_number,n);
- f.close();
- cout<<"信息修改完毕!"<<endl;
- x++;
- }
- }
- if(!x) //没有记录
- {
- cout<<"没有该患者的信息!"<<endl;
- }
- }
- Sleep(1000);
- system("cls");
- }
- //****************************删除信息
- void operate::delete_data()
- {
- system("cls");
- char a;
- cout<<"您确定要删除文档信息吗?(y/n)\\n";
- cin>>a;
- if(toupper(a)=='Y')
- {
- system("del C:\\\\患者信息.txt"); //删除
- cout<<"删除成功!"<<endl;
- Sleep(1000);
- }
- else;
- system("cls");
- }
- //**************************退出程序
- void operate::exit_all()
- {
- exit(0);
- }
- void main_select()
- {
- char m;
- string s1=" *******菜单*******\\n\\
- *1.执行挂号\\n\\
- *2.统计费用\\n\\
- *3.查询并显示患者信息\\n\\
- *4.修改电话号码\\n\\
- *5.删除文档信息\\n\\
- *6.退出\\n";
- d:cout<<s1;
- cout<<"请选择:"<<endl;
- cin>>m;
- if(m < '1' || m > '6')
- {
- cout<<"请输入1-6之间的数字";
- cin>>m;
- }
- m = atoi(&m);
- operate person;
- if(m == 1)
- {
- person.register_new();
- goto d;
- }
- if(m == 2)
- {
- person.calculate();
- goto d;
- }
- if(m == 3)
- {
- person.refer();
- goto d;
- }
- if(m == 4)
- {
- person.modify();
- goto d;
- }
- if(m == 5)
- {
- person.delete_data();
- goto d;
- }
- if(m == 6)
- {
- person.exit_all();
- }
- }
- //**********************************user.h
- //该片段来自于http://www.codesnippet.cn/detail/040520149418.html
来源: http://www.codesnippet.cn/detail/040520149418.html