Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Person{
- protected:
- string name;
- public:
- Person() {name ="";}
- void setName(string n) {name = n;}
- void print() const {}
- };
- class Doctor : public Person{
- private:
- string department;
- public:
- Doctor(){department ="";}
- void setDepartment(string d) {department = d;}
- void print() const
- {
- cout <<"Doctor in-charged" << endl
- <<"============= " << endl
- <<"Doctor’s Name : " << name << endl
- <<"Department : " << department << endl;
- }
- };
- class Ward{
- private:
- string roomNo;
- public:
- Ward() {roomNo = ""; }
- void setRoomNo(string no) {roomNo = no;}
- string getRoomNo() const {return roomNo;}
- };
- class Patient : public Person
- {
- private:
- string disease;
- Doctor* doctor;
- Ward* ward;
- public:
- Patient(){disease ="";}
- void setDisease(string d){ disease = d; }
- void setDoctor (Doctor* d) { doctor = d;}
- void setWard (Ward* w) {ward = w;}
- void print() const
- {
- cout << "Patient’s Name : " << name << endl
- << "Disease : " << disease << endl
- << "Ward No :" << ward -> getRoomNo() << endl ;
- doctor->print(); //Using pointer
- }
- void print (int seqNo)
- {
- cout << "Patient No. " << seqNo << endl;
- print();
- }
- };
- int main ()
- {
- int count;
- Patient p_list [100];
- string name, dis, wardno , doc_name , dep;
- Ward local_ward;
- Doctor local_doc;
- cout << "How many patients to enter? => " ;
- cin >> count;
- cin.ignore();
- cout<<endl;
- for (int i = 0 ; i <count ; i++)
- {
- cout <<"Enter the following information: " << endl;
- cout <<"Patient's Name => ";
- getline(cin, name);
- p_list[i].setName(name);
- cout <<"Disease => ";
- getline(cin, dis);
- p_list[i].setDisease(dis);
- cout <<"Ward No =>";
- getline(cin, wardno);
- local_ward.setRoomNo(wardno);
- p_list[i].setWard(&local_ward);
- cout <<"Doctor's Name => ";
- getline(cin, doc_name);
- local_doc.setName(doc_name);
- cout <<"Department => ";
- getline(cin, dep);
- local_doc.setDepartment(dep);
- p_list[i].setDoctor(&local_doc);
- cout << endl << endl;
- }
- for (int i=0; i<count; i++)
- {
- p_list[i].print(i+1);
- cout << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement