Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =============================================================================================================
- main.cpp
- =============================================================================================================
- #include <iostream>
- #include "zbior.h"
- using namespace std;
- int main()
- {
- Zbior a(5);
- Zbior b(6);
- Zbior wynik(7);
- int liczba;
- while( true )
- {
- cout << "==MENU==" << endl;
- cout << "1. Dodaj element do zbioru A" << endl;
- cout << "2. Dodaj element do zbioru B" << endl;
- cout << "3. Wyswietl elementy zbioru A" << endl;
- cout << "4. Wyswietl elementy zbioru B" << endl;
- cout << "5. Wyszysc zbior A" << endl;
- cout << "6. Wyszysc zbior B" << endl;
- cout << "7. Suma zbiorow" << endl;
- int menu;
- cin >> menu;
- switch( menu ){
- case 1:
- cout << "Podaj liczbe: " << endl;
- cin >> liczba;
- a.dodaj(liczba);
- break;
- case 2:
- cout << "Podaj liczbe: " << endl;
- cin >> liczba;
- b.dodaj(liczba);
- break;
- case 3:
- a.wyswietl();
- break;
- case 4:
- b.wyswietl();
- break;
- case 5:
- a.wyczysc();
- break;
- case 6:
- b.wyczysc();
- break;
- case 7:
- cout << "Suma zbiorow A i B wynosi: ";
- //wynik = a + b;
- break;
- default:
- cout << "Nieprawidlowy wybor." << endl;
- break;
- }
- }
- return 0;
- }
- =============================================================================================================
- zbior.cpp
- =============================================================================================================
- #include <iostream>
- #include "zbior.h"
- #include <vector>
- #include <algorithm>
- //#include <functional>
- //#include <cassert>
- using namespace std;
- Zbior::Zbior()
- {
- tab.push_back(0);
- }
- Zbior::Zbior(int x)
- {
- tab.push_back(x);
- }
- int Zbior::get_size()
- {
- return tab.size();
- }
- int Zbior::get_tab(int a)
- {
- return tab[a];
- }
- void Zbior::dodaj(int a)
- {
- tab.push_back(a);
- }
- void Zbior::wyswietl()
- {
- for( int i = 0; i < tab.size(); i++ )
- cout << tab[ i ] << endl;
- }
- void Zbior::wyczysc(){
- tab.clear();
- }
- =============================================================================================================
- zbior.h
- =============================================================================================================
- #pragma once
- #include <iostream>
- #include <vector>
- using namespace std;
- class Zbior
- {
- vector<int> tab;
- public:
- Zbior();
- Zbior(int);
- //~Zbior();
- int get_size();
- int get_tab(int);
- void dodaj(int);
- void wyswietl();
- void wyczysc();
- friend Zbior operator+ (const Zbior& a, const Zbior& b);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement