0% found this document useful (0 votes)
27 views1 page

79 DemoArrayADTC++

The document defines a C++ class called Array that dynamically allocates an array, allows the user to input elements into the array, and displays the array. The class has private data members to store the array pointer and its size and length, and public methods to initialize the array, take user input, and display the array before deallocating the memory.

Uploaded by

ßpñ lç
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)
27 views1 page

79 DemoArrayADTC++

The document defines a C++ class called Array that dynamically allocates an array, allows the user to input elements into the array, and displays the array. The class has private data members to store the array pointer and its size and length, and public methods to initialize the array, take user input, and display the array before deallocating the memory.

Uploaded by

ßpñ lç
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/ 1

#include <iostream>

using namespace std;

class Array{

private:
int* A;
int size;
int length;

public:
Array(int size){
this->size = size;
A = new int [size];
}

void create(){
cout << "Enter number of elements: " << flush;
cin >> length;
cout << "Enter the array elements: " << endl;
for (int i = 0; i < length; i++){
cout << "Array element: " << i << " = " << flush;
cin >> A[i];
}
}

void display(){
for (int i = 0; i < length; i++){
cout << A[i] << " ";
}
}

~Array(){
delete[] A;
cout << "Array destroyed" << endl;
}
};

int main() {

Array arr(10);
arr.create();
arr.display();

return 0;
}

You might also like