1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
// Hi, I have a question regarding OOP. can someone guide me how to do number
// 4 b, c, d? since this is my first exercise on OOP. I do not really master
// the subject
// 1. Create a class named Staff with at least the following data members (id,
// name, birthdate, education, certification, address, and main language,).
// 2. Design a proper Address class that stores and manipulates the address
// elements.
// 3. The Hospital class must have at least the following members (Name as a
// std::string, Address as an Address object, phone, fax, e-mail, an array of
// departments, and any fields you feel necessary)
// 4. The Department class has at least the following members (name, an array
// of Staff, number of staff, and any number of data fields you find
// necessary).
// 5. In the main function:
// a. Create 7 Address objects and initialize them with some data.
// b. Create 6 objects of Staff and initialize them with data of your choice.
// Add an address object to each staff object created.
// c. Create 2 department objects.
// Add the first 3 Staff objects to the first department object and the
// last three to the second department.
// d. Create an object of type Hospital.
// Initialize the address of the hospital to the 7th address.
// Add the two departments to the hospital.
// e. Display all the components you created with proper functions and
// messages.
#include <iostream>
#include <memory>
#include <vector>
class Address
{
public :
Address();
Address(const std::string& a_num,
const std::string& a_street,
const std::string& a_city,
const std::string& a_state,
const std::string& a_postcode,
const std::string& a_country)
: num (a_num)
, street (a_street)
, city (a_city)
, state (a_state)
, postcode (a_postcode)
, country (a_country)
{
}
std::string getNum() const {return num;}
std::string getStreet() const {return street;}
std::string getCity() const {return city;}
std::string getState() const {return state;}
std::string getPostcode() const {return postcode;}
std::string getCountry() const {return country;}
private :
std::string num;
std::string street;
std::string city;
std::string state;
std::string postcode;
std::string country;
};
class Staff
{
public :
Staff();
Staff(const std::string& s_id,
const std::string& s_date,
const std::string& s_name,
const std::string& s_edu,
const std::string& s_cert,
const std::string& s_add,
const std::string& s_lang)
: id (s_id)
, bdate (s_date)
, name (s_name)
, edu (s_edu)
, cert (s_cert)
, add (s_add)
, lang (s_lang)
{
}
std::string getID() const { return id; }
std::string getDate () const { return bdate; }
std::string getName() const { return name; }
std::string getEdu() const { return edu; }
std::string getCert() const { return cert; }
std::string getAdd() const { return add; }
std::string getLang() const { return lang; }
private :
std::string id;
std::string bdate;
std::string name;
std::string edu;
std::string cert;
std::string add; // Are you sure this is not required to be an Address?
std::string lang;
};
class Department
{
public :
Department() = default;
Department(const std::string& d_name)
: name (d_name)
{
}
Department(const std::string& d_name, const std::vector<Staff>& personal)
: name(d_name)
, staff(personal)
{
}
void add_staff_member(const Staff& staff_member);
std::string getName() const { return name; }
int getNumOfStaff() const { return staff.size(); }
private :
std::string name;
std::vector<Staff> staff;
};
class Hospital
{
public :
Hospital();
Hospital(const std::string& h_name,
const std::string& h_phone,
const std::string& h_email)
: name (h_name)
, phone (h_phone)
, email (h_email)
{
}
Hospital(const std::string& h_name,
const std::string& h_phone,
const std::string& h_email,
const std::vector<Address>& personal,
const std::vector<Department>& personal)
: name (h_name)
, phone (h_phone)
, email (h_email)
, address (personal)
, department (personal)
{
}
std::string getHName();
std::string getPhone();
std::string getEmail();
~Hospital();
private :
std::string name;
std::vector<Address> address;
std::vector<Department> department;
std::string phone;
std::string email;
};
int main ()
{
std::unique_ptr<Address[]>addObj = std::make_unique<Address[]>(7);
addObj[0].setAdd("1", "AA", "TALL", "SL", "24000", "CHINA");
addObj[1].setAdd("2", "BB", "LONG", "MZ", "25000", "CAMBODIA");
addObj[2].setAdd("3", "CC", "BONE", "SL", "33000", "MANILA");
addObj[3].setAdd("4", "DD", "LEGS", "PR", "55000", "PARIS");
addObj[4].setAdd("5", "EE", "HAND", "SL", "77000", "USA");
addObj[5].setAdd("6", "FF", "HEAD", "MK", "89000", "UK");
addObj[6].setAdd("7", "GG", "NAIL", "SL", "70000", "KOREA");
for(int i = 0; i < 7; i++)
{
std::cout << addObj[i].getNum() << ", "
<< addObj[i].getStreet() << ", "
<< addObj[i].getCity() << ", "
<< addObj[i].getState() << ", "
<< addObj[i].getPostcode() << ", "
<< addObj[i].getCountry() << '\n';
}
std::cout << '\n';
std::unique_ptr<Staff[]>staffObj = std::make_unique<Staff[]>(6);
std::unique_ptr<Department[]>deptObj = std::make_unique<Department[]>(2);
std::shared_ptr<Hospital>objHosp = std::make_shared<Hospital>();
}
|