Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #include "Bus.hpp"
  2. #include "String.hpp"
  3. #include <stdio.h>
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. Bus:: Bus (const Bus &Q)
  9. {
  10. identifity_number = String (Q.identifity_number);
  11. surname_ = String (Q.surname_);
  12. route_number = Q.route_number;
  13. IO_ = Q.IO_;
  14. }
  15.  
  16. bool Bus:: operator > (const Bus &Q) const
  17. {
  18. return route_number > Q.route_number;
  19. }
  20.  
  21. bool operator == (const Bus &Q1, const Bus &Q2)
  22. {
  23. return Q1.route_number == Q2.route_number;
  24. }
  25.  
  26. void Bus:: operator ++ ()
  27. {
  28. route_number++;
  29. }
  30.  
  31. Bus operator ++ (Bus &Q, int n)
  32. {
  33. Bus bus = Q;
  34. Q.route_number++;
  35. return bus;
  36. }
  37.  
  38. Bus Bus:: operator = (const Bus &Q)
  39. {
  40. route_number = Q.route_number;
  41. identifity_number = Q.identifity_number;
  42. IO_ = Q.IO_;
  43. surname_ = Q.surname_;
  44. return *this;
  45. }
  46.  
  47. Bus Bus:: operator + ( char *s)
  48. {
  49. String str;
  50. str = surname_ + s;
  51. surname_ = str;
  52. return *this;
  53. }
  54.  
  55. Bus operator + (Bus &Q, const char *s)
  56. {
  57. String str;
  58. str = Q.surname_ + s;
  59. Q.surname_ = str;
  60. return Q;
  61. }
  62.  
  63. char& Bus:: operator [] (int i)
  64. {
  65. return identifity_number [i];
  66. }
  67.  
  68. ostream& operator<< (ostream& out, Bus &Q)
  69. {
  70. return out <<"identifity number - "<<Q.identifity_number <<"; route number - "<< Q.route_number <<"; the driver - " << Q.surname_<< ' '<< Q.IO_;
  71. }
  72.  
  73. istream& operator>> (istream& in, Bus & Q)
  74. {
  75. int n;
  76. cout << "enter the number of symbols\n";
  77. in >> n;
  78. String a(n);
  79. cout << "enter identifity number\n";
  80. in >> a;
  81. cout << "enter the number of symbols\n";
  82. in >> n;
  83. String b(n);
  84. cout << "enter the surname\n";
  85. in >> b;
  86. cout << "enter the number of symbols\n";
  87. in >> n;
  88. String s(n);
  89. cout << "enter the inicialy\n";
  90. in >> s;
  91. cout << "enter tne number of rout\n";
  92. short int c;
  93. in >> c;
  94. if (c<0)
  95. throw "tne number is incorrect\n";
  96. Q =Bus (a,c,b,s);
  97. return in;
  98. }
  99.  
  100. int Max ( Bus &Q)
  101. {
  102. int max_index = 0;
  103. unsigned long int t = Q.identifity_number.length();
  104. for (int i=1; i<=t; i++)
  105. {
  106. if (Q[i] > Q[max_index])
  107. {
  108. max_index = i;
  109. }
  110. }
  111. return max_index+1;
  112. }
  113.  
  114. void Sort (Bus &Q)
  115. {
  116. unsigned long int t = Q.identifity_number.length();
  117. for (int i=1;i<t;i++)
  118. {
  119. char key = Q [i];
  120. int j=i-1;
  121. while (j>=0 && Q[j]>key)
  122. {
  123. Q[j+1]=Q[j];
  124. j--;
  125. }
  126. Q[j+1]=key;
  127. }
  128. cout << "changed identifity number is "<<Q.identifity_number << endl;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement