SHOW:
|
|
- or go back to the newest paste.
| 1 | // ConsoleApplication92.cpp : Defines the entry point for the console application. | |
| 2 | // | |
| 3 | ||
| 4 | #include "stdafx.h" | |
| 5 | #include<iostream> | |
| 6 | #include<string.h> | |
| 7 | #include<assert.h> | |
| 8 | using namespace std; | |
| 9 | ||
| 10 | ||
| 11 | ||
| 12 | class Person | |
| 13 | {
| |
| 14 | public: | |
| 15 | Person(const char* na = "", const char da[9] = ""); | |
| 16 | Person(const Person&); | |
| 17 | Person& operator=(const Person&); | |
| 18 | ~Person(); | |
| 19 | ||
| 20 | const char* getName() const { return name; }
| |
| 21 | const char* getBirth_date() const { return date; }
| |
| 22 | ||
| 23 | void setName(const char*); | |
| 24 | void setDate(const char da[9]); | |
| 25 | ||
| 26 | void print() const; | |
| 27 | ||
| 28 | ||
| 29 | ||
| 30 | private: | |
| 31 | char* name; | |
| 32 | char date[9]; | |
| 33 | ||
| 34 | }; | |
| 35 | ||
| 36 | ||
| 37 | void Person::setName(const char* na) | |
| 38 | {
| |
| 39 | if (this->name) | |
| 40 | {
| |
| 41 | delete[] this->name; | |
| 42 | this->name = NULL; | |
| 43 | } | |
| 44 | name = new char[strlen(na) + 1]; | |
| 45 | assert(name); | |
| 46 | strcpy_s(name, strlen(na), na); | |
| 47 | } | |
| 48 | ||
| 49 | void Person::setDate(const char da[9]) | |
| 50 | {
| |
| 51 | strcpy_s(date, strlen(da), da); | |
| 52 | } | |
| 53 | ||
| 54 | Person::Person(const char* na, const char da[9]) | |
| 55 | {
| |
| 56 | setName(na); | |
| 57 | setDate(da); | |
| 58 | } | |
| 59 | ||
| 60 | Person::Person(const Person & pe) | |
| 61 | :Person(pe.name, pe.date) | |
| 62 | {}
| |
| 63 | ||
| 64 | Person& Person::operator=(const Person& pe) | |
| 65 | {
| |
| 66 | if (this != &pe) | |
| 67 | {
| |
| 68 | ||
| 69 | setDate(pe.date); | |
| 70 | setName(pe.name); | |
| 71 | } | |
| 72 | ||
| 73 | return *this; | |
| 74 | } | |
| 75 | ||
| 76 | Person::~Person() | |
| 77 | {
| |
| 78 | delete[] name; | |
| 79 | } | |
| 80 | ||
| 81 | void Person::print() const | |
| 82 | {
| |
| 83 | cout << "Name: " << name << endl; | |
| 84 | cout << "Date of birth: " << date << endl; | |
| 85 | ||
| 86 | } | |
| 87 | class Student : virtual public Person | |
| 88 | {
| |
| 89 | public: | |
| 90 | Student(const char* = "", char[9] = "", int = 0, double = 0); | |
| 91 | Student(const Student&); | |
| 92 | Student& operator=(const Student&); | |
| 93 | bool operator==(const Student& other) const; | |
| 94 | bool operator!=(const Student& other) const; | |
| 95 | void set_fNumb(int); | |
| 96 | void set_uspeh(double); | |
| 97 | int get_fNumb() const { return f_num; }
| |
| 98 | double get_uspeh()const { return mid_mark; }
| |
| 99 | void print() const; | |
| 100 | ||
| 101 | ~Student(); | |
| 102 | private: | |
| 103 | int f_num; | |
| 104 | double mid_mark; | |
| 105 | }; | |
| 106 | bool Student::operator==(const Student& other) const {
| |
| 107 | return (this->f_num == other.get_fNumb()) && (this->mid_mark == other.get_uspeh()); | |
| 108 | }; | |
| 109 | bool Student::operator!=(const Student& other) const {
| |
| 110 | return !this->operator==(other); | |
| 111 | } | |
| 112 | void Student::set_fNumb(int nu) | |
| 113 | {
| |
| 114 | f_num = nu; | |
| 115 | ||
| 116 | } | |
| 117 | void Student::set_uspeh(double mid) | |
| 118 | {
| |
| 119 | if (mid < 2 || mid > 6) | |
| 120 | throw "incorect\n"; | |
| 121 | mid_mark = mid; | |
| 122 | } | |
| 123 | ||
| 124 | Student::Student(const char* nam, char dat[9], int numb, double mid) | |
| 125 | :Person(nam, dat) | |
| 126 | {
| |
| 127 | f_num = numb; | |
| 128 | mid_mark = mid; | |
| 129 | ||
| 130 | } | |
| 131 | ||
| 132 | Student::Student(const Student& st) :Person(st) | |
| 133 | {
| |
| 134 | set_fNumb(st.f_num); | |
| 135 | set_uspeh(st.mid_mark); | |
| 136 | } | |
| 137 | ||
| 138 | Student& Student::operator=(const Student&st) | |
| 139 | {
| |
| 140 | if (this != &st) | |
| 141 | {
| |
| 142 | Person::operator=(st); | |
| 143 | set_fNumb(st.f_num); | |
| 144 | set_uspeh(st.mid_mark); | |
| 145 | } | |
| 146 | ||
| 147 | return *this; | |
| 148 | } | |
| 149 | ||
| 150 | ||
| 151 | ||
| 152 | void Student::print() const | |
| 153 | {
| |
| 154 | Person::print(); | |
| 155 | cout << Student::get_fNumb() << Student::get_uspeh() << endl; | |
| 156 | } | |
| 157 | ||
| 158 | Student::~Student() {}
| |
| 159 | ||
| 160 | class Employee :virtual public Person | |
| 161 | {
| |
| 162 | public: | |
| 163 | Employee(const char* Name, char Date[9], const char* pos, double sal); | |
| 164 | Employee(const Employee&); | |
| 165 | Employee& operator=(const Employee&); | |
| 166 | ~Employee(); | |
| 167 | ||
| 168 | void set_pos(const char*); | |
| 169 | void set_sal(double); | |
| 170 | const char* get_pos() const { return possition; }
| |
| 171 | double get_sal()const { return salary; }
| |
| 172 | void print() const; | |
| 173 | ||
| 174 | private: | |
| 175 | char*possition; | |
| 176 | double salary; | |
| 177 | ||
| 178 | }; | |
| 179 | ||
| 180 | void Employee::set_pos(const char*po) | |
| 181 | {
| |
| 182 | if (possition != NULL) | |
| 183 | delete[]possition; | |
| 184 | possition = new char[strlen(po) + 1]; | |
| 185 | assert(possition); | |
| 186 | strcpy_s(possition, strlen(po), po); | |
| 187 | ||
| 188 | } | |
| 189 | ||
| 190 | void Employee::set_sal(double sa) | |
| 191 | {
| |
| 192 | salary = sa; | |
| 193 | } | |
| 194 | ||
| 195 | Employee::Employee(const char* Na, char Da[9], const char* pos, double sal) :Person(Na, Da) | |
| 196 | {
| |
| 197 | this->set_pos(pos); | |
| 198 | this->set_sal(sal); | |
| 199 | } | |
| 200 | Employee::Employee(const Employee& emp) : Person(emp) | |
| 201 | {
| |
| 202 | this->set_pos(emp.possition); | |
| 203 | this->set_sal(emp.salary); | |
| 204 | } | |
| 205 | Employee& Employee::operator=(const Employee & emp) | |
| 206 | {
| |
| 207 | if (this != &emp) | |
| 208 | {
| |
| 209 | Person::operator=(emp); | |
| 210 | this->set_pos(emp.possition); | |
| 211 | this->set_sal(emp.salary); | |
| 212 | } | |
| 213 | ||
| 214 | return *this; | |
| 215 | } | |
| 216 | Employee::~Employee() | |
| 217 | {
| |
| 218 | ||
| 219 | delete[] possition; | |
| 220 | } | |
| 221 | ||
| 222 | void Employee::print() const | |
| 223 | {
| |
| 224 | Person::print(); | |
| 225 | cout << Employee::get_pos() << Employee::get_sal() << endl; | |
| 226 | } | |
| 227 | ||
| 228 | class Proffessor :virtual public Person | |
| 229 | {
| |
| 230 | public: | |
| 231 | Proffessor(const char* Na = "", char Da[9] = "", const char* sub = "", Student* sts = nullptr, int sts_size = 0); | |
| 232 | Proffessor(const Proffessor&); | |
| 233 | Proffessor& operator=(const Proffessor&); | |
| 234 | ~Proffessor(); | |
| 235 | bool operator==(const Proffessor& pr); | |
| 236 | void set_subj(const char*); | |
| 237 | void set_arr_stud(Student*, int); | |
| 238 | const char* get_subj() const { return subjects; }
| |
| 239 | int get_size()const { return size; }
| |
| 240 | const Student* get_arr_stud()const | |
| 241 | {
| |
| 242 | return studs; | |
| 243 | } | |
| 244 | ||
| 245 | void print() const; | |
| 246 | ||
| 247 | ||
| 248 | private: | |
| 249 | char* subjects; | |
| 250 | Student* studs; | |
| 251 | int size; | |
| 252 | }; | |
| 253 | bool Proffessor::operator==(const Proffessor& pr) {
| |
| 254 | if (pr.get_size() == this->get_size()) {
| |
| 255 | return false; | |
| 256 | } | |
| 257 | for (int i = 0; i < pr.get_size(); i++) {
| |
| 258 | if (pr.get_arr_stud()[i]!= this->get_arr_stud()[i]) {
| |
| 259 | return false; | |
| 260 | } | |
| 261 | } | |
| 262 | return true && (strcmp(subjects, pr.get_subj()) == 0); | |
| 263 | }; | |
| 264 | void Proffessor::set_subj(const char*su) | |
| 265 | {
| |
| 266 | if (subjects != NULL) | |
| 267 | delete[]subjects; | |
| 268 | subjects = new char[strlen(su) + 1]; | |
| 269 | assert(subjects); | |
| 270 | strcpy_s(subjects, strlen(su), su); | |
| 271 | } | |
| 272 | void Proffessor::set_arr_stud(Student* stu, int size) | |
| 273 | {
| |
| 274 | if (studs != NULL) | |
| 275 | delete[]studs; | |
| 276 | studs = new Student[size]; | |
| 277 | ||
| 278 | for (int i = 0; i < size; i++) | |
| 279 | {
| |
| 280 | ||
| 281 | studs[i] = stu[i]; | |
| 282 | } | |
| 283 | } | |
| 284 | Proffessor::Proffessor(const char* Na, char Da[9], const char* sub, Student* sts, int sts_size) :Person(Na, Da) | |
| 285 | {
| |
| 286 | this->set_subj(sub); | |
| 287 | this->set_arr_stud(sts, sts_size); | |
| 288 | this->size = sts_size; | |
| 289 | } | |
| 290 | Proffessor::Proffessor(const Proffessor&pro) :Person(pro) | |
| 291 | {
| |
| 292 | this->set_subj(pro.subjects); | |
| 293 | this->set_arr_stud(pro.studs, pro.get_size()); | |
| 294 | } | |
| 295 | ||
| 296 | Proffessor& Proffessor::operator=(const Proffessor & pro) | |
| 297 | {
| |
| 298 | if (this != &pro) | |
| 299 | {
| |
| 300 | Person::operator=(pro); | |
| 301 | this->set_subj(pro.subjects); | |
| 302 | this->set_arr_stud(pro.studs, pro.get_size()); | |
| 303 | } | |
| 304 | ||
| 305 | return *this; | |
| 306 | } | |
| 307 | Proffessor::~Proffessor() | |
| 308 | {
| |
| 309 | ||
| 310 | delete[] studs; | |
| 311 | delete[] subjects; | |
| 312 | } | |
| 313 | void Proffessor::print() const | |
| 314 | {
| |
| 315 | Person::print(); | |
| 316 | cout << Proffessor::get_subj() << Proffessor::get_arr_stud() << endl; | |
| 317 | } | |
| 318 | ||
| 319 | class Decan : virtual public Proffessor, virtual public Employee | |
| 320 | {
| |
| 321 | public: | |
| 322 | Decan(const char* na, char da[9], const char* sub, Student* sts, char*pos, double sal) | |
| 323 | : | |
| 324 | Employee(na, da, sub, sal), | |
| 325 | Proffessor(na, da, sub, sts, 2) | |
| 326 | {}
| |
| 327 | ||
| 328 | void print() const | |
| 329 | {
| |
| 330 | Person::print(); | |
| 331 | cout << Employee::get_pos() << Employee::get_sal() << endl; | |
| 332 | cout << Proffessor::get_subj() << Proffessor::get_arr_stud() << endl; | |
| 333 | } | |
| 334 | ||
| 335 | }; | |
| 336 | ||
| 337 | Student bestStud(Proffessor& pro) | |
| 338 | {
| |
| 339 | int maxIndex = 0; | |
| 340 | for (int i = 1; i < pro.get_size(); i++) {
| |
| 341 | if (pro.get_arr_stud()[i].get_uspeh() > pro.get_arr_stud()[maxIndex].get_uspeh()) | |
| 342 | maxIndex = i; | |
| 343 | } | |
| 344 | return pro.get_arr_stud()[maxIndex]; | |
| 345 | } | |
| 346 | ||
| 347 | bool is_it_in(Proffessor *pro, int len, Decan& de) {
| |
| 348 | for (int i = 0; i < len; i++) {
| |
| 349 | if ((de == pro[i])) {
| |
| 350 | return true; | |
| 351 | } | |
| 352 | } | |
| 353 | return false; | |
| 354 | } | |
| 355 | int main() | |
| 356 | {
| |
| 357 | int len; | |
| 358 | cin >> len; | |
| 359 | Proffessor* arr = new Proffessor[len]; | |
| 360 | ||
| 361 | for (int i = 0; i < len; i++) {
| |
| 362 | char Na[50]; char Da[9]; char sub[20]; Student* sts = nullptr; | |
| 363 | cin >> Na >> Da >> sub; | |
| 364 | Proffessor temp(Na, Da, sub, sts, 0); | |
| 365 | arr[i] = temp; | |
| 366 | } | |
| 367 | Student* st = new Student; | |
| 368 | Decan dec("Ivanov", "08.03.12", "Älgebra", st, "teacher", 670.00);
| |
| 369 | ||
| 370 | if (is_it_in(arr, len, dec)) | |
| 371 | cout << "The proffesor is a decan" << endl; | |
| 372 | ||
| 373 | int siz = 2; | |
| 374 | Proffessor pr("Stefanova", "05.02.07", "Programing", st, siz);
| |
| 375 | ||
| 376 | return 0; | |
| 377 | ||
| 378 | } |