Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Human
- {
- protected:
- char* name = nullptr;
- int age = 0;
- public:
- Human() = default;
- Human(const char*, int);
- void Output_Human();
- ~Human();
- };
- Human::Human(const char* Name, int Age)
- {
- name = new char[strlen(Name) + 1];
- strcpy_s(name, strlen(Name) + 1, Name);
- age = Age;
- }
- void Human::Output_Human()
- {
- cout << "Output Human\n";
- cout << "Name: " << name << endl
- << "Age: " << age << endl << endl;
- }
- Human::~Human()
- {
- if (name != nullptr) delete[] name;
- }
- class Programmer : public Human
- {
- double Salary = 0;
- public:
- Programmer() = default;
- Programmer(const char* n, int a, double S);
- void Output();
- };
- Programmer::Programmer(const char* n, int a, double S) :Human(n, a), Salary(S) {}
- void Programmer::Output()
- {
- cout << "Output Student\n";
- Output_Human();
- cout << "Salary: " << Salary << endl;
- }
Add Comment
Please, Sign In to add comment