Guest User

Untitled

a guest
Mar 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int getLastNumber(int number) {
  5. int lastNumber = number % 10;
  6. return lastNumber;
  7. }
  8.  
  9. void swap(int *first, int *second) {
  10. int temp = *first;
  11. *first = *second;
  12. *second = temp;
  13. }
  14.  
  15. class SuperArray {
  16. private:
  17. int MAX_SIZE;
  18. int size;
  19. int * array;
  20. void sort();
  21. void push(int number);
  22. void show();
  23. void menu();
  24. public:
  25. SuperArray(int maxSize);
  26. };
  27.  
  28. void SuperArray::sort() {
  29. int i, j;
  30. for (i = 0; i < size - 1; i++)
  31. for (j = 0; j < size - i - 1; j++)
  32. if (getLastNumber(array[j]) > getLastNumber(array[j + 1]))
  33. swap(array[j], array[j + 1]);
  34. }
  35.  
  36.  
  37. void SuperArray::push(int number) {
  38. if (size < MAX_SIZE) {
  39. array[size] = number;
  40. sort();
  41. size++;
  42. }
  43. else
  44. cout << "YOU overfilled the array!!!!!!" << endl;
  45.  
  46. }
  47.  
  48. void SuperArray::show() {
  49. cout << endl;
  50. for (int i = 0; i < size; i++)
  51. cout << array[i] << ' ';
  52. cout << endl;
  53. }
  54.  
  55. void SuperArray::menu() {
  56. cout << "1. Display array" << endl;
  57. cout << "2. Push in array" << endl;
  58. while (1) {
  59.  
  60. int variant;
  61. cin >> variant;
  62.  
  63. switch (variant) {
  64. case 1:
  65. show();
  66. break;
  67. case 2:
  68. cout << "Enter the number: ";
  69. int number;
  70. cin >> number;
  71. push(number);
  72. break;
  73. default:
  74. cout << "Wrong" << endl;
  75. }
  76. }
  77. }
  78.  
  79. SuperArray::SuperArray(int maxSize) {
  80. MAX_SIZE = maxSize;
  81. array = new int[MAX_SIZE];
  82. menu();
  83. }
  84.  
  85. void main() {
  86. cout << "Enter the max size of array: ";
  87. int maxSize;
  88. cin >> maxSize;
  89. SuperArray arr(maxSize);
  90. system("pause");
  91.  
  92. }
Add Comment
Please, Sign In to add comment