怎样修改这个程序????

程序如下:就是怎样可以实现以下功能;
设计人类(Person类)和医生类(Doctor类),在此基础上,通过增加患者和账单,使它们公用于表示一家诊所的信息管理。
(1)在一条医生记录中,包括医生的专业说明(specialty),如内科医生(surgeon)、儿科医生(pediatrician) 、产科医生(obstetrician)及全科医生(general practitioner)。
(2)Doctor记录还含有诊费(office_vist_fee)。
(3)在一条患者记录中,包括该患者产生的药费(drug_fee) ,患者的诊费(即医生的诊费)。
(4)在一条账单记录中,包括一条患者对象、该患者对应得主治医生、该患者产生的诊费和药费。
(5)应用程序能够显示出诊所中每个患者的信息和对应主治医生的信息。
(6)能够统计出所有患者的总费用。

yiyxiai

#include<iostream>
#include<string>
using namespace std;
class Person{                      //人类 
    public:
        Person(string name1,string sex1,int age1,double office_vist_fee1):name(name1),sex(sex1),age(age1),office_vist_fee(office_vist_fee1)
        { 
        }
        void show()
        {cout<<"姓名:"<<name<<endl;
         cout<<"性别:"<<sex<<endl;
         cout<<"年龄:"<<age<<endl;
         cout<<"诊费:"<<office_vist_fee<<endl; 
         } 
    protected:
        string name;
        string sex;
        int age;
        double office_vist_fee;    //诊费 
};
class Doctor:public Person{        //医生类 
    public:
        Doctor(string name1,string sex1,int age1,double office_vist_fee1,string spe):Person(name1,sex1,age1,office_vist_fee1)
        {specialty=spe;            //spe为医生的专业说明 
        }
        void input()         //增加医生信息 
        {cout<<endl;
         /*cout<<"姓名:";
         cout<<"性别:";
         cout<<"年龄:";
         cout<<"诊费:";*/ 
         cout<<"主治病例:"<<specialty<<endl; 
        }
        countkind()    //按姓名查询患者信息 
        {char na;
         cout<<"请输入要查询的医生姓名:";
          {
            if(na==name)
                {cout<<"姓名:"<<name<<endl;
                 cout<<"性别:"<<sex<<endl;
                 cout<<"年龄:"<<age<<endl;
                 cout<<"诊费:"<<office_vist_fee<<endl;//诊费 
                 cout<<"病例:"<<specialty<<endl;}            //主治病例
            else
                cout<<"查询信息错误!"<<endl; 
        }}
    protected:
        string specialty;
};
class Patient:public Person{      //患者类 
    public:
        Patient(string name1,string sex1,int age1,double office_vist_fee1,double drug_fee1):Person(name1,sex1,age1,office_vist_fee1)
        {drug_fee=drug_fee1;       
        }
        input()           //增加患者信息 
        {cout<<endl;
         /*cout<<"姓名:";
         cout<<"性别:";
         cout<<"年龄:";
         cout<<"诊费:";*/ 
         cout<<"药费:"<<drug_fee<<endl; 
        }
        countkind()       //按姓名查询患者信息 
        {char na; 
         cout<<"请输入患者的姓名:"<<na<<endl;
         if(na==name)
            {cout<<"姓名:"<<name<<endl;
             cout<<"性别:"<<sex<<endl;
             cout<<"年龄:"<<age<<endl;
             cout<<"诊费:"<<office_vist_fee<<endl;
             cout<<"药费:"<<drug_fee<<endl;}
         else                                              
           cout<<"查询信息错误!"<<endl;  
        }
    protected:
        double drug_fee;
};
class Count:public Doctor,public Patient{                       //Count为账单类 
    public:
        Count(string name1,string sex1,int age1,double drug_fee1,double office_vist_fee1,double total_fee1):Doctor(name1,sex1,age1,office_vist_fee1/*,spe*/),Patient(name1,sex1,age1,office_vist_fee1,drug_fee1)
        {total_fee=total_fee1;
        }
        void total_pay()                          //总的费用 
        {cout<<total_fee<<'='<<office_vist_fee<<'+'<<drug_fee<<endl;
        }
        void show()
        {cout<<"patient.name"<<name<<endl;
         cout<<"patient.sex"<<sex<<endl;
         cout<<"patient.age"<<age<<endl;
         cout<<"patient.drug_fee"<<drug_fee<<endl;
         cout<<"patient.office_vist_fee"<<office_vist_fee<<endl;
         cout<<"patient.total_fee"<<total_fee<<endl;
         
        }
    protected:
        string name;
        string sex;
        int age;     
        double drug_fee;          
        double office_vist_fee;
        double total_fee;     
};
int main()
{
    Doctor do1("扁鹊","男",24,110,"神经科");
    Doctor do2("华佗","男",25,111,"精神病");
    Doctor do3("小乔","女",23,112,"相思病"); 
    Patient pa1("鲁班","男",21,100,10);
    Patient pa2("赵云","男",22,100,11);
    Patient pa3("周瑜","男",23,100,12);
    Count C1;
    C1.show; 
    return 0; 
}
阅读 3.1k
1 个回答

所有患者的总费用这里没有写出来,加一个static的成员就好了

/* clinic.h */
#include <iostream>
using namespace std;

class Person    // 人类
{
public:
    Person(string name1, string sex1):name(name1), sex(sex1){}
    void show() const;
protected:
    string name;
    string sex;
};

class Doctor:public Person        // 医生类
{
public:
    Doctor(string name, string sex, string spec, double fee):Person(name, sex), specialty(spec), office_vist_fee(fee){}
    void show() const;
    double get_office_vist_fee() const;
private:
    string specialty;
    double office_vist_fee;
};

class Patient:public Person        // 病人类
{
public:
    Patient(string name, string sex, double drug, Doctor &d):Person(name, sex), drug_fee(drug), doctor(d)
    {
        all_fee = 0;
    }
    void show() const;
    void set_fee();        // 计算总费用
private:
    double drug_fee;
    Doctor doctor;        // 医生类的对象
    double all_fee;        // 总费用
};

class Bill        // 账单类
{
public:
    Bill(Patient &p, Doctor &d):patient(p), doctor(d)
    {
        patient.set_fee();
    }
    void show() const;
private:
    Patient patient;    // 病人类的对象
    Doctor doctor;        // 医生类的对象
};


#include <iostream>
#include "clinic.h"
using namespace std;

void Person::show() const
{
    cout << "name:" << name << " sex:" << sex << endl;
}

void Doctor::show() const
{
    Person::show();
    cout << "              specialty:" << specialty << " office_vist_fee:" << office_vist_fee << endl;
}

double Doctor::get_office_vist_fee() const        // 获取医生的诊费
{
    return office_vist_fee;
}

void Patient::show() const
{
    cout << "患者信息:";
    Person::show();
    cout << "主治医师信息:";
    doctor.show();
    cout << "all fee:" << all_fee << endl;
}

void Patient::set_fee()
{
    all_fee += drug_fee;
    all_fee += doctor.get_office_vist_fee();
}

void Bill::show() const
{
    patient.show();
}

int main()
{
    Doctor d1("扁鹊", "男", "内科医生", 1500);
    Doctor d2("华佗", "男", "妇科医生", 2000);
    Patient p1("关羽", "男", 500, d1);
    Patient p2("小乔", "女", 600, d2);

    Bill b1(p1, d1);
    b1.show();
    Bill b2(p2, d2);
    b2.show();

    return 0;
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题