fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. struct MojNauczycielToDupek {
  7. int **tablica;
  8. int *rozmiar;
  9.  
  10. MojNauczycielToDupek() {
  11. tablica = NULL;
  12. rozmiar = NULL;
  13. }
  14.  
  15. void podlacz(int **tab, int *n) {
  16. tablica = tab;
  17. rozmiar = n;
  18. }
  19.  
  20. } mojaKlasaJestOK;
  21.  
  22. void insert()
  23. {
  24. int nowyRozmiar = *mojaKlasaJestOK.rozmiar + 1;
  25. int *nowaTablica = new int[nowyRozmiar];
  26.  
  27. copy_n(*mojaKlasaJestOK.tablica, *mojaKlasaJestOK.rozmiar, nowaTablica);
  28. *(nowaTablica + *mojaKlasaJestOK.rozmiar) = 1;
  29.  
  30. int *temp = *mojaKlasaJestOK.tablica;
  31.  
  32. *mojaKlasaJestOK.tablica = nowaTablica;
  33. *mojaKlasaJestOK.rozmiar = nowyRozmiar;
  34.  
  35. delete[] temp;
  36. }
  37.  
  38. void choose()
  39. {
  40.  
  41. }
  42.  
  43. void remove()
  44. {
  45.  
  46. }
  47.  
  48. void resize()
  49. {
  50.  
  51. }
  52.  
  53. int main()
  54. {
  55. int roz;
  56. cout << "Enter a number of cells:";
  57. cin >> roz;
  58. int *tab;
  59. tab = new int[roz];
  60. for (int i=0;i<roz;i++)
  61. {
  62. cin >> tab[i];
  63. }
  64. for (int i=0;i<roz;i++)
  65. {
  66. cout << tab[i] << endl;
  67. }
  68.  
  69. mojaKlasaJestOK.podlacz(&tab, &roz);
  70.  
  71. int wybor;
  72. do
  73. {
  74. cout << "1: insert 1 cell to the end" << endl;
  75. cout << "2: choose a cell and insert 1 cell after it" << endl;
  76. cout << "3: remove the first cell" << endl;
  77. cout << "4: resize the table" << endl;
  78. cout << "5: quit" << endl;
  79. cin >> wybor;
  80. cout << "wybor = " << wybor << endl;
  81. } while(wybor!=1 && wybor !=2 && wybor !=3 && wybor !=4 && wybor !=5);
  82.  
  83. switch (wybor)
  84. {
  85. case 1:
  86. insert();
  87. break;
  88. case 2:
  89. choose();
  90. break;
  91. case 3:
  92. remove();
  93. break;
  94. case 4:
  95. resize();
  96. break;
  97. case 5:
  98. break;
  99. }
  100.  
  101. cout << "End state: " << endl;
  102. cout << "roz = " << roz << endl;
  103. cout << "tab = " << endl;
  104.  
  105. for(int i=0; i < roz; i++) {
  106. cout << tab[i] << ", ";
  107. }
  108.  
  109. cout << endl;
  110.  
  111. return 0;
  112. }
Success #stdin #stdout 0s 4356KB
stdin
5
1
2
3
4
5
1
stdout
Enter a number of cells:1
2
3
4
5
1: insert 1 cell to the end
2: choose a cell and insert 1 cell after it
3: remove the first cell
4: resize the table
5: quit
wybor = 1
End state: 
roz = 6
tab = 
1, 2, 3, 4, 5, 1,