//设计人类(Person类)和医生类(Doctor类),在此基础上,通过增加患者和账单,使它们公用于表示一家诊所的信息管理。
//(1)在一条医生记录中,包括医生的专业说明(specialty),
// 如内科医生(surgeon)、儿科医生(pediatrician) 、产科医生(obstetrician)及全科医生(general practitioner)。
//(2)Doctor记录还含有诊费(office_vist_fee)。
//(3)在一条患者记录中,包括该患者产生的药费(drug_fee) ,患者的诊费(即医生的诊费)。
//(4)在一条账单记录中,包括一条患者对象、该患者对应得主治医生、该患者产生的诊费和药费。
//(5)应用程序能够显示出诊所中每个患者的信息和对应主治医生的信息。
//(6)能够统计出所有患者的总费用。
#define _CRT_SECURE_NO_WARNINGS 1 //vs2013的环境需要这句话
#include <iostream>
#include <cstring>
#include <windows.h>
#include <fstream>
#include <stdlib.h>
using namespace std;
#define N 200
class Person //人
{
public:
Person(){}
Person(const char *_Name, const char *_Sex, const char *_Address, int _Age);
void Print();
~Person(){}
//
char Name[10];
char Sex[3];
char Address[20];
int Age;
};
class Doctor //医生
{
public:
Doctor(){}
Doctor(const char *_Dname, const char *_Specialty, double _Fees);
void Print();
void D_Add();
int D_Select(Doctor Doc[], char name_[],int j); //查找某个医生
void D_All_Inf(Doctor Doc[], int j); //查看所有医生信息
void D_Save_File(Doctor Doc[], int j); //保存至文件
~Doctor(){}
//
char Dname[10];
char Specialty[10]; //医生科室(儿科,内科等)
double Fees; //诊费
};
class Patient : public Person //患者
{
public:
Patient(){}
Patient(const char *_Name, const char *_Sex, const char *_Address, int _Age, double _Medicine_Fee);
void Print();
void P_Add();
int P_Select(Patient Pat[], char name_[],int j);
void P_All_Inf(Patient Pat[], int j);
void P_Save_File(Patient Pat[], int j);
~Patient(){}
double Medicine_Fee;//药费
};
class Bill : public Patient, public Doctor //清单
{
public:
Bill(){}
Bill(const char *_Name, const char *_Sex, const char *_Address, int _Age, double _Medicine_Fee,
const char *_Dname, const char *_Specialty, double _Fees);
void Print();
void B_Add();
int B_Select(Bill Bil[], char name_[],int j);
void B_All_Inf(Bill Bil[], int j);
void B_Save_File(Bill Bil[], int j);
//void B_Read_File(Bill Bil[]);
double NumMoney(Bill Pat[], int j);
~Bill(){}
};
Person::Person(const char *_Name, const char *_Sex, const char *_Address, int _Age)
{
strcpy(Name, _Name);
strcpy(Sex, _Sex);
strcpy(Address, _Address);
Age = _Age;
}
Doctor::Doctor(const char *_Dname, const char *_Specialty, double _Fees)
{
strcpy(Dname, _Dname);
strcpy(Specialty, _Specialty);
Fees = _Fees;
}
Patient::Patient(const char *_Name, const char *_Sex, const char *_Address, int _Age, double _Medicine_Fee)
:Person(_Name, _Sex, _Address, _Age)
{
Medicine_Fee = _Medicine_Fee;
}
Bill::Bill(const char *_Name, const char *_Sex, const char *_Address, int _Age,
double _Medicine_Fee,
const char *_Dname, const char *_Specialty, double _Fees)
: Patient(_Name, _Sex, _Address, _Age, _Medicine_Fee), Doctor(_Dname, _Specialty, _Fees)
{
}
void Person::Print()
{
cout << "患者的姓名是:" << Name << endl;
cout << "患者的性别是:" << Sex << endl;
cout << "患者的家庭住址是:" << Address << endl;
cout << "患者的年龄是:" << Age << endl;
}
void Doctor::Print()
{
cout << "医生的姓名是:" << Dname << endl;
cout << "医生的科室是:" << Specialty << endl;
cout << "医生的诊费是:" << Fees << endl;
cout << "---------------------------" << endl;
}
void Patient::Print()
{
Person::Print();
cout << "患者的医药费是:" << Medicine_Fee << endl;
}
void Bill::Print()
{
Patient::Print();
Doctor::Print();
}
void Doctor::D_Add()
{
cout << "请输入医生姓名:";
cin >> Dname;
cout << "请输入医生科室:";
cin >> Specialty;
cout << "请输入医生诊费:";
cin >> Fees;
}
int Doctor::D_Select(Doctor Doc[], char name_[], int j)
{
int i = 0;
while (strcmp(name_, Doc[i].Dname) != 0)
{
i++;
if (i >= j)
{
return 0;
}
}
return i;
}
void Doctor::D_Save_File(Doctor Doc[], int j)
{
fstream outfile;
outfile.open("Doctor.txt", ios::out);
if (!outfile)
{
cout << "文件打开失败!";
abort(); //退出程序
}
for (int i = 0; i < j; i++)
{
outfile << Doc[i].Dname << " ";
outfile << Doc[i].Specialty << " ";
outfile << Doc[i].Fees << endl;
}
outfile.close();
}
void Doctor::D_All_Inf(Doctor Doc[], int j)
{
for (int i = 0; i<j; i++)
{
Doc[i].Print();
}
}
void Patient::P_Add()
{
cout << "请输入患者姓名:";
cin >> Name;
cout << "请输入患者性别:";
cin >> Sex;
cout << "请输入患者家庭住址:";
cin >> Address;
cout << "请输入患者年龄:";
cin >> Age;
cout << "请输入患者医药费:";
cin >> Medicine_Fee;
}
int Patient::P_Select(Patient Pat[], char name_[],int j)
{
int i = 0;
while (strcmp(name_, Pat[i].Name) != 0)
{
i++;
if (i >= j)
{
return 0;
}
}
return i;
}
void Patient::P_All_Inf(Patient Pat[], int j)
{
for (int i = 0; i<j; i++)
{
Pat[i].Print();
cout << "---------------------------" << endl;
}
}
void Patient::P_Save_File(Patient Pat[], int j)
{
fstream outfile;
outfile.open("Patient.txt", ios::out);
if (!outfile)
{
cout << "文件打开失败!";
abort(); //退出程序
}
for (int i = 0; i < j; i++)
{
outfile << Pat[i].Name << " ";
outfile << Pat[i].Sex << " ";
outfile << Pat[i].Address << " ";
outfile << Pat[i].Age << " ";
outfile << Pat[i].Medicine_Fee << endl;
}
outfile.close();
}
double Bill::NumMoney(Bill Bil[], int j)
{
double sum = 0.0;
for (int i = 0; i<j; i++)
{
sum = sum + Bil[i].Medicine_Fee + Bil[i].Fees;
}
return sum;
}
void Bill::B_Add()
{
Patient::P_Add();
Doctor::D_Add();
}
int Bill::B_Select(Bill Bil[], char name_[],int j)
{
int i = 0;
while (strcmp(name_, Bil[i].Name) != 0)
{
i++;
if (i >= j)
{
return 0;
}
}
return i;
}
void Bill::B_All_Inf(Bill Bil[], int j)
{
for (int i = 0; i<j; i++)
{
Bil[i].Print();
}
}
void Bill::B_Save_File(Bill Bil[], int j)
{
fstream outfile;
outfile.open("Bill.txt", ios::out);
if (!outfile)
{
cout << "文件打开失败!";
abort(); //退出程序
}
for (int i = 0; i < j; i++)
{
outfile << Bil[i].Name << " ";
outfile << Bil[i].Sex << " ";
outfile << Bil[i].Address << " ";
outfile << Bil[i].Age << " ";
outfile << Bil[i].Medicine_Fee << " ";
outfile << Bil[i].Dname << " ";
outfile << Bil[i].Specialty << " ";
outfile << Bil[i].Fees << endl;
}
outfile.close();
}
void menu()
{
system("cls");
cout << "***************************" << endl;
cout << "1.医生操作" << endl;
cout << "2.患者操作" << endl;
cout << "3.患者清单操作" << endl;
cout << "0.结束程序" << endl;
cout << "***************************" << endl;
}
void Dmenu()
{
system("cls");
cout << "***************************" << endl;
cout << "1.查询所有的医生信息" << endl;
cout << "2.按名查找医生" << endl;
cout << "3.增加医生" << endl;
cout << "4.返回上一层" << endl;
cout << "***************************" << endl;
}
void Pmenu()
{
system("cls");
cout << "***************************" << endl;
cout << "1.查询所有的患者信息" << endl;
cout << "2.按名查找患者" << endl;
cout << "3.增加患者" << endl;
cout << "4.返回上一层" << endl;
cout << "***************************" << endl;
}
void Bmenu()
{
system("cls");
cout << "***************************" << endl;
cout << "1.查询所有的患者清单" << endl;
cout << "2.查找某个患者清单" << endl;
cout << "3.增加清单" << endl;
cout << "4.计算所有患者的总费用" << endl;
cout << "5.返回上一层" << endl;
cout << "***************************" << endl;
}
int main()
{
int n; //用来选择的变量
int i = 5, j = 5, z = 5; //医生、患者、清单的总数
char name_[10];
Doctor Doc[N] = { { "张三", "内科", 5 },
{ "李四", "外科", 20 },
{ "王五", "眼科", 6 },
{ "华佗", "全科", 100 },
{ "张仲景", "妇科", 50 } };
Patient Pat[N] = { { "赵信", "男", "山西", 18, 200.5 },
{ "李二狗", "男", "陕西", 45, 1000.8 },
{ "赵灵芝", "女", "浙江", 30, 563.5 },
{ "王麻子", "男", "新疆", 24, 50.0 },
{ "瑞文", "女", "上海", 17, 108.4 } };
Bill Bil[N] = { { "赵信", "男", "山西", 18, 200.5, "张三", "内科", 5 },
{ "李二狗", "男", "陕西", 45, 1000.8, "李四", "外科", 20 },
{ "赵灵芝", "女", "浙江", 30, 563.5, "张仲景", "妇科", 50 },
{ "王麻子", "男", "新疆", 24, 50.0, "王五", "眼科", 6 },
{ "瑞文", "女", "上海", 17, 108.4, "张仲景", "妇科", 50 } };
while (1)
{
menu();
cout << "请输入你的操作:";
cin >> n;
switch (n)
{
case 1:{
while (1)
{
Dmenu();
cout << "请输入你的操作:";
cin >> n;
switch (n)
{
case 1:{
Doc[1].D_All_Inf(Doc, i); //查询所有医生信息
system("pause");
}break;
case 2:{
cout << "请输入医生的姓名:";
cin >> name_;
if (Doc[1].D_Select(Doc, name_, i) == 0)
{
printf("无该医生!\n");
}
else
{
Doc[Doc[1].D_Select(Doc, name_, i)].Print(); //查找某个医生信息
}
system("pause");
}break;
case 3:{
Doc[i].D_Add();//增加医生
i++;
}break;
case 4:{
}break;
default:
cout << "输入错误!请重新输入!" << endl;
Sleep(500);
break;
}//end switch
if (n == 4)
break;
}//end while
}break;
case 2:{
while (1)
{
Pmenu();
cout << "请输入你的操作:";
cin >> n;
switch (n)
{
case 1:{
Pat[1].P_All_Inf(Pat, j); //查询所有患者信息
system("pause");
}break;
case 2:{
cout << "请输入患者的姓名:";
cin >> name_;
if (Pat[1].P_Select(Pat, name_, j) == 0)
{
printf("无该患者!\n");
}
else
{
Pat[Pat[1].P_Select(Pat, name_, j)].Print(); //查找某个患者信息
}
system("pause");
}break;
case 3:{
Pat[j].P_Add(); //增加患者
j++;
}break;
case 4:{
}break;
default:
cout << "输入错误!请重新输入!" << endl;
Sleep(500);
break;
}//end switch
if (n == 4)
break;
}//end while
}break;
case 3:{
while (1)
{
Bmenu();
cout << "请输入你的操作:";
cin >> n;
switch (n)
{
case 1:{
//Bil[1].B_Read_File(Bil);
Bil[1].B_All_Inf(Bil, z); //查询所有患者清单信息
system("pause");
}break;
case 2:{
cout << "请输入患者的姓名:";
cin >> name_;
if (Bil[1].B_Select(Bil, name_, z) == 0)
{
printf("无该患者清单!\n");
}
else
{
Bil[Bil[1].B_Select(Bil, name_, z)].Print(); //查找某个患者清单信息
}
system("pause");
}break;
case 3:{
Bil[z].B_Add();//增加患者清单
z++;
}break;
case 4:{
cout << Bil[1].NumMoney(Bil, z) << endl;
system("pause");
}break;
case 5:{
}break;
default:
cout << "输入错误!请重新输入!" << endl;
Sleep(500);
break;
}//end switch
if (n == 5)
break;
}//end while
}break;
case 0:{
}break;
default:
cout << "输入错误!请重新输入!" << endl;
Sleep(500);
break;
}//end switch
if (n == 0)
break;
}//end while
Doc[1].D_Save_File(Doc, i); //将信息保存到文件中
Pat[1].P_Save_File(Pat, j);
Bil[1].B_Save_File(Bil, z);
return 0;
}
诊所管理系统
最新推荐文章于 2024-07-25 09:28:53 发布