Advertisement
Garey

Danny Class [02.10.2018]

Oct 2nd, 2018
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.12 KB | None | 0 0
  1. //
  2. //  02_10_upr_3_oop.cpp
  3. //  ConsoleApplication1
  4. //
  5. //  Created by Kolev on 2.10.18.
  6. //  Copyright © 2018 Kolev. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11.  
  12. using namespace std;
  13.  
  14. class Adress {
  15. private:
  16.     string ulica;
  17.     string kod;
  18.     string grad;
  19. public:
  20.     Adress();
  21.     Adress(string, string, string);
  22.     explicit Adress(const Adress &);
  23.     ~Adress();
  24.  
  25.     //set
  26.     void set_ulica(string);
  27.     void set_kod(string);
  28.     void set_grad(string);
  29.  
  30.     //get
  31.     string get_ulica();
  32.     string get_kod();
  33.     string get_grad();
  34.  
  35.     void print_info();
  36. };
  37.  
  38. Adress::Adress() {
  39.     this->ulica = "";
  40.     this->kod = "";
  41.     this->grad = "";
  42. }
  43.  
  44. Adress::Adress(string ulica, string kod, string grad) {
  45.     this->ulica = ulica;
  46.     this->kod = kod;
  47.     this->grad = grad;
  48. }
  49.  
  50. Adress::Adress(const Adress &obj) {
  51.     this->ulica = obj.ulica;
  52.     this->kod = obj.kod;
  53.     this->grad = obj.grad;
  54. }
  55.  
  56. Adress::~Adress() {}
  57.  
  58. //set
  59. void Adress::set_ulica(string ulica) {
  60.     this->ulica = ulica;
  61. }
  62.  
  63. void Adress::set_kod(string kod) {
  64.     this->kod = kod;
  65. }
  66.  
  67. void Adress::set_grad(string grad) {
  68.     this->grad = grad;
  69. }
  70.  
  71. //get
  72. string Adress::get_ulica() {
  73.     return this->ulica;
  74. }
  75.  
  76. string Adress::get_kod() {
  77.     return this->kod;
  78. }
  79.  
  80. string Adress::get_grad() {
  81.     return this->grad;
  82. }
  83.  
  84. void Adress::print_info() {
  85.     cout << "Ulica:  " << this->ulica << endl;
  86.     cout << "Poshtenski kod:  " << this->kod << endl;
  87.     cout << "Grad:  " << this->grad << endl;
  88.     cout << "---------------------------" << endl;
  89. }
  90.  
  91. class Person {
  92. protected:
  93.     string name;
  94.     string egn;
  95.     enum Gender {
  96.         male, female, unknown
  97.     } gender;
  98. public:
  99.     Person();
  100.     Person(string, string, string);
  101.     ~Person();
  102.  
  103.     void set_name(string);
  104.     void set_egn(string);
  105.     void set_gender(string);
  106.  
  107.     string get_name();
  108.     string get_egn();
  109.     string get_gender();
  110.  
  111.     void print_information();
  112.  
  113. };
  114.  
  115. Person::Person() {
  116.     this->name = "";
  117.     this->egn = "";
  118.     this->gender = Gender::male;
  119. }
  120.  
  121. Person::Person(string name, string egn, string gender) {
  122.     this->name = name;
  123.     this->egn = egn;
  124.     if (gender == "male") this->gender = Gender::male;
  125.     else if (gender == "female") this->gender = Gender::female;
  126.     else if (gender == "unknown") this->gender = Gender::unknown;
  127. }
  128.  
  129. Person::~Person() {}
  130.  
  131. //set
  132.  
  133. void Person::set_name(string name) {
  134.     this->name = name;
  135. }
  136.  
  137. void Person::set_egn(string egn) {
  138.     this->egn = egn;
  139. }
  140.  
  141. void Person::set_gender(string gender) {
  142.     if (gender == "male") this->gender = Gender::male;
  143.     else if (gender == "female") this->gender = Gender::female;
  144.     else if (gender == "unknown") this->gender = Gender::unknown;
  145. }
  146.  
  147. //get
  148.  
  149. string Person::get_name() {
  150.     return this->name;
  151. }
  152.  
  153. string Person::get_egn() {
  154.     return this->egn;
  155. }
  156.  
  157. string Person::get_gender() {
  158.     if (gender == Gender::male) return "male";
  159.     else if (gender == Gender::female) return "female";
  160.     else
  161.         return "unknown";
  162.  
  163. }
  164.  
  165. void Person::print_information() {
  166.     cout << "Ime:  " << this->name << endl;
  167.     cout << "EGN:  " << this->egn << endl;
  168.     cout << "Pol:  " << get_gender() << endl;
  169.     cout << "---------------------------" << endl;
  170. }
  171.  
  172.  
  173. class Student : public Person {
  174. private:
  175.     string fn;
  176.     Adress adress;
  177. public:
  178.     Student();
  179.     Student(string, const Adress &);
  180.     explicit Student(const Student &);
  181.     ~Student();
  182.  
  183.     void set_fn(string);
  184.     string get_fn();
  185.     void print_info();
  186.  
  187. };
  188.  
  189. Student::Student() {
  190.     this->fn = "";
  191.     this->adress = Adress();
  192. }
  193.  
  194. Student::Student(string fn, const Adress& adress) {
  195.     this->fn = fn;
  196.     this->adress = adress;
  197. }
  198.  
  199. Student::Student(const Student &obj) {
  200.     this->fn = obj.fn;
  201.     this->adress = obj.adress;
  202. }
  203.  
  204. Student::~Student()
  205. {
  206. }
  207.  
  208. void Student::set_fn(string fn) {
  209.     this->fn = fn;
  210. }
  211.  
  212. string Student::get_fn() {
  213.     return this->fn;
  214. }
  215.  
  216. void Student::print_info() {
  217.     cout << "Name: " << this->name << endl;
  218.     cout << "FN:  " << this->fn << endl;
  219.     this->adress.print_info();
  220. }
  221.  
  222. int main() {
  223.     system("clear");
  224.     Adress adr1("Vqra", "9020", "Varna");
  225.     Adress adr3("Dryzki 27", "9000", "Varna");
  226.     Adress adr2(adr1);
  227.  
  228.     Student one("17621707", adr3);
  229.     // Person one("Stefan Kolev","9812201049","male");
  230.     one.get_gender();
  231.     one.print_info();
  232.     return 0;
  233. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement