Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<cstring>
  4. using namespace std;
  5.  
  6. bool logiranje(char *&adminPass, char *&pass) {
  7. char c = 0;
  8. int counter = 0;
  9. pass = new char[20];
  10. cout << "Unesi password: ";
  11. do {
  12. while (c != '\r')
  13. {
  14. c = _getch();
  15. if (c == '\0')
  16. continue;
  17. pass[counter] = c;
  18. counter++;
  19. cout << "*";
  20. }
  21. pass[counter] = '\0';
  22. if (strcmp(adminPass, pass) == 0) {
  23. delete[]pass;
  24. pass = nullptr;
  25. return true;
  26. }
  27. else {
  28. cout << "Pokusaj opet" << endl;
  29. }
  30. } while (strcmp(adminPass,pass)!=0);
  31. }
  32. void OslobodiMemoriju(char *&tekst) {
  33. delete[] tekst;
  34. tekst = nullptr;
  35. cout << "Info: Memorija oslobodjena" << endl;
  36. }
  37. int PrikaziMeni() {
  38. int izbor = 1;
  39. do {
  40. cout << "Meni" << endl;
  41. cout << "1. Unos novog teksta" << endl;
  42. cout << "2. dodavanje teksta" << endl;
  43. cout << "3. informacije o tekstu" << endl;
  44. cout << "4. pretraga" << endl;
  45. cout << "5. zatvori editor" << endl;
  46. cout << "Unesi izbor: ";
  47. cin >> izbor;
  48. cin.ignore();
  49. system("cls");
  50. } while (izbor < 1 || izbor>5);
  51. return izbor;
  52. }
  53. void UnosTeksta(char *& tekst) {
  54. const int max = 300;
  55. char temp[max];
  56.  
  57. cout << "Unesite tekst: ";
  58. cin.getline(temp, max);
  59. /*if (tekst != nullptr)
  60. OslobodiMemoriju(tekst);*/
  61. int vel = strlen(temp) + 1;
  62. tekst = new char[vel];
  63. strcpy_s(tekst, vel, temp);
  64. }
  65. void DodajTekst(char *& tekst) {
  66. const int max = 300;
  67. char temp[max];
  68. cout << "Dodaj tekst" << endl;
  69. cout << tekst << " ";
  70. cin.getline(temp, max);
  71. int vel = strlen(tekst) + strlen(temp) + 2;
  72. char *novitekst = new char[vel];
  73. strcpy_s(novitekst, vel, tekst);
  74. strcat_s(novitekst, vel, " ");
  75. strcpy_s(novitekst, vel, temp);
  76.  
  77. OslobodiMemoriju(tekst);
  78. tekst = novitekst;
  79.  
  80. cout << "Info: tekst dodan" << endl;
  81. }
  82. void Informacije(char * tekst) {
  83. int razmaci = 0, mala = 0, velika = 0, interpunkcijski = 0, brojevi = 0;
  84. int vel = strlen(tekst);
  85. for (int i = 0; i < vel; i++)
  86. {
  87. if (isspace(tekst[i]))
  88. razmaci++;
  89. else if (isdigit(tekst[i]))
  90. brojevi++;
  91. else if (islower(tekst[i]))
  92. mala++;
  93. else if (isupper(tekst[i]))
  94. velika++;
  95. else if (ispunct(tekst[i]))
  96. interpunkcijski++;
  97. }
  98. cout << "Info" << endl;
  99. cout << "Niz ima: " << strlen(tekst) << "karaktera" << endl;
  100. cout << "Razmaka ima: " << razmaci << endl;
  101. cout << "Malih slova ima: " << mala << endl;
  102. cout << "Velikih slova ima: " << velika << endl;
  103. cout << "Interpunckijski znakova ima: " << interpunkcijski << endl;
  104. cout << "Info: informacije prikazane" << endl;
  105. }
  106. void Pretraga(char *tekst) {
  107. const int max = 20;
  108. char temp[max];
  109. char nastavak;
  110. cout << "Pretraga" << endl;
  111. cout << "Unesite tekst koji trazite: ";
  112. cin.getline(temp, max);
  113. char *pok = strstr(tekst, temp);
  114. if (pok == NULL)
  115. cout << "Tekst " << temp << " nije pronadjen" << endl;
  116. else {
  117. cout << "Tekst " << temp << " je pronadjen" << endl;
  118. cout << "Da li zelite prikazati sadrzaj koji se nalazi nakon pronadjenog teksta (D/N): ";
  119. cin >> nastavak;
  120. if (toupper(nastavak) == 'D')
  121. cout << "Tekst " << pok << endl;
  122. }
  123. }
  124.  
  125. void main() {
  126. int izbor = 0;
  127. char *tekst = nullptr;
  128. const int max = 10;
  129. char *adminPass = "djenan";
  130. char *userPass = nullptr;
  131. do {
  132. cout << "Tekst edition" << endl;
  133. izbor = PrikaziMeni();
  134.  
  135. logiranje(adminPass, userPass);
  136.  
  137. if (tekst == nullptr && (izbor == 2 || izbor == 3 || izbor == 4))
  138. cout << "Potrebno je dodati tekst prvo" << endl;
  139. else {
  140. switch (izbor)
  141. {
  142. case 1:UnosTeksta(tekst); break;
  143. case 2:DodajTekst(tekst); break;
  144. case 3:Informacije(tekst); break;
  145. case 4:Pretraga(tekst); break;
  146. }
  147. }
  148. system("pause>0");
  149. system("cls");
  150. } while (izbor != 5);
  151. //if (tekst != NULL)
  152. OslobodiMemoriju(tekst);
  153. //system("pause>0");
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement