Advertisement
Guest User

valuten kurs

a guest
Jan 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <conio.h>
  7.  
  8. using namespace std;
  9.  
  10. class Currency
  11. {
  12. private:
  13. int c_hour;
  14. double c_FX;
  15. public:
  16. Currency() // подразбиращ - може да бъде и празен
  17. {
  18. c_hour = 0;
  19. c_FX = 0;
  20. }
  21. Currency(int a, int b) // експлицитен
  22. {
  23. c_hour = a;
  24. c_FX = b;
  25. }
  26. Currency(Currency *p) // копиращ конструктор
  27. {
  28. c_hour = p->c_hour;
  29. c_FX = p->c_FX;
  30. }
  31. bool operator<(Currency &a) // оператор за сравнение <
  32. {
  33. return c_hour < a.c_hour;
  34. }
  35. inline Currency operator+(Currency &a) // оператор за сумиране
  36. {
  37. this->c_FX += a.c_FX;
  38. return *this;
  39. }
  40. inline Currency operator-(Currency &a) // оператор за изваждане
  41. {
  42. a.c_FX -= this->c_FX;
  43. return *this;
  44. }
  45. friend istream& operator>>(istream& in, Currency &a) // предефиниране на оператор за въвеждане
  46. {
  47. in >> a.c_FX >> a.c_hour;
  48. return in;
  49. }
  50. friend ostream& operator<<(ostream& out, Currency &a) // предефиниране на оператор за извеждане
  51. {
  52. out << a.c_hour << " " << a.c_FX << endl;
  53. return out;
  54. }
  55. };
  56.  
  57. class DD
  58. {
  59. private:
  60. string dd_data;
  61. vector<Currency>dd_v;
  62. public:
  63. DD(string f)
  64. {
  65. ifstream ifile(f, ios::in); // дефиниране на файл за въвеждане в променливи от класа
  66. if (ifile.is_open()) // обработка на изключение дефакто ако няма файл с името което подаваме като параметър по горе - няма да се изпълни конструктора
  67. {
  68. ifile >> dd_data;
  69. copy(dd_v.begin(), !ifile.eof());
  70. ifile.close();
  71. }
  72. else
  73. {
  74. cout << "File couldn't be opened!";
  75. exit(1);
  76. }
  77. }
  78. void setdd(string a)
  79. {
  80. dd_data = a;
  81. }
  82. string getdd()
  83. {
  84. return dd_data;
  85. }
  86. friend istream& operator>>(istream& in, DD &a)
  87. {
  88. in >> a.dd_data;
  89. a.dd_v.push_back(in);
  90. return in;
  91. }
  92. friend ostream& operator<<(ostream& out, DD &a)
  93. {
  94. out << a.dd_data << endl;
  95. copy(a.dd_v.begin(), a.dd_v.end());
  96. return out;
  97. }
  98. };
  99.  
  100. int main()
  101. {
  102. DD object("neshtosi");
  103. cout << object;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement