//設計人類(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;
}
診所管理系統
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.