erehh

საკონტროლო სავარჯიშო 2

Jun 7th, 2022
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Person
  7. {
  8. protected:
  9.     string name;
  10.     string surname;
  11. public:
  12.     //კონსტრუქტორი პიროვნების ობიექტისა
  13.     Person(string name, string surname)
  14.     {
  15.         this->name = name;
  16.         this->surname = surname;
  17.     }
  18.  
  19.     ~Person() {};
  20.  
  21.     void printInfo() {
  22.         cout << "---------------------" << endl;
  23.         cout << "\tPerson\t" << endl;
  24.         cout << "Name - " << name << endl;
  25.         cout << "Surname - " << surname << endl;
  26.         cout << "---------------------" << endl;
  27.         cout << endl;
  28.     }
  29. };
  30.  
  31. class Student : public Person
  32. {
  33. protected:
  34.     string speciality;
  35.     float GPA;
  36. public:
  37.     //კონსტრუქტორი სტუდენტ ობიექტისა
  38.     Student(string name, string surname, string speciality, float GPA) :
  39.         Person(name, surname)
  40.     {
  41.         this->speciality = speciality;
  42.         this->GPA = GPA;
  43.     }
  44.  
  45.     ~Student() {};
  46.  
  47.     void printInfo() {
  48.         cout << "---------------------" << endl;
  49.         cout << "\tStudent\t" << endl;
  50.         cout << "Name - " << name << endl;
  51.         cout << "Surname - " << surname << endl;
  52.         cout << "Speciality - " << speciality << endl;
  53.         cout << "GPA - " << GPA << endl;
  54.         cout << "---------------------" << endl;
  55.         cout << endl;
  56.     }
  57.  
  58.     void setSpeciality(){
  59.         cout << "Enter the students speciality : ";
  60.         cin >> speciality;
  61.         cout << endl << "Speciality has been set!" << endl;
  62.         cout << endl;
  63.     }
  64.  
  65.  
  66. };
  67.  
  68. class Employee : public Student
  69. {
  70. protected:
  71.     string job;
  72.     double salary;
  73. public:
  74.     //კონსტრუქტორი თანამშრომლის ობიექტისა
  75.     Employee(string name, string surname, string speciality, float GPA, string job, double salary):
  76.         Student(name, surname, speciality, GPA)
  77.     {
  78.         this->job = job;
  79.         this->salary = salary;
  80.     }
  81.    
  82.     ~Employee() {};
  83.  
  84.     void printInfo() {
  85.         cout << "---------------------" << endl;
  86.         cout << "\tEmployee\t" << endl;
  87.         cout << "Name - " << name << endl;
  88.         cout << "Surname - " << surname << endl;
  89.         cout << "Speciality - " << speciality << endl;
  90.         cout << "GPA - " << GPA << endl;
  91.         cout << "Job - " << job << endl;
  92.         cout << "Salary - " << salary << endl;
  93.         cout << endl;
  94.         cout << "---------------------" << endl;
  95.     }
  96.  
  97.     void setSalary() {
  98.         if (salary < 1000)
  99.             salary *= 2;
  100.         else
  101.             salary = salary;
  102.     }
  103. };
  104.  
  105. int main()
  106. {
  107.     Person person_("Nick", "Sidiani");
  108.     person_.printInfo();//დაიბეჭდევა ინფორმაცია
  109.     person_.~Person();//დესტრუქტორი ამუშავდება
  110.  
  111.     Student student_("Buba", "Arxiani", "Coding", 3.1);
  112.     student_.printInfo();//დაიბეჭდევა ინფორმაცია
  113.     student_.setSpeciality();//სპეციალობა შეიცვლება კლავიატურიდან შემოტანილით
  114.     student_.printInfo();//დაიბეჭდევა ინფორმაცია
  115.     student_.~Student();//დესტრუქტორი ამუშავდება
  116.  
  117.     Employee employee_("Giorgi", "Giorgadze", "Cooking", 1.7, "Chef", 800);
  118.     employee_.printInfo();//დაიბეჭდევა ინფორმაცია
  119.     employee_.setSalary();//შეიცვლება ანაზღაურება, თუ 1000-ზე ნაკლებია
  120.     employee_.printInfo();//დაიბეჭდევა ინფორმაცია
  121.     employee_.~Employee();//დესტრუქტორი ამუშავდება
  122. }
Advertisement
Add Comment
Please, Sign In to add comment