Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <vector>
- #include <algorithm>
- #include <conio.h>
- using namespace std;
- class Currency
- {
- private:
- int c_hour;
- double c_FX;
- public:
- Currency() // подразбиращ - може да бъде и празен
- {
- c_hour = 0;
- c_FX = 0;
- }
- Currency(int a, int b) // експлицитен
- {
- c_hour = a;
- c_FX = b;
- }
- Currency(Currency *p) // копиращ конструктор
- {
- c_hour = p->c_hour;
- c_FX = p->c_FX;
- }
- bool operator<(Currency &a) // оператор за сравнение <
- {
- return c_hour < a.c_hour;
- }
- inline Currency operator+(Currency &a) // оператор за сумиране
- {
- this->c_FX += a.c_FX;
- return *this;
- }
- inline Currency operator-(Currency &a) // оператор за изваждане
- {
- a.c_FX -= this->c_FX;
- return *this;
- }
- friend istream& operator>>(istream& in, Currency &a) // предефиниране на оператор за въвеждане
- {
- in >> a.c_FX >> a.c_hour;
- return in;
- }
- friend ostream& operator<<(ostream& out, Currency &a) // предефиниране на оператор за извеждане
- {
- out << a.c_hour << " " << a.c_FX << endl;
- return out;
- }
- };
- class DD
- {
- private:
- string dd_data;
- vector<Currency>dd_v;
- public:
- DD(string f)
- {
- ifstream ifile(f, ios::in); // дефиниране на файл за въвеждане в променливи от класа
- if (ifile.is_open()) // обработка на изключение дефакто ако няма файл с името което подаваме като параметър по горе - няма да се изпълни конструктора
- {
- ifile >> dd_data;
- copy(dd_v.begin(), !ifile.eof());
- ifile.close();
- }
- else
- {
- cout << "File couldn't be opened!";
- exit(1);
- }
- }
- void setdd(string a)
- {
- dd_data = a;
- }
- string getdd()
- {
- return dd_data;
- }
- friend istream& operator>>(istream& in, DD &a)
- {
- in >> a.dd_data;
- a.dd_v.push_back(in);
- return in;
- }
- friend ostream& operator<<(ostream& out, DD &a)
- {
- out << a.dd_data << endl;
- copy(a.dd_v.begin(), a.dd_v.end());
- return out;
- }
- };
- int main()
- {
- DD object("neshtosi");
- cout << object;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement