Advertisement
Guest User

Untitled

a guest
May 25th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.90 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. struct WordCard{
  8. string slovo,perevod;
  9. };
  10.  
  11. class dictionary{
  12. private:
  13. string name;
  14. WordCard *mas;
  15. int size,count;
  16. public:
  17. dictionary(){
  18. cout<<"ZAPOLNENIE SLOVARYA!"<<endl;
  19. cout<<"Vvedite nazvanie slovarya : ";
  20. cin>>name;
  21. do{
  22. cout<<"Vvedite maximal`noe kolichestvo slov v slovare : ";cin>>size;
  23. mas = new WordCard[size+1];
  24. cout<<"Vvedite skolko slov vu xotite vvesti seuchas : ";cin>>count;--count;
  25. if(count>size)
  26. cout<<"eror,kolichestvo ne mojet but` bolshe razmera slovarya!"<<endl;
  27. else{
  28. for(int i = 0;i<count+1;i++){
  29. string tmp;
  30. bool fnd = true;
  31. if(i==0){
  32. cout<<"Vvedite slovo : ";
  33. cin>>tmp;
  34. }
  35. if(i>=1){
  36. do{
  37. cout<<"Vvedite slovo : ";
  38. cin>>tmp;
  39. if(find(tmp,1)==true){
  40. cout<<"Slovo uje est` v slovare!"<<endl;
  41. fnd = false;
  42. }
  43. else if(find(tmp,1)==false)
  44. fnd=true;
  45. }while(fnd==false);
  46. }
  47. mas[i].slovo = tmp;
  48. cout<<"Vvedite perevod : ";
  49. cin>>mas[i].perevod;
  50. }
  51. }
  52. cout<<endl<<"NAZAVANIE SLOVARYA : "<<name<<endl;
  53. for(int i = 0;i<count+1;i++){
  54. cout<<mas[i].slovo<<" " <<mas[i].perevod<<endl;
  55. }
  56. }while(count>size);
  57. }
  58. dictionary(int n){size = n; count = -1;mas = new WordCard[n+1];name = "SLOVAR` - REZULTAT";}
  59. int getSize(){return this->size;}
  60. int getCount(){return this->count+1;}
  61. void change (){
  62. cout<<"Nazvanie : "<<this->name;
  63. cout<<"Izmenit nazvanie na : ";cin>>this->name;
  64. cout<<"Nazvanie slovarya izmeneno na : "<<this->name;
  65. }
  66. void add(){
  67. if(count+1<size){
  68. ++count;
  69. cout<<"Vvedite slovo : ";
  70. cin>>mas[count].slovo;
  71. cout<<"Vvedite perevod slova : ";
  72. cin>>mas[count].perevod;
  73. }
  74. else
  75. cerr<<"Nelzya dobavit elemnt!"<<endl;
  76.  
  77. }
  78. WordCard &operator[] (string fnd){
  79. for(int i = 0;i<count+1;i++){
  80. if(mas[i].slovo == fnd)
  81. return mas[i];
  82. }
  83. }
  84. void show(){
  85. cout<<"NAZVANIE SLOVARYA : "<<this->name<<endl;
  86. for(int i = 0;i<count+1;i++){
  87. cout<<"Slovo : "<<mas[i].slovo<<endl;
  88. cout<<"Perevod : "<<mas[i].perevod<<endl;
  89. }
  90. }
  91. void remove () {
  92. char ch;
  93. int tmp = count+1;
  94. int i = 0;
  95. do{
  96. cout<<"Slovo : "<<mas[i].slovo<<endl<<"Perevod : "<<mas[i].perevod<<endl;
  97. cout<<"Udalit eto slovo?\n1 - da\n2 - net"<<endl;
  98. ch = _getch();
  99. switch(ch){
  100. case'1':
  101. for(int j = i;j<tmp;j++){
  102. mas[j] = mas[j+1];
  103. }
  104. mas[size-1].perevod = "";
  105. mas[size-1].slovo= "";
  106. --count;
  107. if(i!=0)
  108. i--;
  109. break;
  110. case '2':
  111. i++;
  112. break;
  113. }
  114. }while(i!=count+1);
  115. }
  116. void changeName(){
  117. cout<<"Vu xotite izmenit` nazvanie slovarya "<<this->name;
  118. cout<<"Vvedite novoe nazvanie : ";cin>>name;
  119. }
  120. WordCard find(string fnd){
  121. bool t;
  122. for(int i = 0;i<count+1;i++){
  123. if(mas[i].slovo==fnd)
  124. {
  125. t = true;
  126. return mas[i];
  127. }
  128. }
  129. if(t==false)
  130. cout<<"takogo slova netu v slovare!"<<endl;
  131. }
  132. bool find(string fnd,int a){
  133. for(int i = 0;i<count+1;i++){
  134. if(mas[i].slovo==fnd)
  135. {
  136. return true;
  137. }
  138. }
  139. return false;
  140. }
  141. void add(string slovo,string perevod){
  142. if(count+1<size){
  143. count++;
  144. mas[count].slovo = slovo;
  145. mas[count].perevod = perevod;
  146. }
  147. else
  148. cout<<"Perepolnenie!"<<endl;
  149. }
  150. dictionary deleteDuplicate(){
  151. for(int i = 0;i<count+1;i++){
  152. for(int j = i+1;j<count+1;j++){
  153. if(mas[i].slovo == mas[j].slovo)
  154. {
  155. for(int z = j;z<count;z++){
  156. mas[z] = mas[z+1];
  157. }
  158. count-=1;
  159. }
  160. }
  161. }
  162. return *this;
  163. }
  164. dictionary obedninenie(dictionary &a){
  165. dictionary tmp(255);
  166. for(int i = 0;i<count+1;i++){
  167. tmp.add(this->mas[i].slovo,this->mas[i].perevod);
  168. }
  169. for(int i = 0;i<a.count+1;i++){
  170. tmp.add(a.mas[i].slovo,a.mas[i].perevod);
  171. }
  172. tmp.deleteDuplicate();
  173. return tmp;
  174. };
  175. dictionary peresechenie(dictionary &a){
  176. dictionary q(255);
  177. for(int i = 0;i<count+1;i++){
  178. if(a.find(mas[i].slovo,1) == true)
  179. {
  180. q.add(mas[i].slovo,mas[i].perevod);
  181. }
  182. }
  183. return q;
  184. }
  185. dictionary vuchitanie(dictionary &a){
  186. dictionary tmp(255);
  187. for(int i = 0;i<count;i++){
  188. if(!a.find(mas[i].slovo,1))
  189. {
  190. tmp.add(mas[i].slovo,mas[i].perevod);
  191. }
  192. }
  193. return tmp;
  194. }
  195. string getName(){return name;};
  196. bool sravnenieName(dictionary& a){
  197. if(a.getName() == this->getName())
  198. return true;
  199. return false;
  200. }
  201.  
  202. };
  203. /*
  204. задача 10 стр 43
  205. */
  206.  
  207.  
  208. void main (){
  209. dictionary c(255),d(255),a,b;
  210. char ch,slovar;
  211. do{
  212. cout<<endl<<endl<<"1 - vuvesti informacuy pro slovar`"
  213. "\n2 - izmenit` nazvanie slovarya"
  214. "\n3 - dobavit slovo"
  215. "\n4 - udalit` slovo"
  216. "\n5 - ob`edinenie"
  217. "\n6 - peresichenie"
  218. "\n7 - vuchitanie"
  219. "\n8 - exit";
  220. ch = _getch();
  221. switch(ch){
  222. case'1':
  223. cout<<endl;
  224. cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
  225. cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
  226. slovar = _getch();
  227. if(slovar=='1'){
  228. cout<<"Informacuya pro slovar` : "<<a.getName()<<endl;
  229. a.show();
  230. }
  231. else if(slovar=='2'){
  232. cout<<"Informacuya pro slovar` : "<<b.getName()<<endl;
  233. b.show();
  234.  
  235. }
  236. break;
  237. case'2':
  238. cout<<endl;
  239. cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
  240. cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
  241. slovar = _getch();
  242. if(slovar=='1'){
  243. a.change();
  244. }
  245. else if(slovar=='2'){
  246. b.change();
  247. }
  248. break;
  249. case'3':
  250. cout<<endl;
  251. cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
  252. cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
  253. slovar = _getch();
  254. if(slovar=='1'){
  255. cout<<"Dobavlenie slova v slovar` : "<<a.getName()<<endl;
  256. a.add();
  257. }
  258. else if(slovar=='2'){
  259. cout<<"Dobavlenie slova v slovar` : "<<b.getName()<<endl;
  260. b.add();
  261. }
  262. break;
  263. case'4':
  264. cout<<endl;
  265. cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
  266. cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
  267. slovar = _getch();
  268. if(slovar=='1'){
  269. cout<<"Udalenie slova v slovar` : "<<a.getName()<<endl;
  270. a.remove();
  271. }
  272. else if(slovar=='2'){
  273. cout<<"Udalenie slova v slovar` : "<<b.getName()<<endl;
  274. b.remove();
  275. }
  276. break;
  277. case'5':
  278. cout<<endl;
  279. {
  280. dictionary tmp(255);
  281. cout<<"1 - dlya rabotu so slovarem : "<<a.getName()<<endl;
  282. cout<<"2 - dlya rabotu so slovarem : "<<b.getName()<<endl;
  283. slovar = _getch();
  284. if(slovar=='1'){
  285. cout<<"Ob`edinit slovarya "<<a.getName()<<"so slovarem"<<b.getName()<<endl;
  286. tmp = a.obedninenie(b);
  287. tmp.show();
  288. }
  289. else if(slovar=='2'){
  290. cout<<"Ob`edinit slovarya "<<b.getName()<<"so slovarem "<<a.getName()<<endl;
  291. tmp = b.obedninenie(a);
  292. tmp.show();
  293. }
  294. break;
  295. }
  296. case'6':{
  297. cout<<endl;
  298. dictionary tmp(255);
  299. cout<<"1 - dlya naxojdeniya peresicheniya slovarya "<<a.getName()<<" so slovarem "<<b.getName()<<endl;
  300. cout<<"2 - dlya naxojdeniya peresecheniya slovarya "<<b.getName()<<" so slovarem "<<a.getName()<<endl;
  301. slovar = _getch();
  302. if(slovar=='1'){
  303. a.show();
  304. b.show();
  305. tmp = a.peresechenie(b);
  306.  
  307. tmp.show();
  308. }
  309. else if(slovar=='2'){
  310. tmp = b.peresechenie(a);
  311. tmp.show();
  312. }
  313. break;
  314. }
  315. case'7':{
  316. cout<<endl;
  317. dictionary tmp(255);
  318. cout<<"1 - dlya vuchitaniya iz slovarya "<<a.getName()<<" slovarya "<<b.getName()<<endl;
  319. cout<<"2 - dlya vuchitaniya iz slovarya "<<b.getName()<<" slovarya "<<a.getName()<<endl;
  320. slovar = _getch();
  321. if(slovar=='1'){
  322. tmp = a.vuchitanie(b);
  323. tmp.show();
  324. }
  325. else if(slovar=='2'){
  326. tmp = b.vuchitanie(a);
  327. tmp.show();
  328. }
  329. break;
  330. }
  331. case'8':exit;
  332. }
  333. }while(ch!='8');
  334. system("pause>>void");
  335. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement