Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл "Chisla.h"
- ___________________
- #pragma once
- #include <iostream>
- using namespace std;
- class Chisla
- {
- private:
- int kolvo;
- int *mas;
- public:
- Chisla(int num) //конструктор (создаёт массив из num эементов и заполняет его нулями)
- {
- kolvo = num;
- mas = new int[kolvo];
- for(int n = 0; n<kolvo; n++)
- {
- mas[n] = 0;
- }
- }
- void setMas() //сеттер (устанавливает значения элементов массива)
- {
- if(kolvo == 0)
- {
- cout<<"Vvedite kolichestvo chisel v vashem mnozhestve: ";
- cin>>kolvo;
- cout<<endl;
- }
- mas = new int[kolvo];
- cout<<"Vvedite mnozhestvo tselih chisel: "<<endl;
- for(int n = 0; n<kolvo; n++)
- {
- cout<<endl<<"Vvedite chislo nomer "<<n+1<<" : "<<'\t';
- cin>>mas[n];
- }
- }
- void setChislo(int num, int chislo) //сеттер (устанавливает элементу множества номер num значение chislo)
- {
- mas[num-1] = chislo;
- }
- int getChislo(int num) //геттер (возвращает элемент множества номер num)
- {
- return mas[num-1];
- }
- void intersection(Chisla& c1, Chisla& c2)
- {
- int *per = new int[];
- int n = 0;
- for(int i = 0; i<c1.kolvo; i++)
- {
- for(int j = 0; j<c2.kolvo; j++)
- {
- if(c1.mas[i] == c2.mas[j])
- {
- per[n] = c1.mas[i];
- n++;
- }
- }
- }
- cout<<endl<<"Mnozhestvo peresecheniy: "<<'\t'<<"(";
- for(int k = 0; k<n; k++)
- {
- cout<<per[k]<<';';
- }
- cout<<")";
- delete [] per;
- }
- void combination(Chisla& c1, Chisla& c2)
- {
- int n1 = c1.kolvo;
- int n2 = c2.kolvo;
- int plus = 0;
- int *num = new int[];
- for(int i = 0; i<n1; i++)
- {
- num[i] = c1.mas[i];
- }
- for(int i = 0; i<n1; i++)
- {
- for(int j = 0; j<n2; j++)
- {
- if(num[i] == c2.mas[j])
- {
- continue;
- }
- num[n1+plus] = c2.mas[j];
- plus++;
- }
- }
- n1 = n1+plus;
- cout<<endl<<"Mnozhestvo ob'edineniy: "<<'\t'<<"(";
- for(int i = 0; i<n1; i++)
- {
- cout<<num[i]<<';';
- }
- cout<<")";
- delete [] num;
- }
- ~Chisla(void)
- {
- }
- };
- Исходный код:
- _________________
- #include <iostream>
- #include <Conio.h>
- #include "Chisla.h"
- using namespace std;
- int main()
- {
- Chisla N1 (5);
- N1.setMas();
- Chisla N2(8);
- N2.setMas(); //создали 2 массива, ввели 2 множества
- /*N1.intersection(N1, N2);*/
- N1.combination(N1, N2);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement