Last active
October 3, 2025 06:18
-
-
Save l3ngli/ca3c7a485a9827594428f585b8485b73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 2. Створіть клас Passport (паспорт), який міститиме паспортну інформацію про громадянина України. За допомогою | |
| механізму успадкування, реалізуйте клас ForeignPassport (закордонний паспорт), похідний від Passport. Загран.паспорт | |
| містить крім паспортних даних, також дані про візи. Віза має бути представлена окремим класом. */ | |
| #include <iostream> | |
| using namespace std; | |
| class Passport { | |
| protected: | |
| string name; | |
| string surname; | |
| int age; | |
| public: | |
| void SetName(string name) { | |
| this->name = name; | |
| } | |
| void SetSurname(string surname) { | |
| this->surname = surname; | |
| } | |
| void SetAge(int age) { | |
| if (age < 0 || age > 100) this->age = 18; | |
| else this->age = age; | |
| } | |
| string GetName() const { | |
| return name; | |
| } | |
| string GetSurname() const { | |
| return surname; | |
| } | |
| int GetAge() const { | |
| return age; | |
| } | |
| Passport(string name, string surname, int age) { | |
| SetName(name); | |
| SetSurname(surname); | |
| SetAge(age); | |
| } | |
| void Print() const { | |
| cout << "Name: " << name << "\n"; | |
| cout << "Surname: " << surname << "\n"; | |
| cout << "Age: " << age << "\n"; | |
| } | |
| }; | |
| class Visa { | |
| string country; | |
| string valid_until; | |
| public: | |
| Visa() { | |
| country = "N/A"; | |
| valid_until = "N/A"; | |
| } | |
| Visa(string country, string valid_until) { | |
| this->country = country; | |
| this->valid_until = valid_until; | |
| } | |
| void Print() const { | |
| cout << "Visa: " << country << ", valid until " << valid_until << "\n"; | |
| } | |
| }; | |
| class ForeignPassport : public Passport { | |
| protected: | |
| Visa visa; | |
| public: | |
| ForeignPassport(string name, string surname, int age, const Visa& v) : Passport(name, surname, age), visa(v) {} | |
| void Print() const { | |
| Passport::Print(); | |
| visa.Print(); | |
| } | |
| }; | |
| int main() { | |
| ForeignPassport myPassport("Alice", "Neliub", 18, Visa("China", "2027-06-06")); //сподіваюсь це скоро буде правда хааххахха | |
| myPassport.Print(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment