Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. class Person{
  7.     protected:
  8.         string name;
  9.     public:
  10.         Person() {name ="";}
  11.         void setName(string n) {name = n;}
  12.         void print() const {}
  13. };
  14.  
  15. class Doctor : public Person{
  16.    
  17.     private:
  18.         string department;
  19.     public:
  20.         Doctor(){department ="";}
  21.         void setDepartment(string d) {department = d;}
  22.        
  23.        
  24.         void print() const
  25.         {
  26.             cout <<"Doctor in-charged" << endl
  27.                  <<"============= " << endl
  28.                  <<"Doctor’s Name : " << name << endl
  29.                  <<"Department : " << department << endl;
  30.                  
  31.         }
  32. };
  33.  
  34. class Ward{
  35.    
  36.     private:
  37.         string roomNo;
  38.     public:
  39.         Ward() {roomNo = ""; }
  40.         void setRoomNo(string no) {roomNo = no;}
  41.         string getRoomNo() const {return roomNo;}
  42. };
  43.  
  44. class Patient : public Person
  45. {
  46.     private:
  47.         string disease;
  48.         Doctor* doctor;
  49.         Ward* ward;
  50.     public:
  51.         Patient(){disease ="";}
  52.        
  53.         void setDisease(string d){ disease = d; }
  54.        
  55.         void setDoctor (Doctor* d) { doctor = d;}
  56.        
  57.         void setWard (Ward* w) {ward = w;}
  58.        
  59.         void print() const
  60.         {
  61.             cout << "Patient’s Name : " << name << endl
  62.                  << "Disease : " << disease << endl
  63.                  << "Ward No :" << ward -> getRoomNo() << endl ;
  64.                  doctor->print(); //Using pointer
  65.         }
  66.         void print (int seqNo)
  67.         {
  68.             cout << "Patient No. " << seqNo << endl;
  69.             print();           
  70.         }
  71. };
  72.  
  73.  
  74. int main ()
  75. {
  76.     int count;
  77.     Patient p_list [100];
  78.     string name, dis, wardno , doc_name , dep;
  79.     Ward local_ward;
  80.     Doctor local_doc;
  81.    
  82.    
  83.    
  84.     cout << "How many patients to enter? => " ;
  85.     cin >> count;
  86.     cin.ignore();
  87.     cout<<endl;
  88.    
  89.     for (int i = 0 ; i <count ; i++)
  90.     {
  91.  
  92.        
  93.         cout <<"Enter the following information: " << endl;
  94.        
  95.         cout <<"Patient's Name => ";
  96.  
  97.         getline(cin, name);
  98.         p_list[i].setName(name);
  99.        
  100.         cout <<"Disease => ";
  101.         getline(cin, dis);
  102.         p_list[i].setDisease(dis);
  103.        
  104.         cout <<"Ward No =>";
  105.         getline(cin, wardno);
  106.         local_ward.setRoomNo(wardno);
  107.         p_list[i].setWard(&local_ward);
  108.        
  109.         cout <<"Doctor's Name => ";
  110.         getline(cin, doc_name);
  111.         local_doc.setName(doc_name);
  112.        
  113.         cout <<"Department =>  ";
  114.         getline(cin, dep);
  115.         local_doc.setDepartment(dep);
  116.  
  117.        
  118.         p_list[i].setDoctor(&local_doc);
  119.        
  120.        
  121.         cout << endl << endl;      
  122.        
  123.        
  124.     }
  125.    
  126.    
  127.     for (int i=0; i<count; i++)
  128.     {
  129.         p_list[i].print(i+1);
  130.         cout << endl << endl;
  131.     }
  132.     return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement