Advertisement
mollevi99

Prog II. - hw2 - feladat.cpp

Oct 1st, 2022 (edited)
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Telepes{
  7. private:
  8.     string nev,szul_bolygo,bolygo;
  9.     unsigned int ero;
  10.     bool vegan;
  11. public:
  12.     Telepes();
  13.     const string &get_nev() const;
  14.     void set_nev(const string &nev);
  15.     const string &get_szul_bolygo() const;
  16.     void set_szul_bolygo(const string &szulBolygo);
  17.     const string &get_bolygo() const;
  18.     void set_bolygo(const string &bolygo);
  19.     unsigned int get_ero() const;
  20.     void set_ero(unsigned int ero);
  21.     bool is_vegan() const;
  22.     void set_vegan(const bool &vegan);
  23. };
  24. class Kolonia{
  25. private:
  26.     string nev,bolygo;
  27.     unsigned int letszam;
  28.     Telepes* lakok;
  29. public:
  30.     unsigned int get_letszam() const;
  31.     const Telepes* get_lakok() const;
  32.     const string &get_nev() const;
  33.     void set_nev(const string &nev);
  34.     const string &get_bolygo() const;
  35.     void set_bolygo(const string &bolygo);
  36.     Kolonia();
  37.     Kolonia(const string &nev, const string &bolygo);
  38.  
  39.     Kolonia& operator+=(const Telepes &newTelepes) {
  40.         for(int i=0; i<25; i++){
  41.             if(this->lakok[i].get_nev() == ""){
  42.                 this->lakok[i] = newTelepes;
  43.                 return *this;
  44.             }
  45.         }
  46.         cout << "A kolonia megtelt\n";
  47.         return *this;
  48.     }
  49.     Kolonia& operator~(){
  50.         bool isVeganColony=false;
  51.         int sizeOfColony=0;
  52.         int vegansInColony;
  53.         for(Telepes& lako : this->get_lakok()){
  54.             if(telepesPeldany->nev != ""){
  55.                 sizeOfColony++;
  56.                 if(telepesPeldany->vegan) vegansInColony++;
  57.             }else{
  58.                 if(vegansInColony / sizeOfColony > 0.5 && sizeOfColony > 0)
  59.                 return true;
  60.                 else return false;
  61.             }
  62.         }
  63.         return
  64.     }
  65.  
  66. };
  67.  
  68. int main() {
  69.     Telepes elsoTelepesek[26];
  70.     for(int i=0; i<26; i++) {
  71.         elsoTelepesek[i].set_nev("nev");
  72.         elsoTelepesek[i].set_bolygo("Vegeta");
  73.         elsoTelepesek[i].set_vegan(true);
  74.     }
  75.     Kolonia elsoKolonia = *new Kolonia();
  76.     for(int i=0; i<26; i++) {
  77.         elsoKolonia+=elsoTelepesek[i];
  78.         const Telepes* ittLakok;
  79.         ittLakok= elsoKolonia.get_lakok();
  80.         cout << ittLakok[i].get_bolygo() + "és" + elsoTelepesek[i].get_bolygo()<< endl;
  81.     }
  82.     cout<< ~elsoKolonia ? "VEGÁN KOLÓNIA" : "NEM VEGÁN KOLÓNIA";
  83.     return 0;
  84. }
  85.  
  86. Kolonia::Kolonia() : nev(""), bolygo(""), letszam(0) {
  87.     lakok = new Telepes[25];
  88. }
  89.  
  90. Kolonia::Kolonia(const string &nev, const string &bolygo) : nev(nev), bolygo(bolygo), letszam(0) {
  91.     lakok = new Telepes[25];
  92. }
  93.  
  94. const string &Kolonia::get_nev() const {
  95.     return nev;
  96. }
  97.  
  98. void Kolonia::set_nev(const string &nev) {
  99.     Kolonia::nev = nev;
  100. }
  101.  
  102. const string &Kolonia::get_bolygo() const {
  103.     return bolygo;
  104. }
  105.  
  106. void Kolonia::set_bolygo(const string &bolygo) {
  107.     Kolonia::bolygo = bolygo;
  108. }
  109.  
  110. unsigned int Kolonia::get_letszam() const {
  111.     return letszam;
  112. }
  113.  
  114. const Telepes* Kolonia::get_lakok() const {
  115.     return lakok;
  116. }
  117.  
  118. Telepes::Telepes(){
  119.     nev="";
  120.     szul_bolygo="";
  121.     bolygo="";
  122.     ero=1;
  123.     vegan=false;
  124. }
  125.  
  126. const string &Telepes::get_nev() const {
  127.     return nev;
  128. }
  129.  
  130. void Telepes::set_nev(const string &toBeNev) {
  131.     Telepes::nev = toBeNev;
  132. }
  133.  
  134. const string &Telepes::get_szul_bolygo() const {
  135.     return szul_bolygo;
  136. }
  137.  
  138. void Telepes::set_szul_bolygo(const string &szulBolygo) {
  139.     szul_bolygo = szulBolygo;
  140. }
  141.  
  142. const string &Telepes::get_bolygo() const {
  143.     return bolygo;
  144. }
  145.  
  146. void Telepes::set_bolygo(const string &toBeBolygo) {
  147.     Telepes::bolygo = toBeBolygo;
  148. }
  149.  
  150. unsigned int Telepes::get_ero() const {
  151.     return ero;
  152. }
  153.  
  154. void Telepes::set_ero(unsigned const int toBeEro) {
  155.     Telepes::ero = toBeEro;
  156. }
  157.  
  158. bool Telepes::is_vegan() const {
  159.     return Telepes::vegan;
  160. }
  161.  
  162. void Telepes::set_vegan(const bool &toBeVegan) {
  163.     Telepes::vegan = toBeVegan;
  164. }
  165.  
Tags: homework
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement