Advertisement
Guest User

Untitled

a guest
May 26th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <string.h>
  5. #include <conio.h>
  6. #include <Windows.h>
  7. #include <iomanip>
  8.  
  9. using namespace std;
  10.  
  11. struct NodeE{
  12. string *data[5];
  13. int amount; // so luong vd
  14. };
  15.  
  16. struct NodeM{
  17. string data;
  18. NodeM *pNext;
  19. };
  20.  
  21. struct ListMean{
  22. NodeM *pFirst;
  23. };
  24.  
  25. struct NodeW{
  26. string word;
  27. string type;
  28. ListMean mean;
  29. NodeE ex;
  30. };
  31.  
  32. struct NodeD{
  33. NodeW data;
  34. NodeD *pLeft;
  35. NodeD *pRight;
  36. };
  37.  
  38. struct HashTable{
  39. NodeD *pHead;
  40. NodeD *pTail;
  41. };
  42.  
  43. HashTable *Dic = new HashTable[26];
  44.  
  45. int HamBam(string str){
  46. return str[0]-97;
  47. }
  48.  
  49. void MakeHashTable(){
  50. for (int i = 0; i < 26; i++){
  51. Dic[i].pHead = NULL;
  52. Dic[i].pTail = NULL;
  53. }
  54. }
  55.  
  56. // Ham Do Hoa
  57. void SetColor(WORD color){
  58. HANDLE hConsoleOutput;
  59. hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  60. CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
  61. GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
  62. WORD wAttributes = screen_buffer_info.wAttributes;
  63. color &= 0x000f;
  64. wAttributes &= 0xfff0;
  65. wAttributes |= color;
  66. SetConsoleTextAttribute(hConsoleOutput, wAttributes);
  67. }
  68. void gotoxy(int x, int y){
  69. HANDLE hConsoleOutput;
  70. COORD Cursor_an_Pos = { x, y };
  71. hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
  72. SetConsoleCursorPosition(hConsoleOutput, Cursor_an_Pos);
  73. }
  74. void textcolor(int x){
  75. HANDLE mau;
  76. mau = GetStdHandle(STD_OUTPUT_HANDLE);
  77. SetConsoleTextAttribute(mau, x);
  78. }
  79. void ShowCur(bool CursorVisibility)
  80. {
  81. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  82. CONSOLE_CURSOR_INFO cursor = { 1, CursorVisibility };
  83. SetConsoleCursorInfo(handle, &cursor);
  84. }
  85. void resizeConsole(int width, int height) {
  86. HWND console = GetConsoleWindow();
  87. RECT r;
  88. GetWindowRect(console, &r);
  89. MoveWindow(console, r.left, r.top, width, height, TRUE);
  90. }
  91. void xoamanhinh{
  92. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  93. HANDLE hConsoleOut;
  94. COORD Home = {0, 0};
  95. DWORD dummy;
  96.  
  97. hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
  98. GetConsoleScreenBufferInfo(hConsoleOut,&csbiInfo);
  99.  
  100. FillConsoleOutputCharacter(hConsoleOut, ' ' , csbiInfo.dwSize.X * csbiInfo.dwSize.Y,Home,&dummy);
  101. csbiInfo.dwCursorPosition.X = 0;
  102. csbiInfo.dwCursorPosition.Y = 0;
  103. SetConsoleCursorPosition(hConsoleOut,csbiInfo.dwCursorPosition);
  104. }
  105. void viet(int x, int y, int z){
  106. gotoxy(x,y);
  107. printf("%c",z);
  108. }
  109.  
  110. void vietchuoi(int x, int y, string s, int mau){
  111. gotoxy(x,y);
  112. textcolor(mau);
  113. cout<<s;
  114. }
  115.  
  116. void AddLastMeanList(ListMean &l, string m){ // them cuoi ds nghia
  117. NodeM *p = new NodeM;
  118. p->pNext = NULL;
  119. p->data = m;
  120.  
  121. NodeM *k = l.pFirst;
  122. if (l.pFirst == NULL){
  123. l.pFirst = p;
  124. }
  125. else{
  126. while (true){
  127. if(k->pNext == NULL){
  128. k->pNext = p;
  129. break;
  130. }
  131. k = k->pNext;
  132. }
  133. }
  134. }
  135.  
  136. void DelFirstMeanList(ListMean &l){ // xoa dau ds nghia cua tu
  137. if (l.pFirst == NULL){
  138. return;
  139. }
  140. NodeM *p = l.pFirst;
  141. l.pFirst = l.pFirst->pNext;
  142. delete p;
  143. }
  144.  
  145. // them vao ds tu dien
  146. void InsertFirstListDic(HashTable &ds, NodeW w){ // them dau ds tu dien
  147. NodeD *p = new NodeD;
  148. p->pLeft = NULL;
  149. p->pRight = NULL;
  150. p->data = w;
  151.  
  152. if (ds.pHead == NULL){
  153. ds.pHead = p;
  154. ds.pTail = p;
  155. }
  156. else{
  157. p->pRight = ds.pHead;
  158. ds.pHead->pLeft = p;
  159. ds.pHead = p;
  160. }
  161. }
  162.  
  163. void InsertLastListDic(HashTable &ds, NodeW w){ // them cuoi ds tu dien
  164. NodeD *p = new NodeD;
  165. p->pLeft = NULL;
  166. p->pRight = NULL;
  167. p->data = w;
  168.  
  169. if (ds.pHead == NULL){
  170. ds.pHead = p;
  171. ds.pTail = p;
  172. }
  173. else{
  174. ds.pTail->pRight = p;
  175. p->pLeft = ds.pTail;
  176. ds.pTail = p;
  177. }
  178. }
  179.  
  180. void InsertAfterListDic(HashTable &ds, NodeW w, NodeW temp){ // them sau ds tu dien
  181. NodeD *p = new NodeD;
  182. p->pLeft = NULL;
  183. p->pRight = NULL;
  184. p->data = w;
  185. NodeD *k = Dic[HamBam(w.word)].pHead;
  186. for (NodeD *k = Dic[HamBam(w.word)].pHead; k != NULL; k = k->pRight){
  187. if (k->data.word == temp.word){
  188. p->pRight = k->pRight;
  189. k->pRight->pLeft = p;
  190. p->pLeft = k;
  191. k->pRight = p;
  192. }
  193. }
  194. }
  195.  
  196. void AddHashTable(NodeW w){ // them hashtable
  197. if (Dic[HamBam(w.word)].pHead == NULL){
  198. InsertFirstListDic(Dic[HamBam(w.word)], w);
  199. }
  200. else if (Dic[HamBam(w.word)].pHead->data.word > w.word){
  201. InsertFirstListDic(Dic[HamBam(w.word)], w);
  202. }
  203. else if (Dic[HamBam(w.word)].pTail->data.word < w.word){
  204. InsertLastListDic(Dic[HamBam(w.word)], w);
  205. }
  206. else{
  207. for (NodeD *k = Dic[HamBam(w.word)].pTail; k != NULL; k = k->pLeft){
  208. if(k->data.word < w.word){
  209. InsertAfterListDic(Dic[HamBam(w.word)], w, k->data);
  210. break;
  211. }
  212. }
  213. }
  214. }
  215.  
  216. bool KT(int KiemTra)// kiem tra xem con tu nao o sau nua khong
  217. {
  218. for (int i = KiemTra; i < 26; i++)
  219. {
  220. if (Dic[i].pHead != NULL)
  221. {
  222. return true;
  223. }
  224. }
  225. return false;
  226. }
  227.  
  228. void tachlayvd(string line, NodeW &w){
  229. string temp;
  230. for (int i = 0; i < line.length(); i++){
  231. if(line[i] == ','){
  232. w.ex.data[w.ex.amount] = new string;
  233. *w.ex.data[w.ex.amount] = temp;
  234. w.ex.amount++;
  235. temp.clear();
  236. }
  237. else
  238. temp.push_back(line[i]);
  239. }
  240. w.ex.data[w.ex.amount] = new string;
  241. *w.ex.data[w.ex.amount] = temp;
  242. w.ex.amount++;
  243. }
  244.  
  245. void tachlaynghia(string x, NodeW &w){
  246. string temp;
  247. for (int i = 0; i < x.length(); i++){
  248. if (x[i] == ','){
  249. AddLastMeanList(w.mean, temp);
  250. temp.clear();
  251. }
  252. else{
  253. temp.push_back(x[i]);
  254. }
  255. }
  256. AddLastMeanList(w.mean, temp);
  257. }
  258.  
  259. // xoa tu
  260. void DelWord(HashTable &ds,NodeD* NodeNow){
  261. // xoa Vd
  262. for (int i = 0; i < NodeNow->data.ex.amount; i++){
  263. delete NodeNow->data.ex.data[i];
  264. }
  265. //xoa nghia
  266. while (NodeNow->data.mean.pFirst != NULL){
  267. DelFirstMeanList(NodeNow->data.mean);
  268. }
  269. //xoa node nut DL list
  270. if (NodeNow == ds.pHead){
  271. if (ds.pHead->pRight == NULL)
  272. {
  273. ds.pHead = NULL;
  274. }
  275. else{
  276. ds.pHead = ds.pHead->pRight;
  277. ds.pHead->pLeft = NULL;
  278. }
  279. }
  280. else if (NodeNow == ds.pTail){
  281. ds.pTail = ds.pTail->pLeft;
  282. ds.pTail->pRight = NULL;
  283. }
  284. else{
  285. NodeNow->pRight->pLeft = NodeNow->pLeft;
  286. NodeNow->pLeft->pRight = NodeNow->pRight;
  287. }
  288. delete NodeNow;
  289. }
  290.  
  291. void bangmenu(int x, int y, int m, int n, int mau){
  292. int i,j;
  293. textcolor(mau);
  294. for (i = x; i <= x + m; i++){
  295. for(j = y; j <= y + n; j++){
  296. if(i == x || i == x+m){
  297. if(j == y && i != x + m)
  298. viet(i, j, 218);
  299. else if( j == y && i != x)
  300. viet(i, j, 191);
  301. else if( j == y + n && i != x + m)
  302. viet(i, j, 192);
  303. else if( j == y + n && i != x)
  304. viet(i, j, 217);
  305. else
  306. viet(i, j, 179);
  307. }
  308. else if(j == y || j == y + n)
  309. viet(i, j, 196);
  310. }
  311. }
  312. }
  313.  
  314.  
  315. void menutimkiem(int x, int y){
  316. int i, j;
  317. for (i = x; i <= x + 80; i++){
  318. for (j = y; j <= y + 25; j++){
  319. if (i == x || i == x + 30 || i == x + 80){
  320. if (j == y && i != x && i != x + 80)
  321. viet(i, j, 203);
  322. else if (j == y && i != x + 80)
  323. viet(i, j, 201);
  324. else if (j == y && i != x)
  325. viet(i, j, 187);
  326. else if (j == y + 25 && i != x && i != x + 80)
  327. viet(i, j, 202);
  328. else if (j == y + 25 && i != x + 80)
  329. viet(i, j, 200);
  330. else if (j == y + 25 && i != x)
  331. viet(i, j, 188);
  332. else if (j == y + 4 && i != x + 30 && i != x + 80)
  333. viet(i, j, 204);
  334. else if (j == y + 4 && i != x && i != x + 30)
  335. viet(i, j, 185);
  336. else if (j == y + 4 && i != x && i != x + 80)
  337. viet(i, j, 206);
  338. else
  339. viet(i, j, 186);
  340. }
  341. else if (j == y || j == y + 25 || j == y + 4)
  342. viet(i, j, 205);
  343. }
  344. }
  345. }
  346.  
  347. int batphim()
  348. {
  349. int c=getch();
  350. if(c==8) //phim Backspace
  351. return 1;
  352. else if(c==9) //phim Tab
  353. return 2;
  354. else if(c==13) //phim Enter
  355. return 3;
  356. else if(c==27) //phim Esc
  357. return 4;
  358. else if(c==224)
  359. {
  360. c=getch();
  361. if(c==72) //Keyup
  362. return 5;
  363. else if(c==80) //KeyDown
  364. return 6;
  365. else if(c==75) //KeyLeft
  366. return 7;
  367. else if(c==77) //KeyRight
  368. return 8;
  369. else if(c==83) //Delete
  370. return 9;
  371. }
  372. else if(c==0)
  373. {
  374. c=getch();
  375. if(c==60) //F2
  376. return 12;
  377. if(c==62) //F4
  378. return 13;
  379. }
  380. }
  381.  
  382. int menuXOA(int x, int y){
  383. //NodeW w;
  384. vietchuoi(x+20,y+5,"Ban co muon xoa tu nay khong? Chon [CO] hoac [KHONG].",12);
  385. bangmenu(x+51,y+8,10,4,2);
  386. vietchuoi(x+55,y+10,"CO",14);
  387. vietchuoi(x+73,y+10,"KHONG",15);
  388. int kt=1;
  389. gotoxy(x+80,y+7);
  390. for(;;){
  391. gotoxy(x+80,y+7);
  392. int h=batphim();
  393. if(h==8){ //phim sang phai
  394. if(kt==1){
  395. kt=2;
  396. bangmenu(x+51,y+8,10,4,0);
  397. vietchuoi(x+55,y+10,"CO",15);
  398. bangmenu(x+70,y+8,10,4,2);
  399. vietchuoi(x+73,y+10,"KHONG",14);
  400. }
  401. else if(kt==2){
  402. kt=1;
  403. bangmenu(x+51,y+8,10,4,2);
  404. vietchuoi(x+55,y+10,"CO",14);
  405. bangmenu(x+70,y+8,10,4,0);
  406. vietchuoi(x+73,y+10,"KHONG",15);
  407. }
  408. }
  409. else if(h==7){ //phim sang trai
  410. if(kt==1){
  411. kt=2;
  412. bangmenu(x+51,y+8,10,4,0);
  413. vietchuoi(x+55,y+10,"CO",15);
  414. bangmenu(x+70,y+8,10,4,2);
  415. vietchuoi(x+73,y+10,"KHONG",14);
  416. }
  417. else if(kt==2){
  418. kt=1;
  419. bangmenu(x+51,y+8,10,4,2);
  420. vietchuoi(x+55,y+10,"CO",14);
  421. bangmenu(x+70,y+8,10,4,0);
  422. vietchuoi(x+73,y+10,"KHONG",15);
  423. }
  424. }
  425. else if(h==3){ //phim enter
  426. if(kt==1){
  427. return 1;
  428. }
  429. else if(kt==2){
  430. return 2;
  431. }
  432. }
  433. }
  434. }
  435.  
  436. void menumain();
  437. void menuthemtu(int x, int y){
  438. int i,j;
  439. for (i = x; i <= x + 80; i++){
  440. for (j = y; j <= y + 25; j++){
  441. if (i == x || i == x + 80){
  442. if (j == y && i != x + 80)
  443. viet(i, j, 201);
  444. else if (j == y && i != x)
  445. viet(i, j, 187);
  446. else if (j == y + 25 && i != x && i != x + 80)
  447. viet(i, j, 202);
  448. else if (j == y + 25 && i != x + 80)
  449. viet(i, j, 200);
  450. else if (j == y + 25 && i != x)
  451. viet(i, j, 188);
  452. else
  453. viet(i, j, 186);
  454. }
  455. else if (j == y || j == y + 25)
  456. viet(i, j, 205);
  457. }
  458. }
  459. vietchuoi(x+5,y+2,"1> Nhap tu moi: ",6);
  460. vietchuoi(x+5,y+4,"2> Tu loai: ",6);
  461. vietchuoi(x+5,y+6,"3> Nghia: ",6);
  462. vietchuoi(x+5,y+14,"4> Vi du: ",6);
  463. vietchuoi(x+10,y+16,"a> vd1: ",6);
  464. }
  465.  
  466. int MenuChucNang(int x, int y){
  467. int kt=0;
  468. HashTable ds;
  469. NodeD *NodeNow = new NodeD;
  470. bangmenu(x,y+21,80,4,10);
  471. bangmenu(x+2,y+22,10,2,14);
  472. vietchuoi(x+4,y+23,"THEM TU",15);
  473. vietchuoi(x+20,y+23,"SUA TU",6);
  474. vietchuoi(x+35,y+23,"XOA TU",6);
  475. vietchuoi(x+50,y+23,"THOAT",6);
  476. gotoxy(x+50,28);
  477. for(;;){
  478. int h=batphim();
  479. gotoxy(x+50,28);
  480. if(h==8){ //right
  481. if(kt==0){
  482. kt=1;
  483. bangmenu(x+2,y+22,10,2,0);
  484. vietchuoi(x+4,y+23,"THEM TU",6);
  485. bangmenu(x+18,y+22,10,2,14);
  486. vietchuoi(x+20,y+23,"SUA TU",15);
  487. vietchuoi(x+35,y+23,"XOA TU",6);
  488. vietchuoi(x+50,y+23,"THOAT",6);
  489. }
  490. else if(kt==1){
  491. kt=2;
  492. vietchuoi(x+4,y+23,"THEM TU",6);
  493. bangmenu(x+18,y+22,10,2,0);
  494. vietchuoi(x+20,y+23,"SUA TU",6);
  495. bangmenu(x+33,y+22,10,2,14);
  496. vietchuoi(x+35,y+23,"XOA TU",15);
  497. vietchuoi(x+50,y+23,"THOAT",6);
  498. }
  499. else if(kt==2){
  500. kt=3;
  501. vietchuoi(x+4,y+23,"THEM TU",6);
  502. vietchuoi(x+20,y+23,"SUA TU",6);
  503. bangmenu(x+33,y+22,10,2,0);
  504. vietchuoi(x+35,y+23,"XOA TU",6);
  505. bangmenu(x+48,y+22,10,2,14);
  506. vietchuoi(x+50,y+23,"THOAT",15);
  507. }
  508. else if(kt==3){
  509. kt=0;
  510. bangmenu(x+2,y+22,10,2,14);
  511. vietchuoi(x+4,y+23,"THEM TU",15);
  512. vietchuoi(x+20,y+23,"SUA TU",6);
  513. vietchuoi(x+35,y+23,"XOA TU",6);
  514. bangmenu(x+48,y+22,10,2,0);
  515. vietchuoi(x+50,y+23,"THOAT",6);
  516. }
  517. }
  518. else if(h==7){ //left
  519. if(kt==0){
  520. kt=3;
  521. bangmenu(x+2,y+22,10,2,0);
  522. vietchuoi(x+4,y+23,"THEM TU",6);
  523. vietchuoi(x+20,y+23,"SUA TU",6);
  524. vietchuoi(x+35,y+23,"XOA TU",6);
  525. bangmenu(x+48,y+22,10,2,14);
  526. vietchuoi(x+50,y+23,"THOAT",15);
  527. }
  528. else if(kt==3){
  529. kt=2;
  530. vietchuoi(x+4,y+23,"THEM TU",6);
  531. vietchuoi(x+20,y+23,"SUA TU",6);
  532. bangmenu(x+33,y+22,10,2,14);
  533. vietchuoi(x+35,y+23,"XOA TU",15);
  534. bangmenu(x+48,y+22,10,2,0);
  535. vietchuoi(x+50,y+23,"THOAT",6);
  536. }
  537. else if(kt==2){
  538. kt=1;
  539. vietchuoi(x+4,y+23,"THEM TU",6);
  540. bangmenu(x+18,y+22,10,2,14);
  541. vietchuoi(x+20,y+23,"SUA TU",15);
  542. bangmenu(x+33,y+22,10,2,0);
  543. vietchuoi(x+35,y+23,"XOA TU",6);
  544. vietchuoi(x+50,y+23,"THOAT",6);
  545. }
  546. else if(kt==1){
  547. kt=0;
  548. bangmenu(x+2,y+22,10,2,14);
  549. vietchuoi(x+4,y+23,"THEM TU",15);
  550. bangmenu(x+18,y+22,10,2,0);
  551. vietchuoi(x+20,y+23,"SUA TU",6);
  552. vietchuoi(x+35,y+23,"XOA TU",6);
  553. vietchuoi(x+50,y+23,"THOAT",6);
  554. }
  555. }
  556. else if(h==3){ //enter
  557. if(kt==0){
  558. xoamanhinh();
  559. menuthemtu(x,y);
  560. system("pause");
  561. xoamanhinh();
  562. menumain();
  563.  
  564. }
  565. else if(kt==1){
  566. xoamanhinh();
  567. menuthemtu(x,y);
  568. system("pause");
  569. xoamanhinh();
  570. menumain();
  571. }
  572. else if(kt==2){
  573. xoamanhinh();
  574. menuXOA(x,y);
  575. system("pause");
  576. xoamanhinh();
  577. menumain();
  578. }
  579. else if(kt==3){
  580. gotoxy(8,22);
  581. MessageBox(0, "Dang thoat chuong trinh!", "THONG BAO", MB_OK);
  582. gotoxy(x+5,y+26);
  583. exit(0);
  584. }
  585. }
  586. }
  587. }
  588.  
  589. //YEU CAU
  590. //TIM KIEM
  591. bool SoSanh (string input, string y){
  592. string x = input;
  593. if (x.length() > y.length()){
  594. return false;
  595. }
  596. else{
  597. for (int i =0;i<x.length();i++){
  598. if (x[i]!=y[i]){
  599. return false;
  600. }
  601. }
  602. return true;
  603. }
  604. }
  605. NodeD* Search(string lookup){
  606. int x=HamBam(lookup);
  607. if(x<0){
  608. return NULL;
  609. }
  610. else{
  611. NodeD *p=Dic[x].pHead;
  612. while(p!=NULL)
  613. {
  614. // if(p->data.word.compare(0,lookup.size(),lookup)==0)
  615. if (SoSanh(lookup,p->data.word))
  616. {
  617. return p;
  618. }
  619. p=p->pRight;
  620. }
  621. return NULL;
  622. }
  623. }
  624.  
  625. // xoa man hinh
  626. void DelScreen(int X, int Y, int cd, int cr){
  627. ShowCur(0);
  628. textcolor(7);
  629. for (int i = Y; i < cr + Y; i++){
  630. for (int j = X; j < X + cd; j++){
  631. gotoxy(j, i);
  632. cout << " ";
  633. }
  634. }
  635. }
  636.  
  637. void Xuat1Tu(NodeW w){
  638. DelScreen(37, 15, 48, 12);
  639. gotoxy(37, 17);
  640. cout << w.word << "(" << w.type << ")" << ":";
  641. for (NodeM *k = w.mean.pFirst; k != NULL; k = k->pNext){
  642. cout << k->data;
  643. if (k->pNext != NULL){
  644. cout << ",";
  645. }
  646. }
  647. gotoxy(37, 18);
  648. cout << "VD:";
  649. int j = 19;
  650. for (int i = 0; i < w.ex.amount; i++){
  651. gotoxy(37, j++);
  652. cout << *w.ex.data[i];
  653. }
  654. gotoxy(40, 26);
  655. system("pause");
  656. DelScreen(37, 15, 48, 12);
  657. }
  658.  
  659. void XuLyNhapChu(string &x, int X, int &Y){
  660. ShowCur(1);
  661. while (true){
  662. char c = _getch();
  663. if (((c >= 97 && c <= 122) || c==44 )&& x.length() < X + 47){
  664. x.push_back(c);
  665. cout << c;
  666. }
  667. else if (((c >= 65 && c <= 90) || c==44) && x.length() < X + 47){
  668. c = c + 32;
  669. x.push_back(c);
  670. cout << c;
  671. }
  672. else if (c == 8 && x.length() > 0){
  673. x.erase (x.begin() + x.length()-1);
  674. cout << "\b";
  675. cout << " ";
  676. cout << "\b";
  677. }
  678. else if (c == 32){
  679. x.push_back(' ');
  680. cout << " ";
  681. }
  682. else if (c == 13 && x.length() > 0){ // n?u là phím enter
  683. Y = Y + 3;
  684. return ;
  685. }
  686. else if (c == -32){
  687. c = getch();
  688. if (c == 80){
  689. Y = Y + 3;
  690. break;
  691. }
  692. else if (c == 72){
  693. Y = Y - 3;
  694. break;
  695. }
  696. }
  697. else if (c == 27)
  698. {
  699. return ;
  700. }
  701. }
  702. }
  703.  
  704.  
  705. void GhiFile(){
  706. string mean, ex;
  707. ifstream filein;
  708. filein.open("TU-DIEN-2017.txt", ios_base::in);
  709. if (filein.fail() == true){
  710. cout << "\nFile ko ton tai\n";
  711. system("pause");
  712. }
  713.  
  714. while (true){
  715. NodeW w;
  716. w.ex.amount = 0;
  717. w.mean.pFirst = NULL;
  718.  
  719. getline(filein, w.word, '/');
  720. cout<<w.word<<" "<<endl;
  721. getline(filein, w.type, '/');
  722. getline(filein, mean, '/');
  723. getline(filein, ex, '/');
  724.  
  725. if(w.word.empty()){
  726. break;
  727. }
  728. tachlaynghia(mean, w);
  729. tachlayvd(ex, w);
  730. AddHashTable(w);
  731.  
  732. filein.ignore();
  733. }
  734. filein.close();
  735. }
  736.  
  737. void DocFile(){
  738. ofstream fileout("TU-DIEN-2017.txt", ios::out);
  739. for (int i = 0; i < 26; i++){
  740. for (NodeD *k = Dic[i].pHead; k != NULL; k = k->pRight){
  741. fileout << k->data.word << "/" << k->data.type << "/";
  742. for (NodeM* h = k->data.mean.pFirst; h != NULL; h = h->pNext){
  743. if (h->pNext != NULL){
  744. fileout << h->data << "/";
  745. }
  746. else
  747. fileout << h->data << "/";
  748. }
  749. for (int j = 0; j < k->data.ex.amount; j++){
  750. if (j == k->data.ex.amount - 1){
  751. fileout << *k->data.ex.data[j] << ";";
  752. }
  753. else
  754. fileout << *k->data.ex.data[j] << ",";
  755. }
  756. fileout << endl;
  757. }
  758. }
  759. fileout.close();
  760. }
  761.  
  762. void GiaiPhongBoNho(){
  763. NodeD* k;
  764. for (int i = 0; i < 26; i++){
  765. while(Dic[i].pHead!=NULL){
  766. k = Dic[i].pHead;
  767.  
  768. // xoa Vd
  769. for (int j = 0; j < k->data.ex.amount; j++){
  770. delete k->data.ex.data[j];
  771. }
  772.  
  773. //xoa nghia
  774. while (k->data.mean.pFirst != NULL){
  775. DelFirstMeanList(k->data.mean);
  776. }
  777.  
  778. // xoa tu
  779. if (Dic[i].pHead->pRight == NULL){
  780. Dic[i].pHead = NULL;
  781. }
  782. else
  783. {
  784. Dic[i].pHead = Dic[i].pHead->pRight;
  785. Dic[i].pHead->pLeft = NULL;
  786. }
  787. delete k;
  788. }
  789. }
  790. delete[]Dic;
  791. }
  792.  
  793. void menumain(){
  794. int x, y;
  795. bangmenu(37,1,67,2,11);
  796. vietchuoi(65, 2, "TRA TU DIEN", 9);
  797. textcolor(2);
  798. menutimkiem(x = 30, y = 6);
  799. gotoxy(x+5, y+26);
  800. cout << endl;
  801. MenuChucNang(x,y+7);
  802. }
  803.  
  804. int main(){
  805. resizeConsole(1100,650);
  806. menumain();
  807. // MakeHashTable();
  808. // GhiFile();
  809. /*
  810. for(int i=0;i<26;i++){
  811. for(NodeD* k = Dic[i].pHead;k!=NULL;k=k->pRight){
  812. cout<<k->data.word<<endl;
  813. }
  814. }*/
  815. // DocFile();
  816.  
  817. // system ("pause");
  818. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement