Advertisement
Guest User

Untitled

a guest
May 2nd, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. =============================================================================================================
  2. main.cpp
  3. =============================================================================================================
  4. #include <iostream>
  5. #include "zbior.h"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     Zbior a(5);
  12.     Zbior b(6);
  13.     Zbior wynik(7);
  14.     int liczba;
  15.  
  16.     while( true )
  17.     {
  18.  
  19.         cout << "==MENU==" << endl;
  20.         cout << "1. Dodaj element do zbioru A" << endl;
  21.         cout << "2. Dodaj element do zbioru B" << endl;
  22.         cout << "3. Wyswietl elementy zbioru A" << endl;
  23.         cout << "4. Wyswietl elementy zbioru B" << endl;
  24.         cout << "5. Wyszysc zbior A" << endl;
  25.         cout << "6. Wyszysc zbior B" << endl;
  26.         cout << "7. Suma zbiorow" << endl;
  27.  
  28.         int menu;
  29.         cin >> menu;
  30.  
  31.         switch( menu ){
  32.             case 1:
  33.                 cout << "Podaj liczbe: " << endl;
  34.                 cin >> liczba;
  35.                 a.dodaj(liczba);
  36.                 break;
  37.  
  38.             case 2:
  39.                 cout << "Podaj liczbe: " << endl;
  40.                 cin >> liczba;
  41.                 b.dodaj(liczba);
  42.                 break;
  43.  
  44.             case 3:
  45.                 a.wyswietl();
  46.                 break;
  47.  
  48.             case 4:
  49.                 b.wyswietl();
  50.                 break;
  51.  
  52.             case 5:
  53.                 a.wyczysc();
  54.                 break;
  55.  
  56.             case 6:
  57.                 b.wyczysc();
  58.                 break;
  59.  
  60.             case 7:
  61.                 cout << "Suma zbiorow A i B wynosi: ";
  62.                 //wynik = a + b;
  63.                 break;
  64.  
  65.             default:
  66.                 cout << "Nieprawidlowy wybor." << endl;
  67.                 break;
  68.         }
  69.  
  70.     }
  71.  
  72.     return 0;
  73. }
  74.  
  75.  
  76. =============================================================================================================
  77. zbior.cpp
  78. =============================================================================================================
  79. #include <iostream>
  80. #include "zbior.h"
  81. #include <vector>
  82. #include <algorithm>
  83. //#include <functional>
  84. //#include <cassert>
  85. using namespace std;
  86.  
  87. Zbior::Zbior()
  88. {
  89.     tab.push_back(0);
  90. }
  91.  
  92. Zbior::Zbior(int x)
  93. {
  94.     tab.push_back(x);
  95. }
  96.  
  97. int Zbior::get_size()
  98. {
  99.     return tab.size();
  100. }
  101.  
  102. int Zbior::get_tab(int a)
  103. {
  104.     return tab[a];
  105. }
  106.  
  107. void Zbior::dodaj(int a)
  108. {
  109.     tab.push_back(a);
  110. }
  111.  
  112. void Zbior::wyswietl()
  113. {
  114.     for( int i = 0; i < tab.size(); i++ )
  115.          cout << tab[ i ] << endl;
  116. }
  117.  
  118. void Zbior::wyczysc(){
  119. tab.clear();
  120. }
  121.  
  122. =============================================================================================================
  123. zbior.h
  124. =============================================================================================================
  125. #pragma once
  126. #include <iostream>
  127. #include <vector>
  128. using namespace std;
  129.  
  130. class Zbior
  131. {
  132.    vector<int> tab;
  133.  
  134.  
  135. public:
  136.     Zbior();
  137.      Zbior(int);
  138.      //~Zbior();
  139.  
  140.  
  141.     int get_size();
  142.     int get_tab(int);
  143.     void dodaj(int);
  144.     void wyswietl();
  145.     void wyczysc();
  146.  
  147.     friend Zbior operator+ (const Zbior& a, const Zbior& b);
  148.  
  149. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement