BeloMaximka

Belov_HW_O27

Oct 11th, 2021 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. class Human
  5. {
  6. protected:
  7.     char* name = nullptr;
  8.     int age = 0;
  9. public:
  10.     Human() = default;
  11.     Human(const char*, int);
  12.     void Output_Human();
  13.     ~Human();
  14. };
  15.  
  16. Human::Human(const char* Name, int Age)
  17. {
  18.     name = new char[strlen(Name) + 1];
  19.     strcpy_s(name, strlen(Name) + 1, Name);
  20.     age = Age;
  21. }
  22.  
  23. void Human::Output_Human()
  24. {
  25.     cout << "Output Human\n";
  26.     cout << "Name: " << name << endl
  27.         << "Age: " << age << endl << endl;
  28. }
  29.  
  30. Human::~Human()
  31. {
  32.     if (name != nullptr) delete[] name;
  33. }
  34.  
  35. class Programmer : public Human
  36. {
  37.     double Salary = 0;
  38. public:
  39.     Programmer() = default;
  40.     Programmer(const char* n, int a, double S);
  41.     void Output();
  42. };
  43.  
  44. Programmer::Programmer(const char* n, int a, double S) :Human(n, a), Salary(S) {}
  45.  
  46. void Programmer::Output()
  47. {
  48.     cout << "Output Student\n";
  49.     Output_Human();
  50.  
  51.     cout << "Salary: " << Salary << endl;
  52. }
Add Comment
Please, Sign In to add comment