Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Plansza {
- int size{ 5 };
- int* tab{ new int[5] };
- public:
- Plansza() {
- for (int i{}; i < size; ++i) {
- tab[i] = i;
- }
- }
- ~Plansza() { if (tab) delete[] tab; }
- void print() const {
- for (auto i{ 0 }; i < size; ++i) {
- std::cout << tab[i] << '\t';
- }
- std::cout << std::endl;
- }
- void dodajElement(int nowy) {
- if (size == 0) {
- tab = new int[1];
- tab[0] = nowy;
- }
- else {
- int* temp{ new int[size + 1] };
- for (auto i{ 0 }; i < size; ++i) {
- temp[i] = tab[i];
- }
- delete[] tab;
- temp[size] = nowy;
- ++size;
- tab = temp;
- }
- }
- };
- int main() {
- Plansza p;
- p.print();
- p.dodajElement(10);
- p.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment