Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // дз от 18.12.2024г.
- // 1)
- #include <iostream>
- class Employee {
- private:
- std::string name;
- double salary;
- public:
- Employee(std::string name, double salary) : name(name), salary(salary) {}
- void displayInfo() const {
- std::cout << "Имя сотрудника: " << name << ", Зарплата: " << salary << std::endl;
- }
- };
- class Manager : public Employee {
- private:
- double bonus;
- public:
- Manager(std::string name, double salary, double bonus) : Employee(name, salary), bonus(bonus) {}
- void displayInfo() const {
- Employee::displayInfo();
- std::cout << "Бонус менеджера: " << bonus << std::endl;
- }
- };
- class Developer : public Employee {
- private:
- int linesOfCode;
- public:
- Developer(std::string name, double salary, int linesOfCode) : Employee(name, salary), linesOfCode(linesOfCode) {}
- void displayInfo() const {
- Employee::displayInfo();
- std::cout << "Количество строк кода: " << linesOfCode << std::endl;
- }
- };
- int main() {
- Employee emp("John Doe", 5000.0);
- emp.displayInfo();
- Manager mgr("Jane Smith", 6000.0, 1000.0);
- mgr.displayInfo();
- Developer dev("Mike Brown", 7000.0, 10000);
- dev.displayInfo();
- return 0;
- }
- // 2)
- #include <iostream>
- class Student {
- private:
- std::string name;
- int age;
- static int studentCount;
- public:
- Student(std::string name, int age) : name(name), age(age), studentCount(++studentCount) {}
- ~Student() {
- studentCount--;
- }
- static int getStudentCount() {
- return studentCount;
- }
- void displayInfo() const {
- std::cout << "Имя студента: " << name << ", Возраст: " << age << std::endl;
- }
- };
- int Student::studentCount = 0;
- int main() {
- Student s1("Alice", 20);
- Student s2("Bob", 21);
- Student s3("Charlie", 22);
- std::cout << "Количество созданных объектов: " << Student::getStudentCount() << std::endl;
- s1.displayInfo();
- s2.displayInfo();
- s3.displayInfo();
- // Удаляем один объект
- delete s2;
- std::cout << "Количество объектов после удаления: " << Student::getStudentCount() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement