Advertisement
frusso1337

Planinarsko

Apr 2nd, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4. class PlDrustvo{
  5. private:
  6. char *ime;
  7. int brojTuri;
  8. int clenovi;
  9. public:
  10. PlDrustvo(){
  11. ime=NULL;
  12. brojTuri=0;
  13. clenovi=0;
  14. }
  15. PlDrustvo(char *ime,int brojTuri,int clenovi){
  16. this->ime=new char [strlen(ime)+1];
  17. strcpy(this->ime,ime);
  18. this->brojTuri=brojTuri;
  19. this->clenovi=clenovi;
  20. }
  21. PlDrustvo(const PlDrustvo& p){
  22. this->ime=new char [strlen(p.ime)+1];
  23. strncpy(this->ime,p.ime,strlen(p.ime)+1);
  24. this->brojTuri=p.brojTuri;
  25. this->clenovi=p.clenovi;
  26. }
  27. PlDrustvo& operator=(const PlDrustvo &p){
  28. if(this!=&p){
  29. delete [] this->ime;
  30. this->ime=new char [strlen(p.ime)+1];
  31. strcpy(this->ime,p.ime);
  32. this->brojTuri=p.brojTuri;
  33. this->clenovi=p.clenovi;
  34. }
  35. return *this;
  36. }
  37. PlDrustvo operator+(const PlDrustvo &p){
  38. PlDrustvo p1;
  39. if(*this>p){
  40. delete [] p1.ime;
  41. p1.ime=new char [strlen(this->ime)+1];
  42. strncpy(p1.ime,this->ime,strlen(this->ime)+1);
  43. p1.brojTuri=this->brojTuri;
  44. p1.clenovi=this->clenovi+p.clenovi;
  45. } else {
  46. delete [] p1.ime;
  47. p1.ime=new char [strlen(p.ime)+1];
  48. strncpy(p1.ime,p.ime,strlen(p.ime)+1);
  49. p1.brojTuri=p.brojTuri;
  50. p1.clenovi=this->clenovi+p.clenovi;
  51. }
  52. return p1;
  53. }
  54. ~PlDrustvo(){
  55. delete [] ime;
  56. }
  57. friend ostream& operator<<( ostream& output,PlDrustvo &p){
  58. output<<"Ime: "<<p.ime<<" Turi: "<<p.brojTuri<<" Clenovi: "<<p.clenovi<<endl;
  59. return output;
  60. }
  61. bool operator<(const PlDrustvo& p){
  62. return this->clenovi<p.clenovi;
  63. }
  64. bool operator>(const PlDrustvo& p){
  65. return this->clenovi>p.clenovi;
  66. }
  67. };
  68. void najmnoguClenovi(PlDrustvo* drustva,int n){
  69. PlDrustvo max=drustva[0];
  70. for(int i=1;i<n;i++){
  71. if(drustva[i]>max){
  72. max=drustva[i];
  73. }
  74. }
  75. cout<<"Najmnogu clenovi ima planinarskoto drustvo: "<<max;
  76. }
  77. int main()
  78. {
  79. PlDrustvo drustva[3];
  80. PlDrustvo pl;
  81. for (int i=0;i<3;i++)
  82. {
  83. char ime[100];
  84. int brTuri;
  85. int brClenovi;
  86. cin>>ime;
  87. cin>>brTuri;
  88. cin>>brClenovi;
  89. PlDrustvo p(ime,brTuri,brClenovi);
  90. drustva[i] = p;
  91. }
  92. pl = (drustva[0] + drustva[1]);
  93. cout<<pl;
  94. najmnoguClenovi(drustva, 3);
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement