Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. class Multitude {
  2. private:
  3. string key;
  4.  
  5. public:
  6. static const int size = 32;
  7. char *notice,*warning,*error,*action;
  8. char multitude[size+1];
  9. Multitude (){
  10. notice = "[~ Notice ] ";
  11. warning = "[? Warning] ";
  12. error = "[! Error ] ";
  13. action = "[$ Action ] ";
  14. }
  15. void Clear() {
  16. for (int i=0;i<size;i++) multitude[i]=NULL;
  17. }
  18. void ClearValue() {
  19. int id = 0;
  20. while (true) {
  21. cout<<action<<"Value to delete: ";
  22. getline(cin, key);
  23. // This code converts from string to number safely.
  24. stringstream myStream(key);
  25. if (myStream >> id)
  26. break;
  27. cout<<"Invalid number, please try again"<<endl;
  28. }
  29. multitude[id]=NULL;
  30. }
  31. int CountFilled () {
  32. int quant=0;
  33. for (int i=0;i<size;i++)
  34. if (multitude[i]) quant++;
  35. return quant;
  36. }
  37. void Show() {
  38. char *d;
  39. d = multitude;
  40. int w=8;
  41. char tmp;
  42. cout<<"\nTotal size: "<<sizeof(multitude)-1<<endl;
  43. cout<<"Filled cells: "<<CountFilled()<<endl;
  44. for (int i=0;i<(int)size-1;i++) {
  45. for (int j=0;j<w;j++,i++) {
  46. if (multitude[i]) tmp=multitude[i];
  47. else tmp=(char)(' ');
  48. printf("%5.0f: %c",(float)(i),tmp);
  49. //printf("%5.0f: %c",(float)(i),(char)multitude[i]);
  50. if (i>=size-1) break;
  51. *d++;
  52. }
  53. i--;
  54. cout<<endl;
  55. }
  56. }
  57. int GetValue() {
  58. int id = 0;
  59. while (true) {
  60. cout<<action<<"Numer to get: ";
  61. getline(cin, key);
  62. // This code converts from string to number safely.
  63. stringstream myStream(key);
  64. if (myStream >> id)
  65. break;
  66. cout<<"Invalid number, please try again"<<endl;
  67. }
  68. return id;
  69. }
  70.  
  71. };
  72.  
  73. class CharMultitude:public Multitude {
  74. public:
  75. CharMultitude() {
  76. Clear();
  77. }
  78. // Creates multitude from string
  79. void Create () {
  80. Clear();
  81. cout<<action<<"New string: ";
  82. string tempstr;
  83. getline(cin,tempstr);
  84. int i=0;
  85. while (tempstr[i]) {
  86. multitude[i] = tempstr[i];
  87. i++;
  88. }
  89. if (strlen(multitude)>size) cout<<warning<<"String is longer than "<<size<<" symbols and it will be cut off!";
  90. multitude[(int)strlen(multitude)]=NULL;
  91. }
  92.  
  93. char Get(int n) {
  94. return multitude[n];
  95. }
  96.  
  97. void Insert () {
  98. string newsymb;
  99. cout<<action<<"Insert symbol: ";
  100. getline(cin,newsymb);
  101. string key;
  102. int id = 0;
  103. while (true) {
  104. cout<<action<<"To position : ";
  105. getline(cin, key);
  106. // This code converts from string to number safely.
  107. stringstream myStream(key);
  108. if (myStream >> id)
  109. break;
  110. cout<<"Invalid number, please try again"<<endl;
  111. }
  112. multitude[id] = newsymb[0];
  113. }
  114.  
  115. // Checks quantity of char in multitude
  116. int Check(char *elem) {
  117. int quant=0;
  118. char *p;
  119. p=multitude;
  120. while (*p) {
  121. if (strcmp(p,elem)==0) quant++;
  122. *p++;
  123. }
  124. return quant;
  125. }
  126.  
  127. };
Add Comment
Please, Sign In to add comment