Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication92.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<string.h>
- #include<assert.h>
- using namespace std;
- class Person
- {
- public:
- Person(const char* na = "", const char da[9] = "");
- Person(const Person&);
- Person& operator=(const Person&);
- ~Person();
- const char* getName() const { return name; }
- const char* getBirth_date() const { return date; }
- void setName(const char*);
- void setDate(const char da[9]);
- void print() const;
- private:
- char* name;
- char date[9];
- };
- void Person::setName(const char* na)
- {
- if (this->name)
- {
- delete[] this->name;
- this->name = NULL;
- }
- name = new char[strlen(na) + 1];
- assert(name);
- strcpy_s(name, strlen(na), na);
- }
- void Person::setDate(const char da[9])
- {
- strcpy_s(date, strlen(da), da);
- }
- Person::Person(const char* na, const char da[9])
- {
- setName(na);
- setDate(da);
- }
- Person::Person(const Person & pe)
- :Person(pe.name, pe.date)
- {}
- Person& Person::operator=(const Person& pe)
- {
- if (this != &pe)
- {
- setDate(pe.date);
- setName(pe.name);
- }
- return *this;
- }
- Person::~Person()
- {
- delete[] name;
- }
- void Person::print() const
- {
- cout << "Name: " << name << endl;
- cout << "Date of birth: " << date << endl;
- }
- class Student : virtual public Person
- {
- public:
- Student(const char* = "", char[9] = "", int = 0, double = 0);
- Student(const Student&);
- Student& operator=(const Student&);
- bool operator==(const Student& other) const;
- bool operator!=(const Student& other) const;
- void set_fNumb(int);
- void set_uspeh(double);
- int get_fNumb() const { return f_num; }
- double get_uspeh()const { return mid_mark; }
- void print() const;
- ~Student();
- private:
- int f_num;
- double mid_mark;
- };
- bool Student::operator==(const Student& other) const {
- return (this->f_num == other.get_fNumb()) && (this->mid_mark == other.get_uspeh());
- };
- bool Student::operator!=(const Student& other) const {
- return !this->operator==(other);
- }
- void Student::set_fNumb(int nu)
- {
- f_num = nu;
- }
- void Student::set_uspeh(double mid)
- {
- if (mid < 2 || mid > 6)
- throw "incorect\n";
- mid_mark = mid;
- }
- Student::Student(const char* nam, char dat[9], int numb, double mid)
- :Person(nam, dat)
- {
- f_num = numb;
- mid_mark = mid;
- }
- Student::Student(const Student& st) :Person(st)
- {
- set_fNumb(st.f_num);
- set_uspeh(st.mid_mark);
- }
- Student& Student::operator=(const Student&st)
- {
- if (this != &st)
- {
- Person::operator=(st);
- set_fNumb(st.f_num);
- set_uspeh(st.mid_mark);
- }
- return *this;
- }
- void Student::print() const
- {
- Person::print();
- cout << Student::get_fNumb() << Student::get_uspeh() << endl;
- }
- Student::~Student() {}
- class Employee :virtual public Person
- {
- public:
- Employee(const char* Name, char Date[9], const char* pos, double sal);
- Employee(const Employee&);
- Employee& operator=(const Employee&);
- ~Employee();
- void set_pos(const char*);
- void set_sal(double);
- const char* get_pos() const { return possition; }
- double get_sal()const { return salary; }
- void print() const;
- private:
- char*possition;
- double salary;
- };
- void Employee::set_pos(const char*po)
- {
- if (possition != NULL)
- delete[]possition;
- possition = new char[strlen(po) + 1];
- assert(possition);
- strcpy_s(possition, strlen(po), po);
- }
- void Employee::set_sal(double sa)
- {
- salary = sa;
- }
- Employee::Employee(const char* Na, char Da[9], const char* pos, double sal) :Person(Na, Da)
- {
- this->set_pos(pos);
- this->set_sal(sal);
- }
- Employee::Employee(const Employee& emp) : Person(emp)
- {
- this->set_pos(emp.possition);
- this->set_sal(emp.salary);
- }
- Employee& Employee::operator=(const Employee & emp)
- {
- if (this != &emp)
- {
- Person::operator=(emp);
- this->set_pos(emp.possition);
- this->set_sal(emp.salary);
- }
- return *this;
- }
- Employee::~Employee()
- {
- delete[] possition;
- }
- void Employee::print() const
- {
- Person::print();
- cout << Employee::get_pos() << Employee::get_sal() << endl;
- }
- class Proffessor :virtual public Person
- {
- public:
- Proffessor(const char* Na = "", char Da[9] = "", const char* sub = "", Student* sts = nullptr, int sts_size = 0);
- Proffessor(const Proffessor&);
- Proffessor& operator=(const Proffessor&);
- ~Proffessor();
- bool operator==(const Proffessor& pr);
- void set_subj(const char*);
- void set_arr_stud(Student*, int);
- const char* get_subj() const { return subjects; }
- int get_size()const { return size; }
- const Student* get_arr_stud()const
- {
- return studs;
- }
- void print() const;
- private:
- char* subjects;
- Student* studs;
- int size;
- };
- bool Proffessor::operator==(const Proffessor& pr) {
- if (pr.get_size() == this->get_size()) {
- return false;
- }
- for (int i = 0; i < pr.get_size(); i++) {
- if (pr.get_arr_stud()[i]!= this->get_arr_stud()[i]) {
- return false;
- }
- }
- return true && (strcmp(subjects, pr.get_subj()) == 0);
- };
- void Proffessor::set_subj(const char*su)
- {
- if (subjects != NULL)
- delete[]subjects;
- subjects = new char[strlen(su) + 1];
- assert(subjects);
- strcpy_s(subjects, strlen(su), su);
- }
- void Proffessor::set_arr_stud(Student* stu, int size)
- {
- if (studs != NULL)
- delete[]studs;
- studs = new Student[size];
- for (int i = 0; i < size; i++)
- {
- studs[i] = stu[i];
- }
- }
- Proffessor::Proffessor(const char* Na, char Da[9], const char* sub, Student* sts, int sts_size) :Person(Na, Da)
- {
- this->set_subj(sub);
- this->set_arr_stud(sts, sts_size);
- this->size = sts_size;
- }
- Proffessor::Proffessor(const Proffessor&pro) :Person(pro)
- {
- this->set_subj(pro.subjects);
- this->set_arr_stud(pro.studs, pro.get_size());
- }
- Proffessor& Proffessor::operator=(const Proffessor & pro)
- {
- if (this != &pro)
- {
- Person::operator=(pro);
- this->set_subj(pro.subjects);
- this->set_arr_stud(pro.studs, pro.get_size());
- }
- return *this;
- }
- Proffessor::~Proffessor()
- {
- delete[] studs;
- delete[] subjects;
- }
- void Proffessor::print() const
- {
- Person::print();
- cout << Proffessor::get_subj() << Proffessor::get_arr_stud() << endl;
- }
- class Decan : virtual public Proffessor, virtual public Employee
- {
- public:
- Decan(const char* na, char da[9], const char* sub, Student* sts, char*pos, double sal)
- :
- Employee(na, da, sub, sal),
- Proffessor(na, da, sub, sts, 2)
- {}
- void print() const
- {
- Person::print();
- cout << Employee::get_pos() << Employee::get_sal() << endl;
- cout << Proffessor::get_subj() << Proffessor::get_arr_stud() << endl;
- }
- };
- Student bestStud(Proffessor& pro)
- {
- int maxIndex = 0;
- for (int i = 1; i < pro.get_size(); i++) {
- if (pro.get_arr_stud()[i].get_uspeh() > pro.get_arr_stud()[maxIndex].get_uspeh())
- maxIndex = i;
- }
- return pro.get_arr_stud()[maxIndex];
- }
- bool is_it_in(Proffessor *pro, int len, Decan& de) {
- for (int i = 0; i < len; i++) {
- if ((de == pro[i])) {
- return true;
- }
- }
- return false;
- }
- int main()
- {
- int len;
- cin >> len;
- Proffessor* arr = new Proffessor[len];
- for (int i = 0; i < len; i++) {
- char Na[50]; char Da[9]; char sub[20]; Student* sts = nullptr;
- cin >> Na >> Da >> sub;
- Proffessor temp(Na, Da, sub, sts, 0);
- arr[i] = temp;
- }
- Student* st = new Student;
- Decan dec("Ivanov", "08.03.12", "Älgebra", st, "teacher", 670.00);
- if (is_it_in(arr, len, dec))
- cout << "The proffesor is a decan" << endl;
- int siz = 2;
- Proffessor pr("Stefanova", "05.02.07", "Programing", st, siz);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment