0% found this document useful (0 votes)
45 views4 pages

Q2:Write A Program Using Friend Class. Class Names: 1-Blood - Pressure (Upper, Lower) 2-Patient (Name, BP)

This document contains C++ code to define two classes - patient and blood_pressure - to store patient name, blood pressure readings, and determine if the readings are normal. The patient class stores name and bp readings, while blood_pressure stores upper and lower bp limits. The blood_pressure class is defined as a friend of patient to access private variables. The main function creates objects, gets input, and displays output.

Uploaded by

Ali Nawaz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views4 pages

Q2:Write A Program Using Friend Class. Class Names: 1-Blood - Pressure (Upper, Lower) 2-Patient (Name, BP)

This document contains C++ code to define two classes - patient and blood_pressure - to store patient name, blood pressure readings, and determine if the readings are normal. The patient class stores name and bp readings, while blood_pressure stores upper and lower bp limits. The blood_pressure class is defined as a friend of patient to access private variables. The main function creates objects, gets input, and displays output.

Uploaded by

Ali Nawaz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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;

You might also like