-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unit1.cpp
137 lines (121 loc) · 5.48 KB
/
Unit1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//---------------------------------------------------------------------------
#include <vcl.h>
#include <iostream.h>
#include <conio.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "Unit2.h"
#pragma argsused
int main(int argc, char* argv[])
{
int x, z, y, nummn, numelmax, kolvonezmn, nummnforunion;
char answer;
cout<<"vvedite max kolichestvo mnozestv"<<endl;
cin>>nummn;
nummnforunion=kolvonezmn=nummn;
nummn=nummn+5; //äîáàâëÿåì åù¸ ïÿòü ìíîæåñòâ äëÿ îïåðàöèè îáúåäèíåíèÿ
cout<<"vvedite max kolichestvo elementov vo mnozestve"<<endl;
cin>>numelmax;
Structure(nummn, numelmax);
int number;
while(1){
cout<<endl<<"1-new set\n2-add elements\n3-union\n4-find set\n5-show sets\n0-exit"<<endl;
cin>>number;
switch(number){
case 1: //ñîçäàíèå íîâîãî ìíîæåñòâà
cout<<endl<<"max kolichestvo mnozestv="<<kolvonezmn<<endl;
M:
if(kolvonezmn==0){
cout<<endl<<"limit mnozestv!"<<endl;
break;
}
else{
cout<<endl<<"vvedite predstavitela"<<endl;
cin>>x;
z=Make_Set(x ,nummn, numelmax);
if(z==2){
cout<<endl<<"False input"<<endl<<"Try again?(y/n)"<<endl;
cin>>answer;
if(answer=='y') goto M;
if(answer=='n') break;
}
else{
kolvonezmn=kolvonezmn-1; //êîëè÷åñòâî íåçàäåéñòâîâàííûõ ìíîæåñòâ
cout<<endl<<"Successfull!"<<endl<<"Would you like to add elements?(y/n)"<<endl;
cin>>answer;
if(answer=='y') goto L;
if(answer=='n') break;
}
}
break;
case 2:
L:
cout<<endl<<"vvedite lybo'i element mnozestva i vnosimiy v eto mnozestvo element"<<endl;
cin>>x>>y;
z=Add_Element(x, y, nummn);
if(z==1){
cout<<endl<<"Successfull! Would you like to add another element?(y/n)"<<endl;
cin>>answer;
if(answer=='y') goto L;
if(answer=='n') break;
}
if(z==2){
cout<<endl<<"False input. Would you like to try other predstavitel?(y/n)";
cin>>answer;
if(answer=='n') break;
if(answer=='y') goto L;
}
if(z==3){
cout<<endl<<"Wrong input(this element is already exist). Would you like to try other element?(y/n)";
cin>>answer;
if(answer=='n') break;
if(answer=='y') goto L;
}
break;
case 3:
cout<<endl<<"vvedite po odnomy elementy dvyx mnozestv"<<endl;
cin>>x>>y;
z=Union(x, y, nummn, numelmax, nummnforunion);
if(z==1){
cout<<endl<<"Successfull!"<<endl;
kolvonezmn=kolvonezmn+2;
}
if(z==2) cout<<endl<<"False input"<<endl;
if(z==3) cout<<endl<<"Vvedeny elementy odnogo mnozestva"<<endl;
if(z==4) cout<<endl<<"Nedostatochno mnozestv"<<endl;
break;
case 4:
int z1, z2;
cout<<endl<<"vvedite element mnozestva"<<endl;
cin>>x;
z1=Find_Set(x, nummn);
if(z1<0){
cout<<endl<<"False input!"<<endl;
break;
}
else{
z2=Find_Set_Predst(x, nummn);
cout<<endl<<"etot element-element mnozestva s predstvitelem: "<<z2<<endl;
}
break;
case 5:
cout<<endl<<"What do you want to see?(1-all sets 2-certain set)"<<endl;
cin>>answer;
if(answer=='1'){
z=All_Sets(nummn);
if(z==2) cout<<"There are no sets!"<<endl;
}
if(answer=='2'){
cout<<endl<<"vvedite element mnozestva"<<endl;
cin>>x;
z=Certain_Set(x, nummn);
if(z==2) cout<<"There is no such set!"<<endl;
}
break;
default:
return 0;
}
}
getch();
}
//---------------------------------------------------------------------------