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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
#include <iostream>
#include <cstdio>
#include <cstring>
constexpr size_t MAX_STR { 50 };
class Name {
char* fname {};
char* Lname {};
public:
Name() : fname(new char[MAX_STR]), Lname(new char[MAX_STR]) {}
Name(const char *fN, const char *IN) : Name() {
setfn(fN);
setIn(IN);
}
~Name() {
delete[] fname;
delete[] Lname;
}
Name(const Name& obj) : Name(obj.fname, obj.Lname) {}
Name& operator=(const Name& rhs) {
setfn(rhs.fname);
setfn(rhs.Lname);
}
void setfn(const char* fN) {
std::snprintf(fname, MAX_STR, "%s", fN);
}
void setIn(const char* IN) {
std::snprintf(Lname, MAX_STR, "%s", IN);
}
char* getfn() const {
return fname;
}
char* getIn() const {
return Lname;
}
friend std::ostream& operator<<(std::ostream& out, const Name& n);
};
std::ostream& operator<<(std::ostream& out, const Name& n) {
return out << n.fname << ' ' << n.Lname;
}
class Date {
unsigned day {}, month {}, year {};
public:
Date() {}
Date(unsigned d, unsigned m, unsigned y) : year(y) {
if (m > 0 && m < 13) {
month = m;
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
day = (d > 0 && d < 32) ? d : 0;
else if (m == 2)
day = (d > 0 && d < 29) ? d : 0;
else
day = (d > 0 && d < 31) ? d : 0;
} else
month = 0;
}
bool setd(unsigned d) {
if (d > 0 && d < 32) {
day = d;
return true;
}
return false;
}
bool setm(unsigned m) {
if (m > 0 && m < 13) {
month = m;
return true;
}
return false;
}
void sety(unsigned y) {
year = y;
}
unsigned getd() const {
return day;
}
unsigned getm() const {
return month;
}
unsigned gety() const {
return year;
}
friend std::ostream& operator<<(std::ostream& out, const Date& d);
};
std::ostream& operator<<(std::ostream& out, const Date& d) {
return out << d.day << '/' << d.month << '/' << d.year;
}
class mTime {
unsigned hour {}, min {}, sec {};
public:
mTime() {}
mTime(unsigned h, unsigned m, unsigned s) : hour(h), min(m), sec(s) {}
bool seth(unsigned h) {
if (h >= 0 && h < 24) {
hour = h;
return true;
}
return false;
}
bool setm(unsigned m) {
if (m >= 0 && m < 61) {
min = m;
return true;
}
return false;
}
bool sets(unsigned s) {
if (s >= 0 && s < 61) {
sec = s;
return true;
}
return false;
}
unsigned geth() const {
return hour;
}
unsigned getm() const {
return min;
}
unsigned gets() const {
return sec;
}
friend std::ostream& operator<<(std::ostream& out, const mTime& m1);
};
std::ostream& operator<<(std::ostream& out, const mTime& m1) {
return out << m1.hour << ':' << m1.min << ':' << m1.sec;
}
class Service {
char *source {}, *destination {};
float distance {};
Date bookingDate;
mTime bookingtime;
bool status {};
float fuelrate {};
int cID {}, dID {}, vID {};
};
class Person {
protected:
Name pName;
Date DOB;
unsigned age {}, Nid {};
public:
Person() {}
Person(Name n, Date d, unsigned a, unsigned id) : pName(n), DOB(d), age(a), Nid(id) {}
Person(const Person& obj) : Person(obj.pName, obj.DOB, obj.age, obj.Nid) {}
void setN(const Name& n) {
pName = n;
}
void setdob(const Date& d) {
DOB = d;
}
void setage(unsigned a) {
age = a;
}
void setid(unsigned id) {
Nid = id;
}
unsigned getage() const {
return age;
}
unsigned getid() const {
return Nid;
}
Name getn() const {
return pName;
}
Date getdob() const {
return DOB;
}
friend std::ostream& operator<<(std::ostream out, const Person& p1);
};
std::ostream& operator<<(std::ostream out, const Person& p1) {
return out << "Name of Person is " << p1.pName << "\nDate of birth is " << p1.DOB << "\nAge is: " << p1.age << "\nID is " << p1.Nid;
}
class Customer : public Person {
int cId {};
Service **bookingHistory;
public:
using Person::Person;
Customer() {}
Customer(const Name& p, const Date& dob, unsigned a, unsigned id, unsigned cid, Service** bH) : Person(p, dob, a, id), cId(cid), bookingHistory(bH) {}
~Customer() { }
Customer(const Customer& b1) : Person(b1.pName, b1.DOB, b1.age, b1.Nid), cId(b1.cId), bookingHistory(b1.bookingHistory) {}
void setcusid(unsigned a) {
cId = a;
}
void setbookinghis(Service** bh) {
bookingHistory = bh;
}
unsigned getcusid() const {
return cId;
}
Service** getbookinghis() const {
return bookingHistory;
}
friend std::ostream& operator <<(std::ostream& out, const Customer&);
};
std::ostream& operator <<(std::ostream& out, const Customer& b1) {
return out << "Customer ID is: " << b1.cId;
}
int main() {
Customer cust(Name("Ali", "Baabaa"), Date(23, 05, 2001), 1, 1, 1, nullptr);
//Person *aptr = &cust;
std::cout << cust.getcusid() << '\n' << cust.getn() << '\n' << cust.getdob() << '\n';
}
|