Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class Osoba
- {
- public:
- Osoba()
- {
- }
- Osoba(string Imie, string Nazwisko, string Pesel)
- {
- this->Imie() = Imie;
- this->Nazwisko() = Nazwisko;
- this->Pesel() = Pesel;
- }
- private:
- string _Imie;
- string _Nazwisko;
- string _Pesel;
- public:
- string& Imie()
- {
- return _Imie;
- }
- string& Nazwisko()
- {
- return _Nazwisko;
- }
- string& Pesel()
- {
- return _Pesel;
- }
- bool operator==(Osoba Osoba1)
- {
- if (Imie() == Osoba1.Imie() && Nazwisko() == Osoba1.Nazwisko() && Pesel() == Osoba1.Pesel()) return true;
- else return false;
- }
- };
- class BazaDanych
- {
- private:
- Osoba* _Osoby;
- unsigned int _N;
- public:
- BazaDanych()
- {
- _Osoby = 0;
- _N = 0;
- }
- BazaDanych(const BazaDanych& Baza1)
- {
- this->_N = Baza1._N;
- this->_Osoby = new Osoba[_N];
- for (unsigned int I = 0; I < _N; I++)
- {
- _Osoby[I] = Baza1._Osoby[I];
- }
- }
- ~BazaDanych()
- {
- delete[] _Osoby;
- }
- BazaDanych& operator=(const BazaDanych& Baza1)
- {
- if(this != &Baza1)
- {
- if (_N != 0) delete[] _Osoby;
- _N = Baza1._N;
- _Osoby = new Osoba[_N];
- for (unsigned int I = 0; I < _N; I++)
- {
- _Osoby[I] = Baza1._Osoby[I];
- }
- }
- return *this;
- }
- Osoba& operator[](unsigned int I)
- {
- return _Osoby[I];
- }
- };
- int main()
- {
- Osoba o1;
- cout << "---- 1 ----" << endl;
- cout << o1 << endl;
- Osoba o2("Jan", "Kowalski", 11111111111);
- cout << "---- 2 ----" << endl;
- cout << o2 << endl;
- cout << "---- 3 ----" << endl;
- cout << boolalpha << (o1 == o2) << endl;
- BazaDanych db1;
- cout << "---- 4 ----" << endl;
- cout << db1;
- db1 = db1 + o1;
- cout << "---- 5 ----" << endl;
- cout << db1;
- ifstream plik_we("zadanie6.txt");
- if(!plik_we)
- {
- cout << "---- 6 ----" << endl;
- return 1;
- }
- while(plik_we >> o2)
- {
- db1 = db1 + o2;
- }
- cout << "---- 7 ----" << endl;
- cout << db1;
- {
- BazaDanych db2(db1);
- cout << "---- 8 ----" << endl;
- cout << db2;
- }
- cout << "---- 9 ----" << endl;
- cout << db1;
- BazaDanych db3;
- db3 = db1 + db1
- cout << "---- 10 ----" << endl;
- cout << db3;
- for(int i=0; i<db3.liczbaOsob(); ++i)
- {
- cout << db3[i] << endl;
- }
- cout << "---- 11 ----" << endl;
- db1 = db1 - o1;
- cout << "---- 12 ----" << endl;
- cout << db1;
- cout << "---- 13 ----" << endl;
- cout << db3;
- cout << "---- 14 ----" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement