Vous êtes sur la page 1sur 4

Q2 :Write a program using friend class.

Class names: 1-blood_pressure(upper,lower) 2-patient(name,bp)

#include<conio.h> #include<iostream> using namespace std; class blood_pressure; class patient { private: char*name[]; int bp; public: friend class blood_pressure; patient(char*nname[],int bbp) { *name[]=*nname[]; bp=bbp; } ~patient(); void getinfo() { cin>>*nname[];

cin>>bbp; } void displayinfo() { cout<<*nname[]; cout<<bbp; } }; class blood_pressure { private: int upper; int lower; public: friend class patient; blood_pressure(int uupper,int llower) { upper=uupper; lower=llower; } ~blood_pressure(); void getinfo1() { cin>>uupper; cin>>llower;

} void displayinfo1() { cout<<uupper; cout<<llower; if(uupper==120&&llower==80) { cout<<"bp is normal"<<endl; } else cout<<"bp is not normal"<<endl; } }; int main() { patient patient1("ali"); patient patient2(120/80); patient1.displayinfo(); patient2.displayinfo(); blood_pressure bp1(180); blood_pressure bp2(120); bp1.displayinfo1(); bp2.displayinfo1(); getch(); return 0;

Vous aimerez peut-être aussi