fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class land{
  7. public:
  8. land();
  9. land(char* n, char* k, int p, int s, string h, int b);
  10. land(const land& a);
  11. ~land();
  12. void editName(char*n);
  13. void editKind(char*k);
  14. void editPopulation(int p);
  15. void editSpace(int s);
  16. void editHead(string h);
  17. void editBudget(int b);
  18. friend ostream& operator <<(ostream& o, land& a);
  19. friend istream& operator >>(istream& i, land& a);
  20. land operator + ( int up);
  21. friend bool operator > (const land a, const land b);
  22. friend bool operator < (const land a, const land b);
  23. friend bool operator == (const land a, const land b);
  24. land operator % (int ub);
  25. private:
  26. char* name;
  27. char* kind;
  28. int population;
  29. int space;
  30. string head;
  31. int budget;
  32. };
  33.  
  34. land::land(){
  35. name = "unknown";
  36. kind = "unknown";
  37. population = 0;
  38. space = 0;
  39. head = "Anonymous";
  40. budget = 0;
  41. }
  42.  
  43. land::land(char* n, char* k, int p, int s, string h, int b){
  44. name = n;
  45. kind = k;
  46. population = p;
  47. space = s;
  48. head = h;
  49. budget = b;
  50. }
  51.  
  52. land::land(const land& a){
  53. this->name = a.name;
  54. this->kind = a.kind;
  55. this->population = a.population;
  56. this->space = a.space;
  57. this->head = a.head;
  58. this->budget = a.budget;
  59. }
  60.  
  61. void land::editName(char* n){
  62. this->name = n;
  63. }
  64.  
  65. void land::editKind(char* k){
  66. this->kind = k;
  67. }
  68.  
  69. void land::editPopulation(int p){
  70. this->population = p;
  71. }
  72.  
  73. void land::editSpace(int s){
  74. this->space = s;
  75. }
  76.  
  77. void land::editHead(string h){
  78. this ->head = h;
  79. }
  80.  
  81. void land::editBudget(int b){
  82. this->budget = b;
  83. }
  84.  
  85. istream& operator >> (istream& i, land& a){
  86. i >> a.name >> a.kind >> a.population >> a.space >> a.head >> a.budget;
  87. return i;
  88. }
  89.  
  90. ostream& operator << (ostream& o, land& a){
  91. o << a.name << " " << a.kind << " " << a.population << " " << a.space << " " << a.head << " " << a.budget << endl;
  92. return o;
  93. }
  94.  
  95. bool operator > (const land a, const land b){
  96. if(a.population == b.population)
  97. return a.space > b.space;
  98. else return a.population > b.population;
  99. }
  100.  
  101. bool operator < (const land a, const land b){
  102. if(a.population == b.population)
  103. return a.space < b.space;
  104. else return a.population < b.population;
  105. }
  106.  
  107. bool operator == (const land a, const land b){
  108. if(a.population != b.population)
  109. return 0;
  110. else return a.space == b.space;
  111. }
  112.  
  113. /*land operator + (int up){
  114.   this->population += up;
  115.   return this;
  116. }*/
  117.  
  118. land::~land(){
  119. }
  120.  
  121. int main()
  122. {
  123.  
  124. land test, test2;
  125. cin >> test; // >> operator doesn't work
  126. //test of output operators and methods of edition of containment (and comparison operators too)
  127. cout << test;
  128. test.editBudget(650);
  129. test.editHead("Head");
  130. test.editKind("City");
  131. test.editName("Name");
  132. test.editPopulation(789);
  133. test.editSpace(888);
  134. cout << test << endl << (test<test2) << ' ' << (test>test2) << ' ' << (test==test2);
  135. return 0;
  136. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
unknown unknown 0 0 Anonymous 0
Name City 789 888 Head 650

0 1 0