0% found this document useful (0 votes)
5 views2 pages

ClsDynamicArray H

The document defines a template class 'clsDynamicArray' for creating a dynamic array in C++. It includes methods for setting items, checking size and emptiness, and printing the array contents. The class manages memory allocation and deallocation for the array elements.

Uploaded by

Youssef Mahmoudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

ClsDynamicArray H

The document defines a template class 'clsDynamicArray' for creating a dynamic array in C++. It includes methods for setting items, checking size and emptiness, and printing the array contents. The class manages memory allocation and deallocation for the array elements.

Uploaded by

Youssef Mahmoudi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#pragma once

#include <iostream>
using namespace std;

template <class T>


class clsDynamicArray
{

protected:
int _Size = 0;

public:
T* OriginalArray;

clsDynamicArray(int Size = 0)
{
if (Size < 0)
Size = 0;

_Size = Size;

OriginalArray = new T[_Size];

~clsDynamicArray()
{

delete[] OriginalArray;

bool SetItem(int index, T Value)


{

if (index >= _Size || _Size <0)


{
return false;
}

OriginalArray[index] = Value;
return true;

int Size()
{
return _Size;
}

bool IsEmpty()
{
return (_Size == 0 ? true : false);

}
void PrintList()

for (int i = 0; i <= _Size - 1; i++)


{
cout << OriginalArray[i] << " ";
}

cout << "\n";

};

You might also like