// Hospital.cpp : 定义控制台应用程序的入口点。
//
#include <iostream>
#include <string.h>
using namespace std;
class Patient;
class Doctor
{
public:
static void Heal(Patient& pp);
Doctor(char* name){
strcpy(this->name,name);
cout<<"Doctor:\t"<<this->name<<endl;
}
private:
char name[20];
};
class Patient
{
public:
friend class Doctor;
Patient(char* name,int pa);
//void Heal(int paa=75);
void print();
protected:
char name[20];
static int total;
char heal[20];
int pa;
};
Patient::Patient(char* name,int pa = 80){
strcpy(this->name,name);
this->pa = pa;
}
void Patient::print(){
total++;
cout<<this->name<<"\t"<<this->pa<<"\t"<<this->heal<<endl;;
}
void Doctor::Heal(Patient& pp){
if(pp.pa>=70 && pp.pa<=130){
//cout<<pp.name<<":normal"<<endl;
strcpy(pp.heal,"normal");
}
else if((pp.pa>=50 && pp.pa<=69)||(pp.pa>=131 && pp.pa<=150)){
//cout<<pp.name<<":Heal"<<endl;
strcpy(pp.heal,"medicine");
}
else
{
//cout<<pp.name<<":be in hospital"<<endl;
strcpy(pp.heal,"hospital");
}
}
int Patient::total = 0;
int main()
{
Doctor dc("Hanson");
Patient p1("Tom",155);
Patient p2("John",145);
Patient p3("Sean");
dc.Heal(p1);
dc.Heal(p2);
dc.Heal(p3);
p1.print();
p2.print();
p3.print();
return 0;
}
友元类的使用
最新推荐文章于 2024-06-20 09:00:44 发布