{"id":25841945,"url":"https://github.com/courseworks/ap-1400-1-hw4","last_synced_at":"2025-07-15T07:33:37.861Z","repository":{"id":46010219,"uuid":"429878016","full_name":"courseworks/AP-1400-1-HW4","owner":"courseworks","description":"Polymorphism and Inheritance","archived":false,"fork":false,"pushed_at":"2021-11-29T19:25:11.000Z","size":7,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2023-03-08T11:09:48.249Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/courseworks.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-19T17:14:39.000Z","updated_at":"2021-11-29T19:25:15.000Z","dependencies_parsed_at":"2022-09-08T22:24:36.574Z","dependency_job_id":null,"html_url":"https://github.com/courseworks/AP-1400-1-HW4","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP-1400-1-HW4","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP-1400-1-HW4/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP-1400-1-HW4/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/courseworks%2FAP-1400-1-HW4/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/courseworks","download_url":"https://codeload.github.com/courseworks/AP-1400-1-HW4/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241322575,"owners_count":19944073,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-01T05:32:51.768Z","updated_at":"2025-03-01T05:32:52.639Z","avatar_url":"https://github.com/courseworks.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ccenter\u003e\r\n\u003ch1\u003e\r\nIn The Name Of God\r\n\u003c/h1\u003e\r\n\u003ch2\u003e\r\nAdvanced Programming - Homework 3\r\n\u003c/h2\u003e\r\n\u003ch2\u003e\r\nDr.Amir Jahanshahi\r\n\u003c/h2\u003e\r\n\u003ch3\u003e\r\nDeadline: Sunday,  Azar 14 - 23:59\r\n\u003c/center\u003e\r\n\r\n# Inheritance and Polymorphism\r\nIn this homework we want to see simple inheritance and polymorphism example in c++ programming .At first, suppose we have Human class as parent class. Then we create two classes (`Adult `and` Child`) inheritted from `Human` class.\r\n\r\n## Human\r\n```c++ \r\nclass Human\r\n{\r\npublic:\r\n    std::string first_name;\r\n    std::string last_name;\r\n    int age;\r\n    Gender gender;\r\n    Adult* mother;\r\n    Adult* father;\r\n\r\n\r\n    Human();\r\n    Human(std::string _first_name,\r\n            std::string _last_name,\r\n                int _age,\r\n                    Gender _gender);\r\n    Human(const Human\u0026\u0026);\r\n\r\n    void setParent(Adult* mother,Adult* father);\r\n    Adult* getMother()const{return mother;}\r\n    Adult* getFather()const{return father;}\r\n\r\n\r\n    virtual const Human\u0026 superviser();\r\n    virtual const Child** getFriends();\r\n    virtual std::string what_is_she_or_he_doing();\r\n\r\n};\r\n```\r\nA Human object create by first name , last name , age , and Gender enum.\r\n```c++\r\nenum Gender{\r\n    MALE,\r\n    FEMALE\r\n}\r\n```\r\n### Question 1:\r\nIn human class we have some virtual methods in your report please describe what do `virtual` and `override` mean?\r\n\r\n# Child\r\n```c++\r\nclass Child : public Human\r\n{\r\nprivate:\r\n    Child** friends;\r\n    std::string game;\r\n    Adult* adulthood;\r\n    int number_of_friends = 0;\r\npublic:\r\n\r\n    Child(std::string,std::string,int,Gender);\r\n    Child(const Child\u0026\u0026);\r\n\r\n    Adult growingUp(std::string);\r\n    void addFriend(Child \u0026 child);\r\n    private:\r\n        const Child** getFriends();\r\n        std::string what_is_she_or_he_doing();//print game\r\n        const Human\u0026 superviser();\r\n\r\n};\r\n```\r\n### 1:growingUp\r\n`growingUp` convert `Child` object to `Adult` object and set all the member of `Adult` class.\r\n### 2:addFriend\r\n`addFriend` get a child object and add to `friends` list.\r\n\r\n# Adult\r\n```c++\r\nclass Adult : public Human\r\n{\r\npublic:\r\n    bool married = false;\r\n    bool isMother = false;\r\n    bool isFather = false;\r\n    Adult* spouse;\r\n    Child** children;\r\n    Child* childhood = nullptr;\r\n    int number_of_children = 0;\r\n    std::string job;\r\n    using Human::Human;\r\n\r\n    void marry(Adult*);\r\n    Child babyBorn(std::string fn,Gender gender);\r\n    \r\n    \r\n    private:\r\n        const Human\u0026 superviser();\r\n        std::string what_is_she_or_he_doing();//print job\r\n        const Child** getFriends();\r\n};\r\n```\r\n### Question 2:\r\nSearch about `using` keyword in `Adult` class and describe what does it mean?\r\n### marry:\r\nget an adult object and marry with an adult object and set all members and attributes.\r\n\r\n### babyBorn:\r\nThis function get first name and gender of new child and return new child and set all member of new child and adult children.\r\n\r\n\r\n# Virtual Functions\r\n## supervisor:\r\nIf an `Adult` object call this function it must return itself.\r\nIf a `Child` object call this function it must return her/his father.\r\n\r\n## getFriends:\r\nIf an `Adult` object call this function it must return her/his childhood friends\r\nIf a `Child` object call this function it must return  his/her friends.\r\n\r\n## what_is_she_or_he_doing():\r\nIf an `Adult` object call this function it must return her/his job and print on cosole like below : \r\n```\r\n[Job] : ${HIS/HER_JOB}\r\n```\r\nIf a `Child` object call this function it must return his/her game and print on console like below : \r\n```\r\n[Game] : ${HIS/HER_GAME}\r\n```\r\n\r\n\r\n\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap-1400-1-hw4","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourseworks%2Fap-1400-1-hw4","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourseworks%2Fap-1400-1-hw4/lists"}